DrawIcon API

  • Thread starter Thread starter Phoenix
  • Start date Start date
P

Phoenix

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
 
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.GetExecutingAssembly().GetModules()
(0)), "C:\windows\notepad.exe", 0)
Me.PictureBox1.Image = Bitmap.FromHicon(hIcon)
End Sub
End Class
 
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
 
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
 
Back
Top