Icon.FromHandle(..) not working?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, im attempting to get an applications Icon by using the method
Icon.FromHandle() and passing in a windows handle, yet nothing works ive
tried two different things and neither work. Ive been googleing this to no
avail....code:


Protected Overrides Sub WndProc(ByRef m As Message)

MyBase.WndProc(m)

If m.Msg = WM_SYSCOMMAND Then

Select Case m.WParam.ToInt32

Case 1000

Dim tray As New NotifyIcon(Me.components)


tray.Icon = Icon.FromHandle(m.HWnd)

''tried using Me.Handle to see if that would work but no
'tray.Icon = Icon.FromHandle(Me.Handle)
tray.Visible = True

AddHandler tray.DoubleClick, AddressOf
NotifyIcon1_DoubleClick

SendMessage(m.HWnd.ToInt32, 0, Nothing, Nothing)

End Select

End If

End Sub


i set a breakpoint and step through, the method returns something, but
apparently not an Icon like the MSDN documentation says...any idea how i can
get this working? thanks
 
iwdu15 said:
hi, im attempting to get an applications Icon by using the method
Icon.FromHandle() and passing in a windows handle

You will have to pass in an icon handle ('HICON').
 
so then if i get a windows handle, how can i get either a)its icon handle or
b) its icon? thanks for your help
 
iwdu15 said:
so then if i get a windows handle, how can i get either a)its icon handle
or
b) its icon?

PInvoke with 'SendMessage' + 'WM_GETICON' (see documentation).
 
i cant seem to figre this out....google hasnt helped either....heres what i
have

Protected Overrides Sub WndProc(ByRef m As Message)

MyBase.WndProc(m)

If m.Msg = WM_SYSCOMMAND Then

Select Case m.WParam.ToInt32

Case 1000

SendMessage(m.HWnd, WM_GETICON, Nothing, Nothing)

Dim tray As New NotifyIcon

Dim x As IntPtr = DefWindowProcA(m.HWnd, WM_GETICON,
Nothing, Nothing)

tray.Icon = Icon.FromHandle(x)
tray.Visible = True

AddHandler tray.DoubleClick, AddressOf
NotifyIcon1_DoubleClick

SendMessage(m.HWnd, 0, Nothing, Nothing)

End Select

End If

End Sub


yet the DefWindowProcA doesnt return a windows handle....i couldnt find any
documentation of how to get a specific message on MSDN or AllApi etc....thanks
 
iwdu15 said:
i cant seem to figre this out....google hasnt helped either....heres what i
have

'SendMessage''s return value is the icon handle you can pass to
'Icon.FromHandle'.
 
SendMessage() was returning 0, so i found a way around it. I iterated through
each process comparing that handle to the handle i already have, if theyre
the same i get the main module file name and extract the icon....thanks
though Herfried!
 
Back
Top