FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Current state of the display
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Current state of the display
Posted: Wed Aug 30, 2017 07:40 AM

Is it possible to know the current state of the display - enabled or disabled ?

FWH 17.04/xHarbour BCC7

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Current state of the display
Posted: Wed Aug 30, 2017 08:52 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Current state of the display
Posted: Wed Aug 30, 2017 12:21 PM

Antonio, thanks for your help !

The GetDevicePowerState function takes two parameters. The first parameter is a handle monitor. And how to find it ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Current state of the display
Posted: Wed Aug 30, 2017 02:30 PM
Based on this example:

https://stackoverflow.com/questions/31579658/how-do-i-get-the-status-of-a-display

You could do:

#define MONITOR_DEFAULTTOPRIMARY 1

BOOL bResult;

GetDevicePowerState( MonitorFromWindow( FindWindow( 0, 0 ), MONITOR_DEFAULTTOPRIMARY ), &bResult )

https://msdn.microsoft.com/en-us/library/windows/desktop/dd145064(v=vs.85).aspx
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Current state of the display
Posted: Thu Aug 31, 2017 08:02 AM
I have written so:

Code (fw): Select all Collapse
#include "FiveWin.ch"

#define MONITOR_DEFAULTTOPRIMARY  1

function Main()
local bResult

  GetDevicePowerState( MonitorFromWindow( FindWindow( 0, 0 ),                     MONITOR_DEFAULTTOPRIMARY ), @bResult )
return nil

DLL32 Function GetDevicePowerState(hDevice AS DWORD, @bResult AS BOOL)   AS BOOL PASCAL  FROM "GetDevicePowerState" LIB "kernel32.dll"
DLL32 Function MonitorFromWindow(hDevice AS LONG, pr AS DWORD)   AS BOOL PASCAL  FROM "GetDevicePowerState" LIB "user32.dll"


The function MonitorFromWindow() returns empty. What is my mistake ?
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Current state of the display
Posted: Thu Aug 31, 2017 08:48 AM
DLL32 Function MonitorFromWindow(hDevice AS LONG, pr AS DWORD) AS BOOL PASCAL FROM "MonitorFromWindow" LIB "user32.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Current state of the display
Posted: Thu Aug 31, 2017 08:52 AM
DLL32 Function MonitorFromWindow( hDevice AS LONG, pr AS LONG ) AS LONG PASCAL FROM "MonitorFromWindow" LIB "user32.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Current state of the display
Posted: Thu Aug 31, 2017 11:32 AM

Еhank you, corrected. Now the function GetDevicePowerState returns .F. in any case. And when the display is on and when I turn it off by
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)

Continue the discussion