[fpc-pascal] Windows API SendMessage()

James Richters james at productionautomation.net
Thu Aug 10 03:27:57 CEST 2017


I'm trying to use SenMessage() to turn the display on or off under program
control of a console application.    I got the function to work, and it
turns off the display, but then the program just hangs.  

Does anyone know what I am doing wrong?

 

Here's my sample program

Program Displaycontrol;

Uses Windows;

Begin

  Writeln('Turning Off Display');

  SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
//This seems to work, turning off my display

  Writeln('Display is Off');                      // This Writeln never
happens.    I need to force terminate the program.

  sleep(10000);

  Writeln('Turning On Display');

  SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);

  Writeln('Display is On');

End.

 

James

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170809/4ac6bd5e/attachment.html>


More information about the fpc-pascal mailing list