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 3 13371
Ok, I added the code to a VB6 project now and ran the Wizard in VB.NET.
Right, there are three errors, but there are also hints starting with
"UPGRADE_ISSUE". Did you read the hints?
Now, concerning vbUnicode/vbFromUnicode: All Strings in (VB).NET are Unicode
strings.
The argument lpstrFile for PickIconDlg is an in and _out_ argument. This
means you have to pass a stringbuilder instead because strings are
"immutable". After calling the function, get the returned file by using the
Stringbuilder's ToString method.
To convert the hDC issue, you must use a graphics object instead.
Also, replace
iconfile = Space(256)
slength = GetSystemDirectory(iconfile, Len(iconfile))
iconfile = VB.Left(iconfile, slength)
by
iconfile = Environment.GetFolderPath( _
Environment.SpecialFolder.System _
)
You must also declare PickIconDlg as an "Auto" or "Unicode" function because
the string pointed to by the lpstrfile argument must be unicode. Also
declare hwndOwner as Intptr. The same with the first argument for
ExtractIcon.
So, the resulting code is:
Module Module1
Public Declare Unicode Function PickIconDlg _
Lib "shell32.dll" Alias "#62" ( _
ByVal hwndOwner As IntPtr, _
ByVal lpstrFile As System.Text.StringBuilder, _
ByVal nMaxFile As Integer, _
ByRef lpdwIconIndex As Integer) _
As Integer
Public Declare Function ExtractIcon _
Lib "shell32.dll" Alias "ExtractIconA" ( _
ByVal hInst As IntPtr, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Integer) _
As Integer
Public Declare Function DestroyIcon _
Lib "user32.dll" (ByVal hIcon As Integer) _
As Integer
End Module
'Form:
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 retval As Integer ' return value
Dim sb As System.Text.StringBuilder
iconfile = Environment.GetFolderPath( _
Environment.SpecialFolder.System _
)
iconfile = iconfile & "\shell32.dll"
iconindex = 2
sb = New System.Text.StringBuilder(iconfile, 500)
retval = PickIconDlg( _
Form1.DefInstance.Handle, sb, sb.Length, iconindex _
)
iconfile = sb.ToString
If retval <> 0 Then
Dim g As Graphics
Dim ico As Icon
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon = New IntPtr( _
ExtractIcon(VB6.GetHInstance, iconfile, iconindex) _
)
ico = Icon.FromHandle(New IntPtr(hIcon))
g = Form1.DefInstance.CreateGraphics
g.DrawIcon(ico, 0, 0)
g.Dispose()
ico.Dispose()
retval = DestroyIcon(hIcon)
End If
End Sub
--
Armin
"yxq" <ga***@163.net> schrieb I will run the program in Window XP.
[...}
But there are 3 error.
Can anyone help me?
Maybe - if you could tell us which errors occur where?
--
Armin
Me again...
sorry, the previous code does not work. I shouldn't make changes in OE. ;-(
Change the return type of ExtractIcon to IntPtr:
Public Declare Function ExtractIcon _
Lib "shell32.dll" Alias "ExtractIconA" ( _
ByVal hInst As IntPtr, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Integer) _
As IntPtr
Also change the call to PickIconDlg:
retval = PickIconDlg( _
Form1.DefInstance.Handle, sb, sb.Capacity, iconindex _
)
Also:
If retval <> 0 Then
Dim g As Graphics
Dim ico As Icon
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon = ExtractIcon(VB6.GetHInstance, iconfile, iconindex)
ico = Icon.FromHandle(hIcon)
g = Form1.DefInstance.CreateGraphics
g.DrawIcon(ico, 0, 0)
g.Dispose()
retval = DestroyIcon(hIcon)
End If
(no need to call ico.Dispose when created by Icon.FromHandle. Only
DestroyIcon must be called)
Sorry again.
--
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: William C. White |
last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using
cURL? Our website is hosted on a shared drive and the webhost company
doesn't installed additional software (such as cURL)...
|
by: Albert Ahtenberg |
last post by:
Hello,
I don't know if it is only me but I was sure that header("Location:url")
redirects the browser instantly to URL, or at least stops the execution of
the code. But appearantely it continues...
|
by: James |
last post by:
Hi,
I have a form with 2 fields.
'A'
'B'
The user completes one of the fields and the form is submitted.
On the results page I want to run a query, but this will change
subject to which...
|
by: Ollivier Robert |
last post by:
Hello,
I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9
system. The link succeeds but everytime I try to run php, I get a SEGV from
inside the libcnltsh.so library.
...
|
by: Richard Galli |
last post by:
I want viewers to compare state laws on a single subject.
Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the...
|
by: Albert Ahtenberg |
last post by:
Hello,
I have two questions.
1. When the user presses the back button and returns to a form he filled
the form is reseted. How do I leave there the values he inserted?
2. When the...
|
by: inderjit S Gabrie |
last post by:
Hi all
Here is the scenerio ...is it possibly to do this...
i am getting valid course dates output on to a web which i have designed
....all is okay so far , look at the following web url
...
|
by: Jack |
last post by:
Hi All,
What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g.
select x from y where z=:parameter
Which in asp/jsp would be followed by some statements to bind a value...
|
by: Sandwick |
last post by:
I am trying to change the size of a drawing so they are all 3x3.
the script below is what i was trying to use to cut it in half ... I
get errors.
I can display the normal picture but not the...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
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,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |