|
|
Home » U++ Library support » TopWindow&PopUp, TrayIcon » Restoring TrayIcon control
|
|
|
Re: Restoring TrayIcon control [SOLVED] [message #32135 is a reply to message #32099] |
Tue, 26 April 2011 17:20 |
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 |
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
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 23 12:03:48 CEST 2024
Total time taken to generate the page: 0.01178 seconds
|
|
|