View previous topic :: View next topic |
Author |
Message |
DaveR Valued Contributor
Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Sun Jan 01, 2006 4:41 am Post subject: Restore Tray Icon after desktop crash... |
|
|
I read about this just the other day, but can't find the topic again. I think I didn't create a favorite for it because it was not possible.
So, is it possible for a VDS tray app to restore it's tool tray icon after the windows desktop has crashed? _________________ cheers
Dave
Last edited by DaveR on Mon Jan 02, 2006 12:27 am; edited 2 times in total |
|
Back to top |
|
|
DaveR Valued Contributor
Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Sun Jan 01, 2006 10:06 am Post subject: |
|
|
Ok, lacking a proper API solution, I have worked out a usable VDS solution.
Code: |
rem Use 2 identical icons
#RESOURCE ADD, ICON, Icon_1.ico
#RESOURCE ADD, ICON, Icon_2.ico
rem Create main dialog with Icon_1 taskicon here
rem Place timer before evloop, and after create main dialog code.
rem Start Timer to Swap Tray Icon after 10 seconds
timer start,1,ctdown,00-00:00:10
:EvLoop
wait event
goto @event()
:TIMER1CTDOWN
rem Swap Tray Icon
if @equal(2,%%TrayIcon)
dialog set,trayicon,#Icon_1.ico
%%TrayIcon = 1
else
dialog set,trayicon,#Icon_2.ico
%%TrayIcon = 2
end
rem Start new 10sec countdown timer
timer start,1,ctdown,00-00:00:10
goto evloop
|
_________________ cheers
Dave |
|
Back to top |
|
|
DaveR Valued Contributor
Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Mon Jan 02, 2006 12:26 am Post subject: |
|
|
Darnit! I had the Windows desktop crash so I restarted Explorer... but my tray app's icon did not reappear. _________________ cheers
Dave |
|
Back to top |
|
|
CodeScript Moderator Team
Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Mon Jan 02, 2006 4:01 pm Post subject: |
|
|
May be possible with API also (try option msgevent)
It can also be done more easily using VDSGUI extension.. _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
Back to top |
|
|
WidgetCoder Contributor
Joined: 28 May 2002 Posts: 126 Location: CO, USA
|
Posted: Wed Feb 01, 2006 12:46 am Post subject: WorkAround - Restoring TrayIcon after explorer crashes |
|
|
Dave,
Windows does send a registered message (TaskbarCreated) once explorer created or recreated the Taskbar/notification area. But unfortunately VDS's runtime doesn't pass this message to the "Option Msgevent" function. The code below should work but doesn't:
Code: |
rem obtain message number set msgevent
loadlib user32.dll
%X = @lib(user32, RegisterWindowMessageA, INT:, TaskbarCreated)
freelib user32.dll
option msgevent,%X,TaskBarCreated
:TaskBarCreated
rem replace icon here
goto evloop
|
Workaround: Each time explorer is restarted it receives a new PID so by comparing ID's you can determine if explorer has restarted or not. Run the sample below kill "explorer.exe" using task manager and then run explorer from taskman's File|New Task(Run...) menu to test it for yourself.:
Code: |
Title SysTray Restore Test
option fieldsep,|
# Grab the process ID for explorer.exe
list create,1
list tasklist,1,ni
If @greater(@count(1),0)
list seek,1,0
if @match(1,explorer.exe|)
parse "%%Proc;%%PID",@item(1)
else
warn @chr(34)explorer.exe@chr(34) Not Running
stop
end
Else
warn Tasklist Error
stop
End
dialog create,SysTray Icon Restore Workaround,-1,0,310,37
dialog add,text,txt1,12,9,,,Explorer.exe's PID: @chr(34)%%PID@chr(34)
dialog show
dialog add,taskicon,TTicon,,I'll be back
:TTiconCLICK
:Evloop
wait event,2
goto @event()
:Timer
# Test to see if Explorer's PID has changed
list clear,1
list tasklist,1,ni
IF @greater(@count(1),0)
list seek,1,0
If @match(1,explorer.exe|)
parse "%X;%I",@item(1)
if @unequal(%I,%%PID)
# Explorer has restarted - remove and reload trayicon
dialog remove,TTicon
dialog add,taskicon,TTicon,,I'm back
dialog set,txt1,Old PID: @chr(34)%%PID@chr(34) - New PID: @chr(34)%I@chr(34)
%%PID = %I
end
End
END
goto evloop
:Close
list close,1
exit
|
BTW: If your planning to minimize your app to the system tray see:
http://www.vdsworld.com/forum/viewtopic.php?p=26993&highlight=#26993
Best Regards,
Bill |
|
Back to top |
|
|
DaveR Valued Contributor
Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Wed Feb 01, 2006 3:04 am Post subject: |
|
|
That's excellent, Bill.
It works perfectly. Thanks. _________________ cheers
Dave |
|
Back to top |
|
|
WidgetCoder Contributor
Joined: 28 May 2002 Posts: 126 Location: CO, USA
|
Posted: Wed Feb 01, 2006 3:39 pm Post subject: |
|
|
Glad to be of assistance, I was struggling with the same issue. |
|
Back to top |
|
|
WidgetCoder Contributor
Joined: 28 May 2002 Posts: 126 Location: CO, USA
|
Posted: Wed Feb 01, 2006 5:17 pm Post subject: |
|
|
Dave,
I found a more efficient way of restoring the TaskIcon using the SysTray's Window ID much in the same way try this:
Code: |
Title TrayIcon Restore 2
# Grab the Window ID for the System Tray
%%WID = @winexists(#shell_TrayWnd)
dialog create,SysTray Icon Restore Workaround 2,-1,0,310,37
dialog add,text,txt1,12,9,,,
dialog show
if %%WID
dialog add,taskicon,TTicon,,I'll be back
dialog set,txt1,SysTray's WindowID: @chr(34)%%WID@chr(34)
else
warn No System Tray Window
stop
end
:TTiconCLICK
:Evloop
wait event,2
goto @event()
:Timer
# Test to see if the SysTray's Window ID has changed
%I = @winexists(#shell_TrayWnd)
if @both(@unequal(%I,%%WID),%I)
# SysTray has restarted - remove and reload trayicon
dialog remove,TTicon
dialog add,taskicon,TTicon,,I'm back
dialog set,txt1,Old WindowID: @chr(34)%%WID@chr(34) - New WindowID: @chr(34)%I@chr(34)
%%WID = %I
end
goto evloop
:Close
exit
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|