Answer the question
In order to leave comments, you need to log in
How to track an event something like "Tray is being created"?
My application is started by a service and adds an icon to the system tray on startup. The problem is that if the user did not immediately log in (entered the password for a long time), the application, although launched by the service, but without a tray icon, did not yet exist when the software tried to create an icon.
There is also such a drawback: if you "kill" the Explorer.exe process in the task manager, and then create a new one in the same place, then all the icons in the tray are restored, but mine is not. Apparently, you need to catch some kind of event like "Tray is being created" and, if it occurs, react by adding your own icon. Actually a question: what for event and how to react? (Win 7 & Win XP)
Answer the question
In order to leave comments, you need to log in
Monitor the window handle of the taskbar and tray. Once a minute or 30 seconds. Stupid, but not very resource intensive. If the handle has changed, then add an icon.
function TaskbarHandle: THandle;
begin
Result := FindWindow('Shell_TrayWnd', nil);
end;
function TrayHandle: THandle;
begin
Result := FindWindowEx(TaskbarHandle, 0, 'TrayNotifyWnd', nil);
end;
//ловим событие WM_TaskbarCreated
procedure TmwdForm.WndProc(var msg: TMessage);
begin
inherited;
if msg.Msg = WM_TaskbarCreated then
<что-то делаем>
end;
...
...
initialization
WM_TASKBARCREATED := RegisterWindowMessage('TaskbarCreated');
end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question