none
Turn off monitor Hex codes RRS feed

  • Question

  • Hi,
     
    I use the following code to turn off my monitor

    Option Explicit
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

    Const SC_MONITORPOWER = &HF170&
    Const MONITOR_ON = -1&
    Const MONITOR_OFF = 2&
    Const WM_SYSCOMMAND = &H112


    Private Sub Form_Load()
        SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
    End Sub

    Can somebody tell me what does &HF170& and other HEX values mean?  Where do I get the dictionary that -1& stands for Monitor on?? Any idea?

    Thanks
    rajgoaj@gmail.com
    • Edited by Rajgoaj Monday, November 3, 2008 12:28 PM
    Monday, November 3, 2008 12:27 PM

Answers

  • hi, those hexadecimal value are used by microsoft windows os to communicate or as signal. It is defined by microsoft.  It has no meanning its just a number used to relay information.

    Here, you sent messaage to windows os to turn off or turn on the monitor. There are lots of such number and message you can send.

    You can search in microsoft msdn library to find what number does microsoft using for what message.

    Love to program in C#.
    • Proposed as answer by Yam Sapkota Friday, November 7, 2008 4:03 PM
    • Marked as answer by Martin Xie - MSFT Monday, November 10, 2008 3:20 AM
    Monday, November 3, 2008 1:45 PM
  • They are constant values meaning some action like

    Function TakeAction(action as integer)
         If action=1 then
            'code to shutdown
        Elseif action = 2 then
            'code to restart
      ElseIf action = 3 then
            'code to logoff
    end if

    end function

    so when you want to call that function to shutdown then you call like
    TakeAction(1)  

    but now a days they are object oriented and values like enum are used to represent action for eg

       Sub TakeAction(ByVal Action As ActionType)
            If Action = ActionType.ShutDown Then
                'code to shutdown
            ElseIf Action = ActionType.Restart Then
                'code to restart
            ElseIf Action = ActionType.LogOff Then
                'code to logoff
            End If

        End Sub

        Public Enum ActionType
            ShutDown = 1
            Restart = 2
            LogOff = 3
        End Enum

    Now to shut down you can call  TakeAction(ActionType.ShutDown)

    I am just showing you an example but there are some other aspects we can consider while developing such kind of method

      SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
    In this example your are sending message to window to perform a action and all those constants you have sent are evaluated and necessary actions are taken

    And as Yam says, you can look for these values in MSDN Forums for specific action, just use the appropriate keywords while looking for them.

    Thanks






    Arjun Paudel
    • Proposed as answer by Yam Sapkota Friday, November 7, 2008 4:03 PM
    • Marked as answer by Martin Xie - MSFT Monday, November 10, 2008 3:20 AM
    Monday, November 3, 2008 3:06 PM

All replies

  • hi, those hexadecimal value are used by microsoft windows os to communicate or as signal. It is defined by microsoft.  It has no meanning its just a number used to relay information.

    Here, you sent messaage to windows os to turn off or turn on the monitor. There are lots of such number and message you can send.

    You can search in microsoft msdn library to find what number does microsoft using for what message.

    Love to program in C#.
    • Proposed as answer by Yam Sapkota Friday, November 7, 2008 4:03 PM
    • Marked as answer by Martin Xie - MSFT Monday, November 10, 2008 3:20 AM
    Monday, November 3, 2008 1:45 PM
  • They are constant values meaning some action like

    Function TakeAction(action as integer)
         If action=1 then
            'code to shutdown
        Elseif action = 2 then
            'code to restart
      ElseIf action = 3 then
            'code to logoff
    end if

    end function

    so when you want to call that function to shutdown then you call like
    TakeAction(1)  

    but now a days they are object oriented and values like enum are used to represent action for eg

       Sub TakeAction(ByVal Action As ActionType)
            If Action = ActionType.ShutDown Then
                'code to shutdown
            ElseIf Action = ActionType.Restart Then
                'code to restart
            ElseIf Action = ActionType.LogOff Then
                'code to logoff
            End If

        End Sub

        Public Enum ActionType
            ShutDown = 1
            Restart = 2
            LogOff = 3
        End Enum

    Now to shut down you can call  TakeAction(ActionType.ShutDown)

    I am just showing you an example but there are some other aspects we can consider while developing such kind of method

      SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
    In this example your are sending message to window to perform a action and all those constants you have sent are evaluated and necessary actions are taken

    And as Yam says, you can look for these values in MSDN Forums for specific action, just use the appropriate keywords while looking for them.

    Thanks






    Arjun Paudel
    • Proposed as answer by Yam Sapkota Friday, November 7, 2008 4:03 PM
    • Marked as answer by Martin Xie - MSFT Monday, November 10, 2008 3:20 AM
    Monday, November 3, 2008 3:06 PM
  • These values are defined in the WinUser.h header file of the Windows SDK.  
    Hans Passant.
    Tuesday, November 4, 2008 5:21 AM
    Moderator