Y
yxq
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
hwndOwner As Long, _
ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As
Long) As Long
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
(ByVal hInst _
As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As
Long
Public Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal
x As Long, _
ByVal y As Long, ByVal hIcon As Long) As Long
Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long)
As Long
Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias
"GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
*******************************************
2. Form1 code
*******************************************
' When the user presses button Command1, display an icon selection dialog
box. If the
' user chooses an icon, then draw it in the corner of window Form1's client
area.
Private Sub Command1_Click()
Dim iconfile As String ' file that contains the desired icon
Dim iconindex As Long ' index of the desired icon
Dim slength As Long ' length of returned string
Dim hIcon As Long ' handle to the icon once it is extracted
Dim retval As Long ' return value
' Figure out where the System directory is.
iconfile = Space(256)
slength = GetSystemDirectory(iconfile, Len(iconfile))
iconfile = Left(iconfile, slength)
' Have the default selection be the third icon in pifmgr.dll. Include
plenty
' of extra space in the string so it can receive the user's selection.
iconfile = iconfile & "\shell32.dll" & vbNullChar & Space(256)
iconindex = 2
' Display the icon selection dialog. If Windows NT or 2000 is running,
convert
' the string to and from Unicode immediately before and after calling
the function.
iconfile = StrConv(iconfile, vbUnicode)
retval = PickIconDlg(Form1.hWnd, iconfile, Len(iconfile), iconindex)
iconfile = StrConv(iconfile, vbFromUnicode)
' Remove the terminating null and empty space from the string.
iconfile = Left(iconfile, InStr(iconfile, vbNullChar) - 1)
' If the user selected something, draw the icon on Form1.
If retval <> 0 Then
' Extract the icon from the file.
hIcon = ExtractIcon(App.hInstance, iconfile, iconindex)
' Draw it in the corner of the window.
retval = DrawIcon(Form1.hDC, 0, 0, hIcon)
' Destroy the icon to free resources.
retval = DestroyIcon(hIcon)
End If
End Sub
****************************************
I use VB.NET auto upgrade wizard to convert the code
1.Moudle1
****************************************
Public Declare Function PickIconDlg Lib "shell32.dll" Alias "#62"(ByVal
hwndOwner As Integer, ByVal lpstrFile As String, ByVal nMaxFile As Integer,
ByRef lpdwIconIndex As Integer) As Integer
Public Declare Function ExtractIcon Lib "shell32.dll" Alias
"ExtractIconA"(ByVal hInst As Integer, ByVal lpszExeFileName As String,
ByVal nIconIndex As Integer) As Integer
Public Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Integer,
ByVal x As Integer, ByVal y As Integer, ByVal hIcon As Integer) As Integer
Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As
Integer) As Integer
Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias
"GetSystemDirectoryA"(ByVal lpBuffer As String, ByVal nSize As Integer) As
Integer
2.Form1 code
*****************************************
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Dim iconfile As String ' file that contains the desired icon
Dim iconindex As Integer ' index of the desired icon
Dim slength As Integer ' length of returned string
Dim hIcon As Integer ' handle to the icon once it is extracted
Dim retval As Integer ' return value
iconfile = Space(256)
slength = GetSystemDirectory(iconfile, Len(iconfile))
iconfile = VB.Left(iconfile, slength)
iconfile = iconfile & "\shell32.dll" & vbNullChar & Space(256)
iconindex = 2
iconfile = StrConv(iconfile, vbUnicode) 'vbUnicode error
retval = PickIconDlg(Form1.DefInstance.Handle.ToInt32, iconfile,
Len(iconfile), iconindex)
iconfile = StrConv(iconfile, vbFromUnicode) 'vbFromUnicode error
iconfile = VB.Left(iconfile, InStr(iconfile, vbNullChar) - 1)
' If the user selected something, draw the icon on Form1.
If retval <> 0 Then
hIcon = ExtractIcon(VB6.GetHInstance.ToInt32, iconfile, iconindex)
retval = DrawIcon(Form1.DefInstance.hDC, 0, 0, hIcon)
'Form1.DefInstance.hDC error
retval = DestroyIcon(hIcon)
End If
End Sub
******************************************
But there are 3 error.
Can anyone help me?
Thanks
I will run the program in Window XP.
The VB6 code
1. moudle1 code
******************************************
Public Declare Function PickIconDlg Lib "shell32.dll" Alias "#62" (ByVal
hwndOwner As Long, _
ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As
Long) As Long
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
(ByVal hInst _
As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As
Long
Public Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal
x As Long, _
ByVal y As Long, ByVal hIcon As Long) As Long
Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long)
As Long
Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias
"GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
*******************************************
2. Form1 code
*******************************************
' When the user presses button Command1, display an icon selection dialog
box. If the
' user chooses an icon, then draw it in the corner of window Form1's client
area.
Private Sub Command1_Click()
Dim iconfile As String ' file that contains the desired icon
Dim iconindex As Long ' index of the desired icon
Dim slength As Long ' length of returned string
Dim hIcon As Long ' handle to the icon once it is extracted
Dim retval As Long ' return value
' Figure out where the System directory is.
iconfile = Space(256)
slength = GetSystemDirectory(iconfile, Len(iconfile))
iconfile = Left(iconfile, slength)
' Have the default selection be the third icon in pifmgr.dll. Include
plenty
' of extra space in the string so it can receive the user's selection.
iconfile = iconfile & "\shell32.dll" & vbNullChar & Space(256)
iconindex = 2
' Display the icon selection dialog. If Windows NT or 2000 is running,
convert
' the string to and from Unicode immediately before and after calling
the function.
iconfile = StrConv(iconfile, vbUnicode)
retval = PickIconDlg(Form1.hWnd, iconfile, Len(iconfile), iconindex)
iconfile = StrConv(iconfile, vbFromUnicode)
' Remove the terminating null and empty space from the string.
iconfile = Left(iconfile, InStr(iconfile, vbNullChar) - 1)
' If the user selected something, draw the icon on Form1.
If retval <> 0 Then
' Extract the icon from the file.
hIcon = ExtractIcon(App.hInstance, iconfile, iconindex)
' Draw it in the corner of the window.
retval = DrawIcon(Form1.hDC, 0, 0, hIcon)
' Destroy the icon to free resources.
retval = DestroyIcon(hIcon)
End If
End Sub
****************************************
I use VB.NET auto upgrade wizard to convert the code
1.Moudle1
****************************************
Public Declare Function PickIconDlg Lib "shell32.dll" Alias "#62"(ByVal
hwndOwner As Integer, ByVal lpstrFile As String, ByVal nMaxFile As Integer,
ByRef lpdwIconIndex As Integer) As Integer
Public Declare Function ExtractIcon Lib "shell32.dll" Alias
"ExtractIconA"(ByVal hInst As Integer, ByVal lpszExeFileName As String,
ByVal nIconIndex As Integer) As Integer
Public Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Integer,
ByVal x As Integer, ByVal y As Integer, ByVal hIcon As Integer) As Integer
Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As
Integer) As Integer
Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias
"GetSystemDirectoryA"(ByVal lpBuffer As String, ByVal nSize As Integer) As
Integer
2.Form1 code
*****************************************
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Dim iconfile As String ' file that contains the desired icon
Dim iconindex As Integer ' index of the desired icon
Dim slength As Integer ' length of returned string
Dim hIcon As Integer ' handle to the icon once it is extracted
Dim retval As Integer ' return value
iconfile = Space(256)
slength = GetSystemDirectory(iconfile, Len(iconfile))
iconfile = VB.Left(iconfile, slength)
iconfile = iconfile & "\shell32.dll" & vbNullChar & Space(256)
iconindex = 2
iconfile = StrConv(iconfile, vbUnicode) 'vbUnicode error
retval = PickIconDlg(Form1.DefInstance.Handle.ToInt32, iconfile,
Len(iconfile), iconindex)
iconfile = StrConv(iconfile, vbFromUnicode) 'vbFromUnicode error
iconfile = VB.Left(iconfile, InStr(iconfile, vbNullChar) - 1)
' If the user selected something, draw the icon on Form1.
If retval <> 0 Then
hIcon = ExtractIcon(VB6.GetHInstance.ToInt32, iconfile, iconindex)
retval = DrawIcon(Form1.DefInstance.hDC, 0, 0, hIcon)
'Form1.DefInstance.hDC error
retval = DestroyIcon(hIcon)
End If
End Sub
******************************************
But there are 3 error.
Can anyone help me?
Thanks