C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

help with NOTIFYICON Rate Topic: -----

#1 tootypegs  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 1
  • View blog
  • Posts: 191
  • Joined: 09-October 07


Dream Kudos: 0

Share |

help with NOTIFYICON

Post icon  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
Was This Post Helpful? 0
  • +
  • -


#2 skaoth  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 67
  • View blog
  • Posts: 568
  • Joined: 07-November 07


Dream Kudos: 100

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
Was This Post Helpful? 0
  • +
  • -

#3 tootypegs  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 1
  • View blog
  • Posts: 191
  • Joined: 09-October 07


Dream Kudos: 0

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!

  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
Was This Post Helpful? 0
  • +
  • -

#4 skaoth  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 67
  • View blog
  • Posts: 568
  • Joined: 07-November 07


Dream Kudos: 100

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

View Posttootypegs, 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!

  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

Was This Post Helpful? 0
  • +
  • -

#5 tootypegs  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 1
  • View blog
  • Posts: 191
  • Joined: 09-October 07


Dream Kudos: 0

Re: help with NOTIFYICON

Posted 28 November 2007 - 09:26 AM

Is there any syntax i can put in to use a predefined icon because im not really interested in making my own if its possible? Something like an '!' would be perfect




thanks
Was This Post Helpful? 0
  • +
  • -

#6 tootypegs  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 1
  • View blog
  • Posts: 191
  • Joined: 09-October 07


Dream Kudos: 0

Re: help with NOTIFYICON

Posted 28 November 2007 - 09:46 AM

View Postskaoth, 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



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);

 }



Was This Post Helpful? 0
  • +
  • -

#7 skaoth  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 67
  • View blog
  • Posts: 568
  • Joined: 07-November 07


Dream Kudos: 100

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)
Was This Post Helpful? 0
  • +
  • -

#8 tootypegs  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 1
  • View blog
  • Posts: 191
  • Joined: 09-October 07


Dream Kudos: 0

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


__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
Was This Post Helpful? 0
  • +
  • -

#9 skaoth  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 67
  • View blog
  • Posts: 568
  • Joined: 07-November 07


Dream Kudos: 100

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.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users