-
[mod edit]This post refers to this thread:
http://cboard.cprogramming.com/showthread.php?t=79130
[/mod edit]
Hi veecee
I'm new to this board but have been visiting other C++ boards for a couple of months. I've gone through the "Hello World", for ... next and other loops etc. I'm interested in creating a custom System Tray icon and have seen code on The Code Project and Planet Source Code. I have Dev-C++ and VCEE but I prefer the former.
I was very pleased when your code compiled correctly (with Dev-C++) and I'd like to add a custom icon. I realise that I'll have to include the icon details as the code is compiled but how exactly would I include it as a resource? I realise that I can add a resource file (tab) on the right side of the Dev-C++ editing screen but, if that's the right way to go about it, what do I write in the resource file? Is it the filepath and name of the icon or do I need to copy and paste binary/hex data (for instance)?
I would have sent you a PM but it seems that I'm not allowed to do that yet!
Finally, you said that you had a version which has a popup menu - I'd like to see that, if you don't mind posting it.
Thanks for your time (and patience)!
-
Apologies.
The original thread was started on 15 May 2006 and the final response was on 16 May 2006. Like many newcomers, I didn't read the forum-specific guidelines, but I will now! I woudn't have resurrected a thread that was many months old but I thought that it would be OK to do so with one that was between three and four weeks old.
As I mentioned, I would have PMd veecee directly but, when I clicked the name or <Members List>, it said that I didn't have permission to access that. I assumed that PMs weren't permitted until a certain number of posts had been reached.
This "rap on the knuckles" hasn't dissuaded me - I just hope that veecee (or someone else) is able to help me!
-
You can load an icon from an .ICO file using LoadImage.
Code:
HICON LoadIconFromFile( LPCTSTR fileName ) {
return (HICON)LoadImage( NULL, fileName, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
}
You can also load an icon from an icon resource using LoadIcon.
Code:
LoadIcon( hInst, MAKEINTRESOURCE(INSTALL_ICON) );
To set your system tray icon, assign your icon handle to the hIcon member of NOTIFYICONDATA.
Code:
NOTIFYICONDATA data ;
data.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(INSTALL_ICON) );
To create an icon resource, add a ICON resource statement into a .RC file:
Code:
#include "iconresource.h"
INSTALL_ICON ICON "install.ico"
INSTALL_ICON is the identifier for the icon, which is defined in iconresource.h:
Code:
#define INSTALL_ICON 103
Add the iconresource.h file into your project and compile it.
-
That's great - I'll have a go. Just to clarify, I assume that the:
<fileName> in ... ( NULL, fileName, IMAGE_ICON ...
and
<"install.ico"> in ... INSTALL_ICON ICON "install.ico" ...
are the full filepath and name of the icon on my hard drive that I want to use?
-
It can be the relative path from the current working directory.
-