Mega Code Archive

 
Categories / Delphi / VCL
 

Handling the TaskbarRestart Message

Title: Handling the TaskbarRestart Message Question: Icons in the system tray are fine. There are serveral articles on Delphi3000 that cover this topic. But there is some aspect missing. There are times when "Explorer" must restart. In this moments you can see which application handle this case correctly and which do not. Those application that do not show up again in the systray missed a small detail. In a similar situation is a service program that starts before login. Answer: When explorer (re)starts the systray as part of the taskbar is rebuilt. This event is signaled by the global message "TaskbarCreated". Here some pseudo code (!!) for handling the TaskbarRestart Message to (re)register to the systray. Declare some where a variable fwm_TaskbarRestart:cardinal; to hold the message id. Assume our message handler / filter is procedure OnMessage(var Msg: TMessage). Initialize (in a initialzation section or form create procedure) fwm_TaskbarRestart as follows: fwm_TaskbarRestart:=RegisterWindowMessage('TaskbarCreated'); and handle the event in the message handler procedure OnMessage(var Msg: TMessage); case Msg.Msg of Wm_QueryEndSession: .... Wm_EndSession: .... else // if we do not own the message id we cannot handle the even if fwm_TaskbarRestart0 then // if the message is ours if Msg.Msg=fwm_TaskbarRestart then // try to register to the systray if not Shell_NotifyIcon(Nim_Add, @fData) then // if we cannot restore the application to a visible state or shut dow Restore; end; Thats it!