Switch off monitor from inside MP (Plugin) (1 Viewer)

TheThunder

MP Donator
  • Premium Supporter
  • May 15, 2007
    45
    3
    Home Country
    Germany Germany
    Hi,
    when i'm lying in bed to listen to music i want to shutdown my monitor with my remote. So i started to write a small plugin with the same code i have already used in other programs where it works nice.
    But in my plugin the code does not work, indeed nothing happens when the function to shutdown the Monitor is called.

    Code:
    [DllImport("c:/Windows/System32/user32.dll")]
    public static extern int SendMessage(int hWnd, uint Msg, long wParam, long lParam);
    
    private const int WM_SYSCOMMAND = 0x0112;
    private const int SC_MONITORPOWER = 0xF170;
    private const int HWND_BROADCAST = 0xFFFF;
    
    private void disable_monitor()
    {
         SendMessage((int)HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
    }

    Anyone an idea why it isn't working from inside MP?
     

    Micropolis

    Portal Pro
    July 22, 2009
    1,588
    1,796
    Bavaria
    Home Country
    Germany Germany
    Hi TheThunder,
    after some tests for one of my plugins (see ScreenControl which give you the described functionality) it was required to wait for a short time. So please insert "Thread.Sleep(1000)" before you use SendMessage and it must be ok. Another hint: It is not a good idea to hard code the path to user32.dll. It works also with [DllImport("user32.dll")] without any problems.

    Cheers, Micropolis ;-)
     

    TheThunder

    MP Donator
  • Premium Supporter
  • May 15, 2007
    45
    3
    Home Country
    Germany Germany
    AW: Switch off monitor from inside MP (Plugin)

    Hi!
    Thanks for the solution and ScreenControl thats exactly what i have planned to do!
    Great job!
     

    AntonyGone

    New Member
    February 28, 2012
    2
    0
    38
    Home Country
    Russian Federation Russian Federation
    TheThunder
    Hi! Did you write that plugin completely?
    I'm using ScreenControl now, but all i need, is a turn monitor off function, that all.

    I would be thankful if you can give me that plugin :) , unfortunately i dont know how to write plugins, and dont have time to learn(
     

    Users who are viewing this thread

    Top Bottom