Windows 7 Display on/off event issue?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
rajan_m
Knows some wx things
Knows some wx things
Posts: 39
Joined: Tue Jan 20, 2009 10:37 am
Location: chennai

Windows 7 Display on/off event issue?

Post by rajan_m »

Hi,

I'm trying to capture display on/off event using following code, able to capture off event but not on.

Code: Select all

WXLRESULT MyFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
	wxTextCtrl* textctrl = (wxTextCtrl*)FindWindowById(MOUSE_TEXT,this);
 
	if(nMsg == WM_SYSCOMMAND )
	{
		if(wParam == SC_MONITORPOWER)
		{
			if(lParam == -1)
				textctrl->AppendText("monitor on\n");	//not working

			if(lParam == 2)
				textctrl->AppendText("monitor off"));	//working
		}
	}
}
I'm not understanding where its going wrong. Help me to solve this issue.

Regards,
Rajan.M
Every exit is an entry somewhere else!
DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 231
Joined: Mon Jan 19, 2015 1:45 pm

Re: Windows 7 Display on/off event issue?

Post by DenDev »

It might be caused by a signing issue, have you tried casting -1 to WXLPARAM?

Code: Select all

...
if(lParam == (WXLPARAM)-1) textctrl->AppendText("monitor on\n");
...
If this does not help you can try to log the value of lParam on order to see what the value is when the monitor is turned on.
I have a bad habbit of not testing the code I post :D
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Windows 7 Display on/off event issue?

Post by doublemax »

If i understand the MSDN documentation correctly, these commands can be used to actively change the monitor power status, not to get notified when it changes.
Use the source, Luke!
Post Reply