[fpc-pascal] Windows API SendMessage()

James Richters james at productionautomation.net
Thu Aug 10 13:11:35 CEST 2017


>You need to use PostMessage if you want to your program to work correctly. SendMessage waits reply and you don't have a message pump in your console application, thus a hang happens.

Thank you... PostMessage() works to turn off the display, but for some strange reason it can't turn it back on.   I set a 20 second delay, and precisely at 20 seconds my  monitor light turns green, but then the monitor goes back to sleep before the screen can be displayed.  I'm guessing the signal is being sent to turn on the monitor, but not to get windows out of power save mode...  I also  see using -1 to turn the display back on is an un-documented feature.    I can get the display back on with a keystroke or moving the mouse, but I'm wanting the program to turn the display back on without user input.  Can anyone think of any other way I could make my console application to turn the display back on without user input?  

I've tried 

progname := FindWindow('displaycontrol', nil);
PostMessage(progname, WM_KEYDOWN, VK_F5, 0);

And while the key sent to the program,  it does not wake the display up.   I see other examples of simulating keyboard input, but I haven't been able to get them to work in a freepascal console application.

James





More information about the fpc-pascal mailing list