473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DrawIcon API

Hi Masters :-)

Could anyone of you please translate the following into Visual Basic
2005 Code ?
I am new to this and tried every trick but failed to translate. Any
help would be highly
appreciated. I can't use Graphics.DrawIcon as I don't have a
IconFile , I am using
ExtractIcon to get a handle to the Icon. Here's the VB6 which I am
trying to Convert
- - -- >

Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As
Long, ByVal Y As Long, ByVal hIcon As Long) As Long

Declare Function ExtractIcon Lib "shell32.dll" Alias
"ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String,
ByVal nIconIndex As Long) As Long

Private Sub Form_Load()

Dim li_hicon As Long

li_hicon = ExtractIcon(li_my_hInst, "C:\WINNT\NOTEPAD.EXE", 0)

picAplIcon.AutoRedraw = -1

li_retcode1 = DrawIcon(picAplIcon.hDC, picAplIcon.ScaleLeft,
picAplIcon.ScaleTop, li_hicon)

picAplIcon.Refresh

End Sub

Thanks to you all in advance!!

Best Regards,

Sudhansu

May 10 '07 #1
3 2963
On May 10, 9:10 am, Phoenix <sudhansutiw...@gmail.comwrote:
Hi Masters :-)

Could anyone of you please translate the following into Visual Basic
2005 Code ?
I am new to this and tried every trick but failed to translate. Any
help would be highly
appreciated. I can't use Graphics.DrawIcon as I don't have a
IconFile , I am using
ExtractIcon to get a handle to the Icon. Here's the VB6 which I am
trying to Convert
- - -- >

Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As
Long, ByVal Y As Long, ByVal hIcon As Long) As Long

Declare Function ExtractIcon Lib "shell32.dll" Alias
"ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String,
ByVal nIconIndex As Long) As Long

Private Sub Form_Load()

Dim li_hicon As Long

li_hicon = ExtractIcon(li_my_hInst, "C:\WINNT\NOTEPAD.EXE", 0)

picAplIcon.AutoRedraw = -1

li_retcode1 = DrawIcon(picAplIcon.hDC, picAplIcon.ScaleLeft,
picAplIcon.ScaleTop, li_hicon)

picAplIcon.Refresh

End Sub

Thanks to you all in advance!!

Best Regards,

Sudhansu
Option Strict On
Option Explicit On

Imports System.Runtime.InteropServices
Imports System.Reflection

Public Class Form1

Private Declare Auto Function ExtractIcon Lib "shell32.dll" ( _
ByVal hInst As System.IntPtr, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Integer) As System.IntPtr

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim hIcon As System.IntPtr =
ExtractIcon(Marshal.GetHINSTANCE(Assembly.GetExecu tingAssembly().GetModules()
(0)), "C:\windows\notepad.exe", 0)
Me.PictureBox1.Image = Bitmap.FromHicon(hIcon)
End Sub
End Class

--
Tom Shelton

May 10 '07 #2
On May 10, 11:10 am, Phoenix <sudhansutiw...@gmail.comwrote:
Hi Masters :-)

Could anyone of you please translate the following into Visual Basic
2005 Code ?
I am new to this and tried every trick but failed to translate. Any
help would be highly
appreciated. I can't use Graphics.DrawIcon as I don't have a
IconFile , I am using
ExtractIcon to get a handle to the Icon. Here's the VB6 which I am
trying to Convert
- - -- >

Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As
Long, ByVal Y As Long, ByVal hIcon As Long) As Long

Declare Function ExtractIcon Lib "shell32.dll" Alias
"ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String,
ByVal nIconIndex As Long) As Long

Private Sub Form_Load()

Dim li_hicon As Long

li_hicon = ExtractIcon(li_my_hInst, "C:\WINNT\NOTEPAD.EXE", 0)

picAplIcon.AutoRedraw = -1

li_retcode1 = DrawIcon(picAplIcon.hDC, picAplIcon.ScaleLeft,
picAplIcon.ScaleTop, li_hicon)

picAplIcon.Refresh

End Sub

Thanks to you all in advance!!

Best Regards,

Sudhansu
Add a picturebox titled "PictureBox1" to a form and add the following
code:

<DllImport("user32.dll")_
Public Shared Function DrawIcon(ByVal hDc As IntPtr, ByVal X As
Integer, ByVal Y As Integer, ByVal hIcon As IntPtr) As Boolean
End Function

<DllImport("shell32.dll")_
Public Shared Function ExtractIcon(ByVal hInst As IntPtr, ByVal
lpszExeFileName As String, ByVal nIconIndex As Integer) As IntPtr
End Function

Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Try
Dim hIcon As IntPtr = ExtractIcon(Me.Handle, "C:\WINNT
\NOTEPAD.EXE", 0)
DrawIcon(e.Graphics.GetHdc(), 10, 10, hIcon)
Finally
e.Graphics.ReleaseHdc()
End Try
End Sub

Thanks,

Seth Rowe

May 10 '07 #3
On May 10, 11:53 am, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On May 10, 11:10 am, Phoenix <sudhansutiw...@gmail.comwrote:
Hi Masters :-)
Could anyone of you please translate the following into Visual Basic
2005 Code ?
I am new to this and tried every trick but failed to translate. Any
help would be highly
appreciated. I can't use Graphics.DrawIcon as I don't have a
IconFile , I am using
ExtractIcon to get a handle to the Icon. Here's the VB6 which I am
trying to Convert
- - -- >
Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As
Long, ByVal Y As Long, ByVal hIcon As Long) As Long
Declare Function ExtractIcon Lib "shell32.dll" Alias
"ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String,
ByVal nIconIndex As Long) As Long
Private Sub Form_Load()
Dim li_hicon As Long
li_hicon = ExtractIcon(li_my_hInst, "C:\WINNT\NOTEPAD.EXE", 0)
picAplIcon.AutoRedraw = -1
li_retcode1 = DrawIcon(picAplIcon.hDC, picAplIcon.ScaleLeft,
picAplIcon.ScaleTop, li_hicon)
picAplIcon.Refresh
End Sub
Thanks to you all in advance!!
Best Regards,
Sudhansu

Add a picturebox titled "PictureBox1" to a form and add the following
code:

<DllImport("user32.dll")_
Public Shared Function DrawIcon(ByVal hDc As IntPtr, ByVal X As
Integer, ByVal Y As Integer, ByVal hIcon As IntPtr) As Boolean
End Function

<DllImport("shell32.dll")_
Public Shared Function ExtractIcon(ByVal hInst As IntPtr, ByVal
lpszExeFileName As String, ByVal nIconIndex As Integer) As IntPtr
End Function

Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Try
Dim hIcon As IntPtr = ExtractIcon(Me.Handle, "C:\WINNT
\NOTEPAD.EXE", 0)
DrawIcon(e.Graphics.GetHdc(), 10, 10, hIcon)
Finally
e.Graphics.ReleaseHdc()
End Try
End Sub

Thanks,

Seth Rowe
DrawIcon(e.Graphics.GetHdc(), 10, 10, hIcon)
And no, I don't know why I chose 10, 10 instead of 0, 0

:-)

Thanks,

Seth Rowe

May 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eric Cadwell | last post by:
We're running Load Runner to test a large 1.0 based WinForms application. I'm getting the following exception when opening and closing a form 400 - 450 times. The form contains several controls and...
3
by: Benny Raymond | last post by:
I've written a class that inherits from MenuItem which displays icons next to the items in a menu... The only problem I'm having is that I have no clue how to turn these icons greyscale if they're...
3
by: yxq | last post by:
Hello I will run the program in Window XP. The VB6 code 1. moudle1 code ****************************************** Public Declare Function PickIconDlg Lib "shell32.dll" Alias "#62" (ByVal...
6
by: yxq | last post by:
Thank Armin Zingler, the codes below work well! But i want to put the icon into Picturebox1 instead of the Form1, how to do? the code ************************** If retval <> 0 Then Dim g As...
1
by: todd | last post by:
I'm trying to make my own messagebox (for custom error dialogs, etc), but having a little trouble with the icons. I use the systemicons, but they're not anti-aliased and look horrible. How can I...
2
by: notregister | last post by:
how do u get the devicenames if i have several usb device connected to an usb hub? will it be any different if i several printer connected to an ethernet router? if there are, how can i get the...
0
by: Jon Slaughter | last post by:
I'm manually displaying images in a TreeView but when I stick the images in the Images(icons) container in the TreeView and use DrawImage they look like crap but when I force an icon draw and use...
6
by: Nathan Laff | last post by:
Why when I inherit a ComboBox and make no code changes, when I set the new control DropDownStyle to dropDownList it appears different than the standard ComboBox control on Vista? In Windows...
2
by: Phoenix | last post by:
Hi Masters :-) Could anyone of you please translate the following into Visual Basic 2005 Code ? I am new to this and tried every trick but failed to translate. Any help would be highly...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.