handler problem in custom class

ExEdzy

Active member
Joined
Nov 25, 2010
Messages
37
Programming Experience
3-5
hi all

I have a little problem with me.handler, well there is no handler in custom class..

so i'm making custom class, where one of functions is to switch off screen.. the code is:

VB.NET:
Public Class Display
        Public WM_SYSCOMMAND As Integer = &H112
        Public SC_MONITORPOWER As Integer = &HF170

        <DllImport("user32.dll")> Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal hMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function

        Public Sub TurnOff()
            SendMessage(handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2)
        End Sub

        Public Sub TurnOn()
            Dim num As Integer = 0
            SendMessage(handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1)
        End Sub

    End Class

so, how can i make this work in custom class, that dosnt have Me

I hope i managed to clear out my problem..

P.S. this code works perfectly in Form..
 
You can pass a valid handle to the class. You could also for example use GetForegroundWindow handle.
 
Back
Top