none
Turn off monitor RRS feed

  • Question

  • I turn off the monitor with the code segment:

    [DllImport("user32.dll")]
            public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
            const int SC_MONITORPOWER = 0xF170;
            const int WM_SYSCOMMAND = 0x0112;
            const int MONITOR_ON = -1;
            const int MONITOR_OFF = 2;
            const int MONITOR_STANBY = 1;

              private void MonitorOff(object sender, RoutedEventArgs e)
            {
                SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
                onFlag = 1;
            }

    I met an issue: after the monitor was turn off, after 1-10 minutes, the monitor was turn on automatically. how can I turn off the monitor and do not let the monitor turn on untill it receives a message to turn on the monitor? Thanks in advanced.

    Friday, March 12, 2010 8:13 PM

Answers

  • Hi wjanry,

    You can try the code below:
        class Monitor
        {
            [DllImport("user32.dll")]
            public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
            public static void TurnOn()
            {
                SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
            }
    
            public static void TurnOff()
            {
                SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
            }
    
            static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
            const uint WM_SYSCOMMAND = 0x0112;
            const int SC_MONITORPOWER = 0xf170;
        }
    If the monitor is turned on a while later, we can create a Timer and send the turn off message frequently.

    Let me know if this does not help.
    Aland LI
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Wednesday, March 17, 2010 8:57 AM
    Moderator

All replies

  • If the amount of time after which it comes back on constant or not? If it is, is it the amount of time windows is programmed to turn the monitor off after the last activity?
    HTH Ciaran http://wannabedeveloper.spaces.live.com
    Monday, March 15, 2010 1:42 PM
  • The amount of time after which it comes back on  is not constant.

    The other interesting thing is the monitor can be turn off by Wizmo (http://www.grc.com/wizmo/wizmo.htm) and the the monitor can not be back any more. But there is not any code about wizmo(it is not open source).
    Monday, March 15, 2010 2:16 PM
  • Hi wjanry,

    You can try the code below:
        class Monitor
        {
            [DllImport("user32.dll")]
            public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
            public static void TurnOn()
            {
                SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
            }
    
            public static void TurnOff()
            {
                SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
            }
    
            static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
            const uint WM_SYSCOMMAND = 0x0112;
            const int SC_MONITORPOWER = 0xf170;
        }
    If the monitor is turned on a while later, we can create a Timer and send the turn off message frequently.

    Let me know if this does not help.
    Aland LI
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Wednesday, March 17, 2010 8:57 AM
    Moderator