473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Icon.FromHandle(..) not working?

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
Jul 25 '06 #1
7 2126
"iwdu15" <jmmgoalsteratyahoodotcomschrieb:
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').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jul 25 '06 #2
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
Jul 25 '06 #3
"iwdu15" <jmmgoalsteratyahoodotcomschrieb:
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).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 25 '06 #4
Great, thanks!
--
-iwdu15
Jul 25 '06 #5
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
Jul 25 '06 #6
"iwdu15" <jmmgoalsteratyahoodotcomschrieb:
>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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 25 '06 #7
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!
--
-iwdu15
Jul 25 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: [Yosi] | last post by:
I have a form , I want to change form icon relate to some states, I all image list witch include some icons. How can I convert image to Icon or how to change the form icon ....in run time
0
by: David Gardiner | last post by:
I'm trying to load an Icon with the following code (from a control panel) if (cpli.idIcon != 0) { HICON hIcon = LoadIcon(hinstCPL, MAKEINTRESOURCE(cpli.idIcon)); ICONINFO iconinfo;...
5
by: Dennis | last post by:
I give up...I have tried all combinations that I can think of and I can't get a bitmap converted to an icon and save it in a filestream or stream; Any help would be appreciated. -- Dennis in...
2
by: Rainer Queck | last post by:
Hello NG, what are the right dimensions for a window icon, used on a mdi child window? My Problem: I used a third party Icon-Designer to design some icons for my application. Those icons look...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.