Enable the monitor to enter the power-saving mode

Source: Internet
Author: User

Sometimes I watch The Notebook before the TV, and I will only be able to touch the TV. It takes too long to automatically close the screen, I don't want to shut down the power source because I want to trigger the mouse, so I went to Google to find the related program. I wanted to use vbs, but vbs couldn't call win api, I had to switch to C #. This is my generation. on my computer, I can make sure that I can enter the power-saving mode.

class Program

{

    const int MONITOR_ON = -1;

    const int MONITOR_OFF = 2;

    const int WM_SYSCOMMAND = 0x0112;

    const int SC_MONITORPOWER = 0xF170;

 

    [DllImport("user32.dll")]

    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 

    [DllImport("user32.dll")]

    static extern bool SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);

 

    static void Main(string[] args)

    {

Intptr hwnd = findwindow (null, null); // find the root window Handler

Sendmessage (hwnd, wm_syscommand, SC _monitorpower, monitor_off); // sends the closing alert message

    }

}

Attaches the EXE extension, if you want to use it.

Lower limit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.