Application/C#

C# :: 모니터 전원 제어

나비:D 2008. 4. 1. 16:34

출처 : http://blog.naver.com/oioois?Redirect=Log&logNo=150028275081

회사 업무중에 S/W적으로 LCD모니터의 전원을 제어할 경우가 생겨..

가장 심플한 방법을 찾아 C#으로 구현해 보았다.

-.Net 제공 관련 클래스를 찾지 못해 Win32 function 호출하는 방법 채택

-일정 시간 후, 모니터 전원 ON을 위해 Timer 컨트롤 사용

using System.Runtime.InteropServices;

namespace monitorPowerCtlSample
{
    public partial class MonitorPower : Form
    {

        const int WM_SYSCOMMAND = 0x0112;
        const int SC_MONITORPOWER = 0xF170;

        const int MONITOR_ON = -1;
        const int MONITOR_OFF = 2;
        const int MONITOR_STANBY = 1;

        [DllImport("user32.dll")]
        private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);  

        //Off버튼을 누르면 LCD모니터 전원을 OFF시킴

        private void btnOff_Click(object sender, EventArgs e)
        {
            SendMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
        }

        //Timer객체의 interval 시간을 적당히 10초정도 추가 테스트

        //10초정도 후에 LCD모니터 전원 ON됨

        private void timer1_Tick(object sender, EventArgs e)
        {
            SendMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);
        }

    }

}

테스트 중에 발생한 오류(?)가 있었다.

전원 ON/OFF를 연속적으로 실행하자 LCD모니터가 절전모드로 들어가 버리는 경우가 있었다.

이에 깊은 지식을 갖지 못한 관계로 아직 해답을 찾지는 못했다.