Why does this vb.net code fail?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jim

    #1

    Why does this vb.net code fail?

    VB.net code to turn monitor on and off.......

    <CODE>
    Module Module1
    Const HWND_BROADCAST As Integer = &HFFFF
    Const SC_MONITORPOWER As Integer = &HF170
    Const WM_SYSCOMMAND As Short = &H112S

    Sub Main()
    Dim instr As String = Command()
    Select Case Command().ToLow er
    'Make sure it matches - and look at the commandline switch
    Case "off"
    TurnOff()
    Case "on"
    TurnOn()
    Case "test"
    TurnOff()
    'turn off monitor
    System.Threadin g.Thread.Sleep( 10000)
    'wait 10 seconds
    TurnOn()
    'turn on monitor
    Case Else
    MsgBox("Usage, [on]/[off]/[test] ", _
    MsgBoxStyle.Inf ormation, _
    "Need Command Switch")
    End Select
    End Sub

    Private Function SendMessage(ByV al Handle As Int32, _
    ByVal wMsg As Int32, ByVal wParam As Int32, _
    ByVal lParam As Int32) As Int32

    End Function

    Sub StandBy()
    SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 1)
    End Sub

    Sub TurnOff()
    SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 2)
    End Sub

    Sub TurnOn()
    SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , -1)
    End Sub

    End Module
    </CODE>

    According to the author (http://www.codeproject.com/useritems/Monitors.asp)
    the code is supposed to allow you to turn off the monitor but it has no
    effect at all on my XP Pro SP2 fully patched PC with LCD screen.

    Any clues?



  • jim

    #2
    It is a console app.....

    I should have mentioned it is a console app.....sorry.. ...

    "jim" <jim@home.netwr ote in message
    news:IpZri.1030 5$x72.382@bigne ws1.bellsouth.n et...
    VB.net code to turn monitor on and off.......
    >
    <CODE>
    Module Module1
    Const HWND_BROADCAST As Integer = &HFFFF
    Const SC_MONITORPOWER As Integer = &HF170
    Const WM_SYSCOMMAND As Short = &H112S
    >
    Sub Main()
    Dim instr As String = Command()
    Select Case Command().ToLow er
    'Make sure it matches - and look at the commandline switch
    Case "off"
    TurnOff()
    Case "on"
    TurnOn()
    Case "test"
    TurnOff()
    'turn off monitor
    System.Threadin g.Thread.Sleep( 10000)
    'wait 10 seconds
    TurnOn()
    'turn on monitor
    Case Else
    MsgBox("Usage, [on]/[off]/[test] ", _
    MsgBoxStyle.Inf ormation, _
    "Need Command Switch")
    End Select
    End Sub
    >
    Private Function SendMessage(ByV al Handle As Int32, _
    ByVal wMsg As Int32, ByVal wParam As Int32, _
    ByVal lParam As Int32) As Int32
    >
    End Function
    >
    Sub StandBy()
    SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 1)
    End Sub
    >
    Sub TurnOff()
    SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 2)
    End Sub
    >
    Sub TurnOn()
    SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , -1)
    End Sub
    >
    End Module
    </CODE>
    >
    According to the author
    (http://www.codeproject.com/useritems/Monitors.asp) the code is supposed
    to allow you to turn off the monitor but it has no effect at all on my XP
    Pro SP2 fully patched PC with LCD screen.
    >
    Any clues?
    >
    >
    >

    Comment

    • Armin Zingler

      #3
      Re: Why does this vb.net code fail?

      "jim" <jim@home.netsc hrieb
      VB.net code to turn monitor on and off.......
      >
      <CODE>
      Module Module1
      Const HWND_BROADCAST As Integer = &HFFFF
      Const SC_MONITORPOWER As Integer = &HF170
      Const WM_SYSCOMMAND As Short = &H112S
      >
      Sub Main()
      Dim instr As String = Command()
      Select Case Command().ToLow er
      'Make sure it matches - and look at the commandline
      switch Case "off"
      TurnOff()
      Case "on"
      TurnOn()
      Case "test"
      TurnOff()
      'turn off monitor
      System.Threadin g.Thread.Sleep( 10000)
      'wait 10 seconds
      TurnOn()
      'turn on monitor
      Case Else
      MsgBox("Usage, [on]/[off]/[test] ", _
      MsgBoxStyle.Inf ormation, _
      "Need Command Switch")
      End Select
      End Sub
      >
      Private Function SendMessage(ByV al Handle As Int32, _
      ByVal wMsg As Int32, ByVal wParam As Int32, _
      ByVal lParam As Int32) As Int32
      >
      End Function
      >
      Sub StandBy()
      SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
      1) End Sub
      >
      Sub TurnOff()
      SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
      2) End Sub
      >
      Sub TurnOn()
      SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
      -1) End Sub
      >
      End Module
      </CODE>
      >
      According to the author
      (http://www.codeproject.com/useritems/Monitors.asp) the code is
      supposed to allow you to turn off the monitor but it has no effect
      at all on my XP Pro SP2 fully patched PC with LCD screen.
      >
      Any clues?

      Your Funcstion SendMessage does Nothing. It is empty. Get the right
      declaration:




      Armin

      Comment

      • rowe_newsgroups

        #4
        Re: Why does this vb.net code fail?

        On Aug 1, 7:14 am, "Armin Zingler" <az.nos...@free net.dewrote:
        "jim" <j...@home.nets chrieb
        >
        >
        >
        VB.net code to turn monitor on and off.......
        >
        <CODE>
        Module Module1
        Const HWND_BROADCAST As Integer = &HFFFF
        Const SC_MONITORPOWER As Integer = &HF170
        Const WM_SYSCOMMAND As Short = &H112S
        >
        Sub Main()
        Dim instr As String = Command()
        Select Case Command().ToLow er
        'Make sure it matches - and look at the commandline
        switch Case "off"
        TurnOff()
        Case "on"
        TurnOn()
        Case "test"
        TurnOff()
        'turn off monitor
        System.Threadin g.Thread.Sleep( 10000)
        'wait 10 seconds
        TurnOn()
        'turn on monitor
        Case Else
        MsgBox("Usage, [on]/[off]/[test] ", _
        MsgBoxStyle.Inf ormation, _
        "Need Command Switch")
        End Select
        End Sub
        >
        Private Function SendMessage(ByV al Handle As Int32, _
        ByVal wMsg As Int32, ByVal wParam As Int32, _
        ByVal lParam As Int32) As Int32
        >
        End Function
        >
        Sub StandBy()
        SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
        1) End Sub
        >
        Sub TurnOff()
        SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
        2) End Sub
        >
        Sub TurnOn()
        SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
        -1) End Sub
        >
        End Module
        </CODE>
        >
        According to the author
        (http://www.codeproject.com/useritems/Monitors.asp) the code is
        supposed to allow you to turn off the monitor but it has no effect
        at all on my XP Pro SP2 fully patched PC with LCD screen.
        >
        Any clues?
        >
        Your Funcstion SendMessage does Nothing. It is empty. Get the right
        declaration:
        >
        http://www.google.com/search?as_q=Se...unction+intptr...
        >
        Armin
        Or check pinvoke.net for the correct declaration:



        Thanks,

        Seth Rowe

        Comment

        Working...