Results 1 to 24 of 24

Thread: Icon

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Someone show me how to use SendMessage and WM_GETICON to retrieve an icon from a handle...?

    Thanks in advance.

  2. #2
    Guest
    Are you looking for that in particular? Because VB-World has an example on how to extract icons from files.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Doesn't draw anything (yes I did supply a handle with an icon)

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  6. #6
    Guest
    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    This doesn't work either; HICON always returns 0.

  8. #8
    Guest
    Is there an Icon loaded in the current Form?

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  10. #10
    Guest
    If you specify 1 for wParam (as I did above) it will draw the large icon.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Yes, for the second time, I provided a handle (I'm not that dumb). Maybe I'm trying the wrong handle. Will Calc work?

  12. #12
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61

    Talking

    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.

  13. #13
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    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.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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?

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Someone must now how to use this!! Or atleast explain why my last post happens?

  19. #19
    Guest
    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)

  20. #20
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  21. #21
    Addicted Member
    Join Date
    Oct 1999
    Location
    chicago (hope)
    Posts
    146

    Thumbs down

    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_

  22. #22
    Addicted Member
    Join Date
    Oct 1999
    Location
    chicago (hope)
    Posts
    146

    Talking 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???????

  23. #23
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  24. #24
    Addicted Member
    Join Date
    Oct 1999
    Location
    chicago (hope)
    Posts
    146

    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
  •  



Click Here to Expand Forum to Full Width