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
Restoring TrayIcon control [message #32074] Wed, 20 April 2011 09:53 Go to next message
lucpolak is currently offline  lucpolak
Messages: 18
Registered: April 2008
Location: France
Promising Member
Hello, i have another problem with the tray icon.

When the explorer.exe crashes (oh yes it's happens Razz), the trayicon is not correctly restored.

For example, here is my TrayIcon :
index.php?t=getfile&id=3187&private=0

I kill explorer.exe (sorry for ms Twisted Evil ) and restart it and my trayIcon is missing Sad
index.php?t=getfile&id=3188&private=0

So the question is : Can I handle this ? Can i detect an explorer crash and restore the TrayIcon Ctrl ?

Thanks a lot Smile

Lucas
  • Attachment: tray1.png
    (Size: 12.06KB, Downloaded 768 times)
  • Attachment: tray2.png
    (Size: 3.49KB, Downloaded 954 times)
Re: Restoring TrayIcon control [message #32099 is a reply to message #32074] Fri, 22 April 2011 09:56 Go to previous messageGo to next message
lucpolak is currently offline  lucpolak
Messages: 18
Registered: April 2008
Location: France
Promising Member
Up up Smile

I found on the web that restoring the TrayIcon can be made by catching the WM_TASKBARCREATED message.

It can be done by declaring this in the WindowProc fct :

// Somewhere in the code or header ....
UINT WM_TASKBARCREATED = 0 ;


// In the WindowProc
if (message == WM_CREATE)
    WM_TASKBARCREATED = RegisterWindowMessageA("TaskbarCreated");

if (message == WM_TASKBARCREATED)
{
  // Restore the icon ... how can i do it ?
}


I've tried de call TrayIcon::Show() method but it crash with a Shell_NotifyIcon Exception because in the Notify Fonction (TrayIconWin32.cpp) we have this line :

	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;
		VERIFY(Shell_NotifyIcon(msg, (NOTIFYICONDATA *)&nid));


I change this to :

	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;
		while (Shell_NotifyIcon(msg, (NOTIFYICONDATA *)&nid) == FALSE)
		{
			Sleep(100);
		}


but it change nothing ...

Helps please Razz
Re: Restoring TrayIcon control [message #32133 is a reply to message #32099] Tue, 26 April 2011 16:25 Go to previous messageGo to next message
lucpolak is currently offline  lucpolak
Messages: 18
Registered: April 2008
Location: France
Promising Member
Hello,

nobody can helps me Sad ?

I'm trying to understand the mecanism of UPP windows and it's not easy Razz.

I'm find in the Win32Wnd.cpp the main WndProc witch enables me to initialize correctly my WM_TASKBARCREATED variable. This piece of code works fine and catch correctly the explorer.exe crashes :

LRESULT CALLBACK Ctrl::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message == WM_CREATE)
	{
		WM_TASKBARCREATED = RegisterWindowMessageA("TaskbarCreated") ;
		ELOG("Ctrl::TASKBARCREATED = "<<WM_TASKBARCREATED);
	}
	
	if (message == WM_TASKBARCREATED)
	{
		ELOG("Ctrl::TASKBARCREATED");
		// How can i translate and recreate order to the TrayIcon class ?
	}
[...]


But how can I recreate tray icon when the message WM_TASKBARCREATED is received ???? How can i Translate this message to the TrayIcon::WindowProc ????

HElps Helps helps .... Sad

Lucas
Re: Restoring TrayIcon control [SOLVED] [message #32135 is a reply to message #32099] Tue, 26 April 2011 17:20 Go to previous messageGo to next message
lucpolak is currently offline  lucpolak
Messages: 18
Registered: April 2008
Location: France
Promising Member
After a long time, i've found the solution :

In CtrlCore, add a static variable to the class Ctrl to store the value of Windows Message TaskbarCreated :

[...]
#ifdef PLATFORM_WIN32 
	static UINT WM_TASKBARCREATED;
#endif

	static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


In Win32Wnd.cpp, initialize this static variable :


static bool sFinished;

UINT Ctrl::WM_TASKBARCREATED = 0;
[...]


And in the WndProc function, Register the TaskbarCreated Message :

if (message == WM_CREATE)
	{
		WM_TASKBARCREATED = RegisterWindowMessageA("TaskbarCreated") ;
		ELOG("Ctrl::TASKBARCREATED = "<<WM_TASKBARCREATED);
	}


Finally, in the TrayIconWin32.cpp, restore the icon if needed :


LRESULT TrayIcon::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{	
	if (message == WM_TASKBARCREATED)
	{
		RLOG("TrayIcon::WM_TASKBARCREATED");
		visible = false;
		Show();
	}
	else if(message == UM_TASKBAR_)
[...]


So, can you integrate it in the next revision of Upp ?

Thanks,

Lucas

Re: Restoring TrayIcon control [SOLVED] [message #32136 is a reply to message #32135] Tue, 26 April 2011 18:15 Go to previous messageGo to next 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
Re: Restoring TrayIcon control [SOLVED] [message #32138 is a reply to message #32135] Wed, 27 April 2011 06:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
lucpolak wrote on Tue, 26 April 2011 11:20


So, can you integrate it in the next revision of Upp ?

Thanks,

Lucas




Yes! And sorry for delay. Good find.
Re: Restoring TrayIcon control [SOLVED] [message #32139 is a reply to message #32136] Wed, 27 April 2011 07:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
lucpolak wrote on Tue, 26 April 2011 12:15

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



Applied in altered form (what if notify is NIM_MODIFY? Smile

Mirek
Re: Restoring TrayIcon control [SOLVED] [message #32147 is a reply to message #32139] Thu, 28 April 2011 08:59 Go to previous message
lucpolak is currently offline  lucpolak
Messages: 18
Registered: April 2008
Location: France
Promising Member
mirek wrote on Wed, 27 April 2011 07:14



Applied in altered form (what if notify is NIM_MODIFY? Smile

Mirek



It's right Smile

Thanks a lot for patching. ^^
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: Thu Apr 18 02:35:04 CEST 2024

Total time taken to generate the page: 0.02072 seconds