473,471 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2968
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.