Jump to content
  • Advertisement
Sign in to follow this  
hkBattousai

Hiding and showing a shell notify icon [SOLVED]

This topic is 4313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am working on a system tray icon class for Windows XP, with DevCPP. It all seems to be working. But I got stuck at Hide() and Show() member functions. I have no idea what code to write for them. Any help will be appreciated.
class CTrayIcon
{
	private:
	
	public:
	NOTIFYICONDATA	Nid;
	CTrayIcon();
	void Create(void);
	void Show(void);
	void Hide(void);
	void Modify(void);
	void Kill(void);
	
};

CTrayIcon::CTrayIcon()
{
	Nid.cbSize			= (DWORD) sizeof(NOTIFYICONDATA);
	Nid.uFlags			= (UINT) NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_STATE | NIF_INFO | NIF_GUID;
	Nid.dwState			= (DWORD) NIS_SHAREDICON | NIS_HIDDEN;
	//Nid.dwStateMask		= (DWORD) NIS_SHAREDICON | NIS_HIDDEN;
	Nid.uTimeout		= (UINT) 10;
	//Nid.uVersion		= (UINT) NOTIFYICON_VERSION;
	Nid.dwInfoFlags		= (DWORD) NIIF_INFO;	// NIIF_ERROR, NIIF_NON, NIIF_WARNING, NIIF_ICON_MASK, NIIF_NOSOUND
	//Nid.guidItem		= (GUID) NULL;			// Version 6.0. Reserved	
}

void CTrayIcon::Create(void)
{
	if(!Shell_NotifyIcon(NIM_ADD, &Nid)) DebugTest("Couldn't create the icon.");
}

void CTrayIcon::Show(void)
{
	
	//if(!Shell_NotifyIcon(NIM_MODIFY, &Nid)) DebugTest("Couldn't show the icon.");
}

void CTrayIcon::Hide(void)
{
	
	//if(!Shell_NotifyIcon(NIM_MODIFY, &Nid)) DebugTest("Couldn't hide the icon.");
}

void CTrayIcon::Modify(void)
{
	if(!Shell_NotifyIcon(NIM_MODIFY, &Nid)) DebugTest("Couldn't modify the icon.");
}

void CTrayIcon::Kill(void)
{
	if(!Shell_NotifyIcon(NIM_DELETE, &Nid)) DebugTest("Couldn't kill the icon.");
}
[Edited by - Battousai on September 28, 2006 3:39:45 PM]

Share this post


Link to post
Share on other sites
Advertisement
I just wrote a function like this.


void SysTray(bool enable)
{
enable ? Shell_NotifyIcon(NIM_ADD, &m_sysTray) : Shell_NotifyIcon(NIM_DELETE, &m_sysTray);
}


I don't know if this is how you do it really, but I just ADD it to show it and then DELETE it to hide it.

Share this post


Link to post
Share on other sites
No - adding and deleting are the only known operations. There's no such thing as a tray icon that is added but not displayed.

Share this post


Link to post
Share on other sites
OK, I stand corrected - there is in fact a hidden state. However, it is only available in certain versions of the API (not much of a limitation - anything more recent than Win2000 should have it).

See The Manual for full documentation on the NOTIFYICONDATA structure.

Share this post


Link to post
Share on other sites
Quote:
dwState
Version 5.0. State of the icon. There are two flags that can be set independently.

NIS_HIDDEN
The icon is hidden.
NIS_SHAREDICON
The icon is shared.

dwStateMask
Version 5.0. A value that specifies which bits of the state member are retrieved or modified. For example, setting this member to NIS_HIDDEN causes only the item's hidden state to be retrieved.


Now Hide() works but Show() doesn't. New code is below :

void CTrayIcon::Show(void)
{
Nid.dwStateMask = NIS_SHAREDICON;
if(!Shell_NotifyIcon(NIM_MODIFY, &Nid)) DebugTest("Couldn't show the icon.");
}

void CTrayIcon::Hide(void)
{
Nid.dwStateMask = NIS_HIDDEN;
if(!Shell_NotifyIcon(NIM_MODIFY, &Nid)) DebugTest("Couldn't hide the icon.");
}


By the way, about version, I've already defined :

#define _WIN32_IE 0x0600


[Edited by - Battousai on September 27, 2006 3:51:22 AM]

Share this post


Link to post
Share on other sites
I think you need to reread the documentation, carefully. What is the difference between dwState and dwStateMask?

Share this post


Link to post
Share on other sites
The only thing I found in MSDN is this :
Quote:
dwState
Version 5.0. State of the icon. There are two flags that can be set independently.

NIS_HIDDEN
The icon is hidden.
NIS_SHAREDICON
The icon is shared.

dwStateMask
Version 5.0. A value that specifies which bits of the state member are retrieved or modified. For example, setting this member to NIS_HIDDEN causes only the item's hidden state to be retrieved.
It doesn't make clear usage of dwStateMask.

Unfortunately, the documentation doesn't touch on this detail. I searched the web with google but found nothing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!