Current state of the display

Current state of the display

Postby Natter » Wed Aug 30, 2017 7:40 am

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

FWH 17.04/xHarbour BCC7
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Current state of the display

Postby Antonio Linares » Wed Aug 30, 2017 8:52 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42068
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Current state of the display

Postby Natter » 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 ?
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Current state of the display

Postby Antonio Linares » Wed Aug 30, 2017 2: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42068
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Current state of the display

Postby Natter » Thu Aug 31, 2017 8:02 am

I have written so:

Code: Select all  Expand view
#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 ?
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Current state of the display

Postby Antonio Linares » Thu Aug 31, 2017 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42068
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Current state of the display

Postby Antonio Linares » Thu Aug 31, 2017 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42068
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Current state of the display

Postby Natter » 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)
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 39 guests