|
First, thanks for the code.
Saved me some time looking up win api code
But what is really the diffence between standby and off?
I've tested both (I'm currently on my laptop) and can't see any diffence...
Regards,
Oyvind Eriksen
|
|
|
|
|
I have to say I don't ever know...
|
|
|
|
|
hi all,
i have impelemented by your method, it works fine, but not for below case:
while playing songs by mediaplayer (or other players), i manually switch monitor off by that funciton, it works till player change to next song.
anyway to keep it always blank unless only when i keypressed or mousemoved?
thanks
|
|
|
|
|
Take a look at Michael Dunn's post (FYI)...
|
|
|
|
|
Is there any way to change monitor's (display)brightness and contrast by code?
Thx for any help...
|
|
|
|
|
Did u got any updates on ur query, even im having the same need, help me out if u found a solution. thanks a ton!!
|
|
|
|
|
WmiSetBrightness Method of the WmiMonitorBrightnessMethods Class
The WmiSetBrightness method sets the display brightness of a computer monitor.
|
|
|
|
|
|
Hmmm, obviously Raymond is right.
I wrote:
If you don't want to bother creating a window to send the message to, you can send the message to all top level windows (HWND_BROADCAST) or you can use GetDesktopWindow function sending the message to the desktop window.
So it's preferable to say "always create a window and use its handle" or if you don't want to bother creating a window to send the message to then don't use this method.
|
|
|
|
|
Great program! I like it.
And is there a similar solution to directly turn off a hard-disk?
I need such a small program for testing purposes!
Please help
|
|
|
|
|
Hi,
Can you use this to detect when a screen goes into a different power mode? I would like to make an application which pauses itself when the machine is unattended for a period of time and was going to use the screen going into power-save mode. I found the SENS COM+ interface which notifies an application of a bunch of useful things. I had assumed that the screensaver notification it delivers would also tell me about the screen blanking if the energystar setting is selected, but it doesn't.
|
|
|
|
|
|
I rated this as a 5 (to my surprise), because I like simple solutions to problems. I know finding the solution is not always easy, which you did. I hope some one adds this to a FAQs some where.
INTP
Every thing is relative...
|
|
|
|
|
|
I can use SendMessage or PostMessage to turn on or turn off the monitor. The problem is I have multiple VGA cards that link to multiple monitors. I just want to turn off the individual one. Can anybody help me?
|
|
|
|
|
Hi, I think this is not possible using the standard WinAPI.
|
|
|
|
|
Hi,
This is nice exe and working perfectly.But i tried using C# and found its not workking , i think i am missing somewhere plz guid me .
I used the code as folows.
The name space I used is :
using System.Runtime.InteropServices;
Now I declared the varrbale
const int MONITOR_ON = -1;
const int MONITOR_OFF = 2;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MONITORPOWER = 0xF170;
const UInt32 ES_CONTINUOUS = 0x80000000;
//declared methods
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
// written following code in page load.
System.Threading.Thread.Sleep(2000);
PostMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
System.Threading.Thread.Sleep(2000);
Please help me out.
Regards,
Lalit Narayan Dubey
S/W Developer , Noida
|
|
|
|
|
Try this
<br />
using System.Runtime.InteropServices;<br />
[DllImport("user32.dll")]<br />
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);<br />
public int WM_SYSCOMMAND = 0x0112;<br />
public int SC_MONITORPOWER = 0xF170;<br />
private System.Windows.Forms.Button button1;<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
int result = 0;<br />
result = SendMessage(ActiveForm.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);<br />
}<br />
|
|
|
|
|
Hi,
Its really working great.thanks. I tried one thing more to have the desktop alwayas live. from control pannel setting i set turn off monitor in 1 min.
and written the code like this in button click
private void button1_Click(object sender, System.EventArgs e)
{
int result = 0;
//
// get handle to active form
//
result = SendMessage(ActiveForm.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, -1);
//
}
but it dont work, the monitor get power down.
What else need to change in application. please help me out here too.
Regards,
Lalit Narayan Dubey
S/W Developer,Noida
|
|
|
|
|
Hmmm, would you like to disable monitor power off function?
Well, use this code but it's not C# code.
#include <windows.h><br />
<br />
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);<br />
<br />
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
static TCHAR szAppName[] = TEXT("Disabler");<br />
HWND hwnd;<br />
MSG msg;<br />
WNDCLASS wndclass;<br />
<br />
wndclass.style = CS_HREDRAW | CS_VREDRAW;<br />
wndclass.lpfnWndProc = WndProc;<br />
wndclass.cbClsExtra = 0;<br />
wndclass.cbWndExtra = 0;<br />
wndclass.hInstance = hInstance;<br />
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br />
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);<br />
wndclass.lpszMenuName = NULL;<br />
wndclass.lpszClassName = szAppName;<br />
<br />
if (!RegisterClass(&wndclass)) <br />
{<br />
MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR);<br />
return 0;<br />
}<br />
<br />
hwnd = CreateWindow(szAppName, TEXT("Screensaver && Monitor Power Saving are temporary disabled..."),<br />
WS_OVERLAPPEDWINDOW,<br />
150, 150,<br />
500, 250,<br />
NULL, NULL, hInstance, NULL);<br />
<br />
ShowWindow(hwnd, nCmdShow);<br />
UpdateWindow(hwnd);<br />
<br />
while(GetMessage(&msg, NULL, 0, 0)) <br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
<br />
return ((int) msg.wParam);<br />
}<br />
<br />
<br />
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch (message)<br />
{<br />
case WM_SYSCOMMAND:<br />
<br />
switch (wParam) <br />
{ <br />
case SC_SCREENSAVE:<br />
case SC_MONITORPOWER:<br />
<br />
return 0;<br />
}<br />
<br />
break;<br />
<br />
case WM_DESTROY:<br />
<br />
PostQuitMessage(0);<br />
<br />
return 0;<br />
}<br />
<br />
return DefWindowProc(hwnd, message, wParam, lParam);<br />
}<br />
|
|
|
|
|
Works great ... in c++ ... how do i get it to work in vb ?
Stoopid SendMessage declare in vb doesnt work
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
any ideas ?
:: For all the hours you save writing user progs in vb, you spend twice as long implenting one tiny windows API call ...
|
|
|
|
|
Oh, see it can be done in VB
Note the commented line that *doesnt* work ...
(Tested on Win2k sp4)
Private Declare Function SendMessageVal Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Sub WakeMonitor()
'SendMessageVal &HFFFF, &H112, &HF170, -1 ' Doesnt work !&@!
SendMessageVal &HFFFF, &H112, 61808, -1
End Sub
|
|
|
|
|
Oops, that works only for the monitor off command - the monitor on command works momentarily and then monitor switches off again, unless it is immediately followed by a MsgBox() command to open a modal message box - which of course stops our app from doing what it's supposed to.
Once again, vb has proved to be a complete piece of ****
What now ?
|
|
|
|
|
At last
Well, the monitor off command may not work in a vb app, but the following seems to be a workaround - it sticks a SHIFT_DOWN and a SHIFT_UP keypress sequence into the keyboard buffer. Ive only tested it on a machine with a keyboard attached so dont know if it works on keyboardless systems ...
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
keybd_event &H1, &H45, 1, 0
keybd_event &H1, &H45, 1 + 2, 0
|
|
|
|
|
In VB &HF170 is an integer and evaluates to -3728
If you append another "&", vb knows it is a long: &HF170& = 61808
(That's why the first code didn't work.)
Try using the following to turn the monitor On:
SendKeys "{PRTSC}" 'simulate a keypress to wake the computer up
an application will never receive that keypress, so it is completely safe
(see sendkeys documentation)
|
|
|
|
|