Results 1 to 3 of 3

Thread: [RESOLVED] Controlling monitor power. [ Turn on / Off ]

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Resolved [RESOLVED] Controlling monitor power. [ Turn on / Off ]

    OK,

    i wanna be able to switch off my screen via code (using v/c)

    looked through my old code and found this.... - it doesnt work though, comes out with Error 6: overflow, pointing to sendmessage....

    now ive got a fresh xp install so maybe its something i havent set up correctly, so does this need something setting to be able to use it?

    vb Code:
    1. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
    2.  
    3. Const SC_MONITORPOWER = &HF170&
    4. Const MONITOR_ON = -1&
    5. Const MONITOR_OFF = 2&
    6. Const WM_SYSCOMMAND = &H112
    7.  
    8. Private Sub ControlScreenPower(bTurnOn As Boolean)
    9.  
    10.     Select Case bTurnOn
    11.         Case True:
    12.             'Turn Monitor on:
    13.             SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
    14.         Case False:
    15.             'Turn Monitor off:
    16.             SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
    17.     End Select
    18.  
    19. End Sub
    20.  
    21. 'me.hwnd = 2294342
    22. ' WM_SYSCOMMAND= 274
    23. ' sc_monitorpower = 61808
    24. ' monitor on = -1
    25. ' and off = 2

    i havent actually tried it on another machine yet, but if you guys say its right ill make an install n check it on the other machine
    Wayne

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Controlling monitor power. [ Turn on / Off ]

    Try this modification to your API declaration.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Any, ByVal lParam As Long) As Long
    You have declared it as integer yet you are passing a long variable.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: Controlling monitor power. [ Turn on / Off ]

    cheers.

    i forgot i posted this till i jst come for a nosy, i actually changed it to Long and it solved it... - but as you suggested the ANY works too
    Wayne

Posting Permissions

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



Click Here to Expand Forum to Full Width