Someone show me how to use SendMessage and WM_GETICON to retrieve an icon from a handle...?
Thanks in advance.
Printable View
Someone show me how to use SendMessage and WM_GETICON to retrieve an icon from a handle...?
Thanks in advance.
Are you looking for that in particular? Because VB-World has an example on how to extract icons from files.
You draw an icon by it's handle using DrawIcon, but what i think is you want to get the icon handle from the window handle?
Anyway here's both:
Code:Public Const WM_GETICON = &H7F&
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'Icon handle
hIcon = SendMessage(hwnd, WM_GETICON, 0, 0)
'Draw the icon
DrawIcon hdc, 0, 0, hIcon
Doesn't draw anything (yes I did supply a handle with an icon)
Did you get a hicon value, (that is not 0)?
Try this:
Code:Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal HICON As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_GETICON = &H7F
Private Sub Command1_Click()
Dim HICON As Long
HICON = SendMessage(hwnd, WM_GETICON, 1, 0)
DrawIcon hdc, 0, 0, HICON
Me.Refresh
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
End Sub
This doesn't work either; HICON always returns 0.
Is there an Icon loaded in the current Form?
Hmm, the problem could be that you don't have a small icon, of the window, btw what do you pass in hwnd?
If you specify 1 for wParam (as I did above) it will draw the large icon.
Yes, for the second time, I provided a handle (I'm not that dumb). Maybe I'm trying the wrong handle. Will Calc work?
Is the icon your form has only a 16x16 icon or is it both 16x16 and 32x32
because I ran megatrons code and it worked but I did not change the original Icon
it also will not work if the forms icon is set to (none) or the icon is the windows logo
Ok, this does work on applications made in VB; but I wanted to be able to use this on any application, like Calculator, Napster, or AOL. I can change wParam to anything and it always works for a VB app. Can someone help?
Use the same message (and wParam, lParam), but send it to a different window, which you can find with FindWindow. Some class names (from Spy++) are:
Napster = NAPSTER
Calculator = SciCalc
You could make your own spy:
Code:Dim a$
DO
A = Space(255)
caption = Left(a, GetClassName(GetForegroundWindow, ByVal a, 255))
doevents
loop
Hah, ok, that's not exactly what I meant. I know good and well how to retrieve handles to other applications using FindWindow and all that jazz- it's the fact that the call doesn't work when I call on AOL or Calc.
Someone must now how to use this!! Or atleast explain why my last post happens?
try this code
you have to know the name of the .exe but you dont even have to have it running(the exe you want the icon from)Code:Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal HICON As Long) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Sub Command1_Click()
Dim HICON As Long
HICON = ExtractIcon(Me.hwnd, "C:\WINDOWS\CALC.EXE", 0)
DrawIcon Me.hdc, 0, 0, HICON
Me.Refresh
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
End Sub
Hmmm, well you could try again..
Code:If GetClassLong(hwnd, -14) Then Handle = GetClassLong(hwnd, -14) 'Get large icon
If SendMessage(hwnd, WM_GETICON, 0, 0) Then Handle = SendMessage(hwnd, WM_GETICON, 0, 0) 'Replace with small if found
If Handle Then
picture1.Cls
DrawIcon picture1.hdc, 0, 0, Handle
picture1.Refresh
Else
MsgBox "No icon handle"
End If
does not work at all !!!!!Code:hIcon = SendMessage(Wnd, WM_GETICON, 1, 0)
DrawIcon Picture1.hdc, 0, 0, hIcon
neighter with vb-apps (me.hwnd) nor with any other app....
i thought of having a wrong wm_geticon, but the api-viewer does NOT have this constante.
is there a possibility to get the exe-name + path of the app, the window belongs to??????
thanx
aj_cool_
it's a win98 se....
but why do the api viewer and http://www.vb-api.com not have ANY entrie concerning WM_GETICON ?
does it EXIST???????
Public Const WM_GETICON = &H7F&
Nope, there is neither WM_GETICON nor something near with the value &H7F. There's a lot of undocumented API i have.
Good suggestion Dennis, but i don't have much time for the web site right now, possibly after i get cable :)
i got cabel :)