+ Reply to Thread
Results 1 to 4 of 4

Thread: turn off display

  1. #1

    turn off display

    I want to turn off display when i press a button , i do not have a great knowledge on system32 , so i though if you could give me an idea to start with , thanks in advance .

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    40
    hello lilian , i`d be happy to help you with that .

    first of all , you need to use that library :
    Code:
    using System.Runtime.InteropServices; // for dll import
    then add these under public class :
    Code:
            //Using the system pre-defined MSDN constants that can be used by the SendMessage() function .
            public int WM_SYSCOMMAND = 0x0112;
            public int SC_MONITORPOWER = 0xF170;
    
            //To call a DLL function from C#, you must provide this declaration .
            [DllImport("user32.dll")]
            private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
    finally when button clicked , add this function :
    Code:
                // this will turn off display
                SendMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);

  3. #3
    Thank you very much , it worked .

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    40
    glad that it helped

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts