Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TopWindow&PopUp, TrayIcon » Restoring TrayIcon control
Re: Restoring TrayIcon control [SOLVED] [message #32136 is a reply to message #32135] Tue, 26 April 2011 18:15 Go to previous messageGo to previous message
lucpolak is currently offline  lucpolak
Messages: 18
Registered: April 2008
Location: France
Promising Member
I have another patch to do about the Shell_NotifyIcon function.

There are some problems with this function like discussed here :

http://msdn.microsoft.com/en-us/library/bb762159(v=vs.85).aspx
or here :
http://issuetracker.delphi-jedi.org/bug_view_advanced_page.p hp?bug_id=3747

A solution can be to modify the TrayIcon::Notify function like this :

void TrayIcon::Notify(dword msg)
{
	if(visible) {
		nid.flags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
		if(nid.icon)
			DestroyIcon(nid.icon);
		nid.icon = IconWin32(icon);
		String stip = ToSystemCharset(tip);
		int len = min(stip.GetLength(), 125);
		memcpy(nid.tip, stip, len);
		nid.tip[len] = 0;
		BOOL Status = Shell_NotifyIcon(msg, (NOTIFYICONDATA *)&nid);
		
		// To prevent from Shell_NotifyIcon bugs...
		// discussed here : http://msdn.microsoft.com/en-us/library/bb762159(v=vs.85).aspx
		// and here : http://issuetracker.delphi-jedi.org/bug_view_advanced_page.php?bug_id=3747
		if (Status == FALSE)			
		{
			// The status of Shell_NotifyIcon is FALSE, in the case of NIM_ADD, we will try to Modify
			// If the modify is OK then we cas consider that the add was worked.
			// Same, case with delete, we can try modify and if KO then we can consider that is icon
			// was deleted correctly. In other cases, we will retry after 100ms
			DWORD ErrorCode = GetLastError();
			if ( (ErrorCode == ERROR_SUCCESS) || (ErrorCode == ERROR_TIMEOUT) )
			{
				int retryCount = 0;
				BOOL retryResult;
				do
				{
					Sleep(100);
					if (msg == NIM_ADD) retryResult = Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA *)&nid);
					else if (msg == NIM_DELETE) retryResult = !Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA *)&nid);
					retryCount++;
				}while( (!retryResult) && (retryCount<50) );
			}
		}
    }
}


Thanks for patching.

Lucas
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to get top and left position of top window
Next Topic: [BUG?] X11 (at least OSX) Menus displayed under TopWindow, owner=RootWindow
Goto Forum:
  


Current Time: Tue Jun 04 22:51:17 CEST 2024

Total time taken to generate the page: 0.02434 seconds