|
-
Aug 11th, 2000, 02:27 PM
#1
Thread Starter
Hyperactive Member
Someone show me how to use SendMessage and WM_GETICON to retrieve an icon from a handle...?
Thanks in advance.
-
Aug 11th, 2000, 02:36 PM
#2
Are you looking for that in particular? Because VB-World has an example on how to extract icons from files.
-
Aug 11th, 2000, 02:38 PM
#3
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 11th, 2000, 08:28 PM
#4
Thread Starter
Hyperactive Member
Doesn't draw anything (yes I did supply a handle with an icon)
-
Aug 12th, 2000, 06:18 AM
#5
transcendental analytic
Did you get a hicon value, (that is not 0)?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 12th, 2000, 09:13 AM
#6
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
-
Aug 12th, 2000, 12:09 PM
#7
Thread Starter
Hyperactive Member
This doesn't work either; HICON always returns 0.
-
Aug 12th, 2000, 12:29 PM
#8
Is there an Icon loaded in the current Form?
-
Aug 12th, 2000, 02:13 PM
#9
transcendental analytic
Hmm, the problem could be that you don't have a small icon, of the window, btw what do you pass in hwnd?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 12th, 2000, 02:22 PM
#10
If you specify 1 for wParam (as I did above) it will draw the large icon.
-
Aug 12th, 2000, 02:56 PM
#11
Thread Starter
Hyperactive Member
Yes, for the second time, I provided a handle (I'm not that dumb). Maybe I'm trying the wrong handle. Will Calc work?
-
Aug 12th, 2000, 03:04 PM
#12
Member
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
---~^ Absalom ^~---
There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.
-
Aug 12th, 2000, 03:07 PM
#13
Member
it also will not work if the forms icon is set to (none) or the icon is the windows logo
---~^ Absalom ^~---
There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.
-
Aug 13th, 2000, 09:45 AM
#14
Thread Starter
Hyperactive Member
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?
-
Aug 13th, 2000, 10:12 AM
#15
Monday Morning Lunatic
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
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 13th, 2000, 01:37 PM
#16
transcendental analytic
You could make your own spy:
Code:
Dim a$
DO
A = Space(255)
caption = Left(a, GetClassName(GetForegroundWindow, ByVal a, 255))
doevents
loop
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 13th, 2000, 11:02 PM
#17
Thread Starter
Hyperactive Member
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.
-
Aug 14th, 2000, 09:44 PM
#18
Thread Starter
Hyperactive Member
Someone must now how to use this!! Or atleast explain why my last post happens?
-
Aug 15th, 2000, 06:28 AM
#19
try this code
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
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)
-
Aug 15th, 2000, 08:07 AM
#20
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 16th, 2000, 06:44 AM
#21
Addicted Member
Code:
hIcon = SendMessage(Wnd, WM_GETICON, 1, 0)
DrawIcon Picture1.hdc, 0, 0, hIcon
does not work at all !!!!!
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_
-
Aug 16th, 2000, 12:25 PM
#22
Addicted Member
windowtz
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???????
-
Aug 16th, 2000, 03:33 PM
#23
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 22nd, 2000, 02:36 AM
#24
Addicted Member
kabel
i got cabel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|