Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

GetClassLong and Icon Handle

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff Gaines - 13 Sep 2003 14:23 GMT
I am writing a file manager (in C#) which uses a dll which hooks into
the system sending my app a message when a window is created or
destroyed, the dll works fine and I am receiving the messages.
When I receive a Window Created message I want to get a handle on its
icon and use it as a graphic on a button (which allows switching to
that application).
Everything is working except getting a handle on an icon for any app I
have written in C#. If any program is started I can pick up its icon
as follows:

ipHIcon = GetClassLong(ipWindow, GCL_HICON);

if(ipHIcon != IntPtr.Zero)
{
    System.Drawing.Icon SIcon= Icon.FromHandle(ipHIcon);
    imlApps.Images.Add(SIcon);
    jraTemp.intIconIndex = imlApps.Images.Count - 1;
    // Clean up - must be done after image inserted in to image list
    jff.JDestroyIcon(ipHIcon);
}
else
    jraTemp.intIconIndex = 0;

I always end up with 0 as my iconindex for any of my own apps written
in C# which seems to imply that GetClassLong won't work for .Net
framework apps. I can get the icon handle I want on my own apps
written in Delphi for instance.

I have tried re-compiling with the app icon as Content, Compile and
Embedded Resource but it makes no difference.

Can anybody advise me how to get a valid icon handle for an app
compiled to run under the .Net framework please?

Signature

Jeff Gaines Damerham Hampshire UK

Mattias Sj?gren - 14 Sep 2003 17:13 GMT
Jeff,

>Can anybody advise me how to get a valid icon handle for an app
>compiled to run under the .Net framework please?

If GetClassLong(GCL_HICON) fails, I would try sending a WM_GETICON
message to the window.

Of course, an icon might not have been set at the time the window is
created, or it might be changed during the execution of the app, so
you might want to update the icon at some interval.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Jeff Gaines - 14 Sep 2003 19:38 GMT
On Sun, 14 Sep 2003 18:13:28 +0200, Mattias Sjögren
<mattias.dont.want.spam@mvps.org> wrote:

>Jeff,
>
[quoted text clipped - 9 lines]
>
>Mattias

Mattias

I am beginning to think you are my personal adviser :-))

SendMessage with WM_ICON works fine thank you.

I am still intrigued as to why GetClassLong(GCL_HICON) fails just with
apps written for the .Net framework. Shortcuts to those progs pick up
the correct icon.

Thanks once more.
Signature

Jeff Gaines Damerham Hampshire UK

Mattias Sj?gren - 14 Sep 2003 23:36 GMT
Jeff,

>I am still intrigued as to why GetClassLong(GCL_HICON) fails just with
>apps written for the .Net framework.

Probably because the window class has been registered
(RegisterClassEx) with a NULL icon handle. That doesn't necessarily
indicate an error.

>Shortcuts to those progs pick up the correct icon.

Shortcuts usually an icon resources in the executable file. It doesn't
have to be the same as any icon used for a window (though it often is)

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.