Page 1 of 1

TaskbarCreated notification support (example included)

Posted: Fri Mar 24, 2006 2:27 am
by Rescator
It seems this is lacking in PB currently!

The way I made it work was this:

Code: Select all

;Put this somewhere early in the app, along with the window creation
taskbarrestart=RegisterWindowMessage_("TaskbarCreated")
Now in your window callback add this:

Code: Select all

Procedure.l WindowCallback(hwnd,message,wparam,lparam)
Protected result.l=#PB_ProcessPureBasicEvents
 Select message
  Case taskbarrestart
   ;Tray icon recreate code here or maybe call a procedure that does this.
 EndSelect
ProcedureReturn result
Endprocedure
This wasn't so much of a issue for me as I was allready using a window callback,
but I'm sure PureBasic purists and beginners will have issues.
And the fact that it annoys the crap out of me when applications do not recreate their tray icons if explorer.exe should "die" and be restarted.

So, Fred pretty please :)
Could you find a way to do this?

I'm not sure if RegisterWindowMessage_("TaskbarCreated") should always be "implemented" or just when systrayicons are used.
Also, older Windows does not support this message. (should do no harm though obviously since it's just a message).

As far as the user/programmer side of things go,
I was thinking of possibly a #PB_Event_TaskbarCreated
so that a programmer could easily just check if this window event is triggered, and then do whatever they need to do.
(like re-create tray icon, or whatever else they may have done with the task bar).

Here is a code example from the PSDK, but it did not work at all here for me. It seemed that WM_CREATE never happen when I killed explorer.exe and restarted it.
My PB example as described above though works perfectly,
so I got no clue what WM_CREATE is in this but it's M$ documentation...
:lol:

Code: Select all

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, 
                         LPARAM lParam)
{
    static UINT s_uTaskbarRestart;

    switch(uMessage)
    {
        case WM_CREATE:
            s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
            break;
        
        default:
            if(uMessage == s_uTaskbarRestart)
                AddTaskbarIcons();
            break;
    }

    return DefWindowProc(hWnd, uMessage, wParam, lParam);
}