Page 1 of 1
help with NOTIFYICON
#1
help with NOTIFYICON
Posted 27 November 2007 - 12:31 AM
Hi, basically i would like to put an icon in the notification area (that little toolbar area near the clock on the desktop - not sure if i called it the right thing). Anyway ive have trawled the internet for research and MSDN gave me 'notifyicon'. After reading and viewong the examples i just cant figure out how to impliment it, everything it talks about is just simply not what i want to learn, i just want to put a basic icon in that tootlbar.
Can anyone start me off or point me in the right direction for maybe some simpler resources to study?
cheers
Can anyone start me off or point me in the right direction for maybe some simpler resources to study?
cheers
#2
Re: help with NOTIFYICON
Posted 27 November 2007 - 07:37 PM
Give this a try and see if it helps
http://msdn2.microso...y/aa453686.aspx.
and here
http://www.codeguru....icle.php/c5933/
The example seems to imply that you will have to have
to know a little about win32. The second examle looks like it
uses MFC.
Also the first example from msdn requires a little fix.
I tried out the example and the icon kept disappearing when I put my
mouse over the icon.
The fix is to add the hwnd of the window to the NOTIFYICONDATA struct.
e.g: nid.hWnd = m_hWnd;
(here m_hWnd is the handle to the main window)
cheers
http://msdn2.microso...y/aa453686.aspx.
and here
http://www.codeguru....icle.php/c5933/
The example seems to imply that you will have to have
to know a little about win32. The second examle looks like it
uses MFC.
Also the first example from msdn requires a little fix.
I tried out the example and the icon kept disappearing when I put my
mouse over the icon.
The fix is to add the hwnd of the window to the NOTIFYICONDATA struct.
e.g: nid.hWnd = m_hWnd;
(here m_hWnd is the handle to the main window)
cheers
#3
Re: help with NOTIFYICON
Posted 28 November 2007 - 01:40 AM
thank you for your help! - i havnt had time to try it out yet but i will!
i was curious how i would manipulate this line of code so i could put an icon in of my choice?
thanks
nid.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_SAMPLEICON));
i was curious how i would manipulate this line of code so i could put an icon in of my choice?
thanks
#4
Re: help with NOTIFYICON
Posted 28 November 2007 - 08:19 AM
The IDI_SAMPLEICON is part of the resource file within the win32 project.
You simply have to add an icon resource to the project and replace
"IDI_SAMPLEICON" with the one you just created.
Here is how to add a icon resource
http://www.functionx...urces/icons.htm
Hope that helps
You simply have to add an icon resource to the project and replace
"IDI_SAMPLEICON" with the one you just created.
Here is how to add a icon resource
http://www.functionx...urces/icons.htm
Hope that helps
tootypegs, on 28 Nov, 2007 - 02:40 AM, said:
thank you for your help! - i havnt had time to try it out yet but i will!
i was curious how i would manipulate this line of code so i could put an icon in of my choice?
thanks
nid.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_SAMPLEICON));
i was curious how i would manipulate this line of code so i could put an icon in of my choice?
thanks
#6
Re: help with NOTIFYICON
Posted 28 November 2007 - 09:46 AM
skaoth, on 27 Nov, 2007 - 08:37 PM, said:
Also the first example from msdn requires a little fix.
I tried out the example and the icon kept disappearing when I put my
mouse over the icon.
The fix is to add the hwnd of the window to the NOTIFYICONDATA struct.
e.g: nid.hWnd = m_hWnd;
(here m_hWnd is the handle to the main window)
cheers
I tried out the example and the icon kept disappearing when I put my
mouse over the icon.
The fix is to add the hwnd of the window to the NOTIFYICONDATA struct.
e.g: nid.hWnd = m_hWnd;
(here m_hWnd is the handle to the main window)
cheers
Sorry for the double post, i sorted my icon problem out now. However just as you said, the icon diserpears when ever i put my mouse on it. Ive read how you said to fix it but im just not understanding it......sorry:( would it be possible to explain a lil more, im a bit of a newbie
void __fastcall TForm1::Button1Click(TObject *Sender)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof(nid);
nid.uID = 100; // Per WinCE SDK docs, values from 0 to 12 are reserved and should not be used.
nid.uFlags = NIF_ICON;
nid.hIcon = LoadIcon(NULL,IDI_ASTERISK);
// Add the notification to the tray.
Shell_NotifyIcon(NIM_ADD, &nid);
}
#7
Re: help with NOTIFYICON
Posted 28 November 2007 - 10:24 AM
What you need to do is associate the window handle (aka hwnd) to the NOTIFYICONDATA structure.
Depending on how you created your window or dialog will dictate how the HWND (handle to a window)
is used.
For example if you are using ATL/WTL, the base classes have a memer varialbe called m_hwnd that
represents the handle to the window.
If you created the window your self by calling
CreateWindowEx() or CreateWindow() then the return value from that
is the handle to the window.
Here is the prototype from MSDN
HWND CreateWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
As you can see the return value is a HWND structure. This value needs to be accessible to the
function you created Button1Click()
This value needs to be assigned to nid.hWnd.
By the way how are you creating the Window for your program? (MFC, win32, WTL/ATL)
Depending on how you created your window or dialog will dictate how the HWND (handle to a window)
is used.
For example if you are using ATL/WTL, the base classes have a memer varialbe called m_hwnd that
represents the handle to the window.
If you created the window your self by calling
CreateWindowEx() or CreateWindow() then the return value from that
is the handle to the window.
Here is the prototype from MSDN
HWND CreateWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
As you can see the return value is a HWND structure. This value needs to be accessible to the
function you created Button1Click()
This value needs to be assigned to nid.hWnd.
By the way how are you creating the Window for your program? (MFC, win32, WTL/ATL)
#8
Re: help with NOTIFYICON
Posted 28 November 2007 - 03:13 PM
I am using Borland c++, sorry my knowledge of c++ is very basic. It comes with a form function. Within the form i just placed a button in which this contains all of the code
This is the structure of my program. So would i put the hwnd structure within the button area??
Thanks for the help
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
void __fastcall TForm1::Button1Click(TObject *Sender)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof(nid);
nid.uID = 100; // Per WinCE SDK docs, values from 0 to 12 are reserved and should not be used.
nid.uFlags = NIF_ICON;
nid.hIcon = LoadIcon(NULL,IDI_ASTERISK);
// Add the notification to the tray.
Shell_NotifyIcon(NIM_ADD, &nid);
}
}
This is the structure of my program. So would i put the hwnd structure within the button area??
Thanks for the help
#9
Re: help with NOTIFYICON
Posted 28 November 2007 - 06:29 PM
Well, I don't know anything about Borland C++ and how it does
its window management sorry.
If you can find out where the CreateWindow() function is being called
then you can copy the hwnd from that to a global variable.
The global variable should then be accessible to your button handler.
However, from the code snippet you provided it seems that
there is a possibility that the TForm class you are deriving from
may also hold the windows hwnd. This I don't know for sure,
so it may be worth looking into the borland API to see if it does.
If none of that works out, you can try and use FindWindow()
e.g: FindWindow(NULL, "WindowTitle");
http://msdn2.microso...y/aa929233.aspx
Hope that helps.
its window management sorry.
If you can find out where the CreateWindow() function is being called
then you can copy the hwnd from that to a global variable.
The global variable should then be accessible to your button handler.
However, from the code snippet you provided it seems that
there is a possibility that the TForm class you are deriving from
may also hold the windows hwnd. This I don't know for sure,
so it may be worth looking into the borland API to see if it does.
If none of that works out, you can try and use FindWindow()
e.g: FindWindow(NULL, "WindowTitle");
http://msdn2.microso...y/aa929233.aspx
Hope that helps.
Page 1 of 1

Ask A New Question
Reply






MultiQuote




|