Posted by Filip on May 30, 2006 In Reply to controlling the screen in delphi posted by Josh
on
May 16, 2006 Switch monitor OFF: Switch monitor ON: Problem: if I program OFF with a button-click, the monitor is always switched ON again after a few seconds. That's because on my system the monitor is switched "ON" automatically upon a mouse or keyboard action. Solution: let Windows "digest" the mouse click on the button by waiting a short while before switching the monitor OFF. Code example, tested under Delphi 7: procedure TForm1.btnOffClick(Sender: TObject); var StartTime: Cardinal; begin // Switch monitor off after second StartTime := GetTickCount; while GetTickCount < StartTime + 1000 do Application.ProcessMessages; SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2); // Switch monitor on again after 15 seconds StartTime := GetTickCount; while GetTickCount < StartTime + 15000 do Application.ProcessMessages; SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1); end; |