| View previous topic :: View next topic |
| Author |
Message |
Dave England Newbie
Joined: 22 Aug 2003 Posts: 3
|
Posted: Fri Aug 22, 2003 3:06 pm Post subject: How to tell vds when pc wants to shut down ? |
|
|
He ya !
I want to log the time I spent working with my pc
so everytime computer shuts down I want to
write the variable in text file.
ok not a problem so far, but:
How I know when Computer logs off, reboot or shutdown?
I had the following idea:
:close
info application closed
....blaŽbla write variable
exit
hmmm dont works but Ive seen it in several applications, for example my
image editing software asks when im trying to shut down... "you want to save your work"
thx in advance if you could help me !  |
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1566
|
Posted: Fri Aug 22, 2003 4:46 pm Post subject: |
|
|
Windows sends all windows a WM_QUERYENDSESSION message, this tells each and every program opened in Windows that it is about to terminate (shutdown, restart).
It may be possible to intercept such a message with VDS and appropriately write your files to disk.
Windows will then immediately send a WM_ENDSESSION, you must then pass back True or False to tell it you are ready to allow a shutdown. Sending a false will halt windows from shutting down and/or may cause your application to terminate and a forced shutdown/restart will occur. You should in almost all circumstances send back a TRUE message to allow you application to close and let Windows terminate. |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Fri Aug 22, 2003 5:35 pm Post subject: |
|
|
This is possible in VDS 5.x using built in fn
using
OPTION MSGEVENT, $11, shutevent
and then under
:shutevent
IF @NOT(@ZERO(@MSGPARAMS( W ) ))
Event name do whatever you want
EXIT
END
GOTO EVLOOP
SORRY IT MAY NOT BE AS SIMPLE (above code cannot work). You should process the message and give a return value. If you set it to false(0) then windows will stop shutdown and after you complete your work you should your self call system shutdown.
However if you are writing someting small to text file that can be completed under 1sec. then above idea may help.
Regards _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension
Last edited by CodeScript on Fri Aug 22, 2003 6:14 pm; edited 3 times in total |
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Fri Aug 22, 2003 6:00 pm Post subject: |
|
|
| Quote: | I had the following idea:
:close
info application closed
....blaŽbla write variable
exit |
This should work in VDS 5. My system tray apps all use it to shut down cleanly. Earlier versions didn't branch to the close label on shutdown, though... _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
Dave England Newbie
Joined: 22 Aug 2003 Posts: 3
|
Posted: Fri Aug 22, 2003 6:21 pm Post subject: nice, thx |
|
|
thanx for all answers
you guys helped me alot  |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Fri Aug 22, 2003 11:53 pm Post subject: |
|
|
I've been wondering how to do this too for awhile now. So is it
better to use the OPTION MSGEVENT or just the close label with
VDS 5?  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Sat Aug 23, 2003 2:54 am Post subject: |
|
|
| FreezingFire wrote: | I've been wondering how to do this too for awhile now. So is it
better to use the OPTION MSGEVENT or just the close label with
VDS 5?  |
Sorry FF I don't know I may test some time. FF did you test the XYNTService.exe I gave you long back ?
Just wanted to know - No obligations.
Hi Dave England
Just a few Ideas.
If the write operation under close label still does not work then
continuosly write to file under a timer say every 0.1 second the current
time.
Accuracy will be upto 0.2 seconds. I think it should be OK for general
purposes.
| Code: |
:EVLOOP
WAIT EVENT,0.1
:TIMER
REM Add Your file write commands here
GOTO EVLOOP
|
If you are on NT based system (Win 2k/NT/XP) and VDS 5 and willing to use windows API then you have even more options.
1.Run the app as a NT service (use XYNTService.exe a freeware utility) so that it doesnot exit even if the user logs off untill the computer is
shutdown!.
2. Use GetUserName API to get the currently logged on user* every time you write to file under the timer and write it with the time. (make seperate ini sections for each user)
This way you can get the session duration info for each of the users.
* = You may have to call another exe to get this info as the service will be run under "system account". Not very sure.
I don't know if you want these advanced options but if you want any more
info let me know. I will help whatever I can.
Regards _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sun Aug 24, 2003 12:21 am Post subject: |
|
|
hi pg,
i tried before to use your suggestion and got nowhere...would you be able to put together some sample code on using WM_ENDSESSION to detect within a vds program when windows shutsdown ...
thanks in advance
serge _________________
|
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1566
|
Posted: Sun Aug 24, 2003 6:01 pm Post subject: |
|
|
Hi Serge,
Unfortunately I haven't played around with the LOADLIB examples enough to write up an example yet. I think CodeScript gave you the correct function to use in VDS directly which most likely is using these api's anyway:
OPTION MSGEVENT, $11, shutevent |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Sun Aug 24, 2003 6:20 pm Post subject: |
|
|
I will try if it works sometime but will take lot of time on my slow computer rebooting every test.
BTW if it works as jules said then that would be better as with PGWARE's and my example shut down is not delayed anyway to offer addditional benefit. If you want that I think it's too complicated.As I said
| Quote: | | You should process the message and give a return value. If you set it to false(0) then windows will stop shutdown and after you complete your work you should your self call system shutdown. |
Regards _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Mon Aug 25, 2003 3:03 am Post subject: |
|
|
skit I think this should be the correct solution. It will then execute the code and on completion the DefWindowProc function in the VDS runtime will return true so that system can shutdown. Everything has already been coded into VDS !!
I assumed that there is no such function even without searching the help (RTFM ... You know what it is )
thoroughly.
Regards _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Mon Aug 25, 2003 8:50 am Post subject: |
|
|
thanks for your answer pg...i was after a solution for vds 4.x as the one suggested is for vds 5...anyone have any idea how to use WM_ENDSESSION in vds 4.x to pick up within a vds program if windows is going to shutdown?
thanks in advance
serge _________________
|
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Mon Aug 25, 2003 10:15 am Post subject: |
|
|
IMHO no solution short of writing a custom dll. _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
|