We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,272 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Turn Off Your Monitor

4
By sandeepparekh9 on Jun 6th, 2011 5:26 pm

Turn you Monitor off from your application.

public partial class Form1 : Form
    {
        public int WM_SYSCOMMAND = 0x0112;
        public int SC_MONITORPOWER = 0xF170; 
        [DllImport("user32.dll")]
        private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendMessage( this.Handle.ToInt32() , WM_SYSCOMMAND , SC_MONITORPOWER ,2 );//DLL function
        }
    }

nice!!

jfarrugia
Junior Poster
113 posts since May 2011
Reputation Points: 17
Solved Threads: 17
Skill Endorsements: 0

Thats cool.

Joshua Kidd
Junior Poster
108 posts since Feb 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

it does not work
please help.

Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?) E:\Windows Application\TEST APPLICATION\TurnOffMonitor\TurnOffMonitor\Form1.cs 19 10 TurnOffMonitor

samee1985
Newbie Poster
7 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

use namespace

using System.Runtime.InteropServices;
bhagawatshinde
Posting Whiz
338 posts since Sep 2010
Reputation Points: 21
Solved Threads: 22
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0679 seconds using 2.67MB