LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting and Stopping a running screensaver in LabVIEW

I have been looking for a way to TURN OFF a screensaver once it has started.

 I have programs that run a long time, monitoring a machine.  When the machine notices a certain activity I want to turn the screensaver OFF.  Surprisingly, this has proven difficult, but, I have finally written some code to accomplish this.

I am working with older machines in our factory running Windows XP with LabVIEW 7.1.  I have tried this VI on my desktop running Windows 7 with LabVIEW 2015 but think it would easily translate to the older machine.

The screensaver must be running WITHOUT requiring a password to get back into the system when it is deactivated.  Otherwise, it will come back to the logon screen and not the calling VI.

The loop detects a running screensaver using the SystemParametersInfoA function.  The loop takes a reading every 10seconds just to detect that the screensaver is running.  When it determines it is running it exits the loop.  The screensaver is the FOREGROUND window and NOT the Active window.  So, you get the handle to the foreground window then send it a message to close.  Then you MUST close the reference to that window.  If you do not then you run the risk of closing the VI on subsequent passes.

All variables are set as “pass value” except for the third input into SystemParametersInfoA which is set to “pass pointer to value”.

I’ve kept this running continuously for over an hour on my machine with the screensaver set to come on every 60seconds.  It works well for me considering how hard it was to get information out of Microsoft!  I have not tried using the wizard to set up calls.  I looked up the C++ syntax for all the function calls on the Windows website. The settings I use are:

For any HWND value use U32 (since I have 32 bit machines).

All UNIT values use U32.

All WPARAM, LPARAM values use U32 (for 32bit machine)

All LRESULT values use I32 (again 32bit machines).

All BOOL values use U8 (only one bit is actually used, but, is allowed to be any size).

All PVOID values are U32 (for 32bit machine) passed as “pointer to value”.

 

Download All
Message 1 of 5
(2,720 Views)

I have used the following link  to disable the screensaver so it never comes on. You can look through the program and see if there is a way to stop screensaver once it has come on.

 

Not sure what your question is, if it is just code add it to the Code Exchange board, it looks useful.

 

mcduff

0 Kudos
Message 2 of 5
(2,706 Views)

Very good info to have, thanks. This would be useful if you need to monitor a system and alert if some condition was met, and you didn't want to have to disable the screensaver. Lots of tests run for many hours (or days) at a time and I'd hate to burn in the screen waiting for an error case that may never come.

0 Kudos
Message 3 of 5
(2,689 Views)

Stevej2,

 

Thank you so much for sharing your development process. Is there a particular question you have, or were you wanting to post your solution to add to the overall knowledge of the developer community?\

 

PahlM

 

0 Kudos
Message 4 of 5
(2,646 Views)

@stevej2 wrote:

 

For any HWND value use U32 (since I have 32 bit machines). Pointer sized (Unsigned) Integer

All UNIT values use U32.

All WPARAM, LPARAM values use U32 (for 32bit machine) Pointer sized (Unsigned) Integer

All LRESULT values use I32 (again 32bit machines). Pointer sized (Unsigned) Integer

All BOOL values use U8 (only one bit is actually used, but, is allowed to be any size). The Windows BOOL is really an int value, (so 32 bit integer), while the C++ bool is usually an uint8, but as with everything in C(++) it is not standardized and every C compile is free to use whatever size it would like most. 

All PVOID values are U32 (for 32bit machine) passed as “pointer to value”. Again use Pointer sized (Unsigned) Integer instead.


First, simply configuring the Call Library Nodes yourself is usually the better way to go about interfacing to shared libraries. Despite its name, the Import Library Wizard does not know about magic and that would be the only way to safely create fully functional code from the limited information that a C header file is able to describe. So while this wizard will create VI templates, they can not be trusted to be right and need to be thoroughly reviewed by a knowledgeable person anyways. In most cases the created VIs will at least need some editing to make them both more performance and user friendly and in not so unfrequent cases to make them actually work correctly. And their icon and connection pane arrangement can only be described as ugly too!

 

As to the datatypes used, unless you have any reason to support pre LabVIEW 2009, which only existed as 32 bit version and did not know the pointer sized integer datatype in the Call Library Node, do use this type whenever it is appropriate. You may argue that you are only working on Windows 32 bit anyways, so why should you care, but there comes the time when LabVIEW 32-bit will be discontinued (when Windows will start to flake out on support for 32-bit applications which will eventually happen) and then all your Call Library Nodes need to be changed. LabVIEW on Mac and Linux platforms already discontinued 32-bit application development support. 

 

As to getting the necessary information for this it used to be fairly easy if you installed the Windows SDK files 25 years ago. All the functions and information used here was present even in Windows 3.1 back then and documented there, although to get such an SDK you had to subscribe to MSDN and receive a box of disks and later CD-ROMS to install. I even posted a very similar library to yours back then to Info-LabVIEW, which was/is a mailing list for LabVIEW. Yes websites didn't really exist back then and the NI forums were still more than 5 years in the future Smiley Very Happy.

Also there used to (and I think still does) float around a LabVIEW Windows Utility library that contains a similar VI to control the Windows screen saver (and yes it's 32-bit only as it was written maybe 15 years ago or more).

Rolf Kalbermatter
My Blog
Message 5 of 5
(2,637 Views)