1

I have this sample code for a single-page Winforms Application

I would like to re-use this in a console Application

Sample code:

Protected Overrides Sub WndProc(ByRef msg As Message)
        If (msg.Msg = SGFPMMessages.DEV_AUTOONEVENT) Then
            If (msg.WParam.ToInt32() = SGFPMAutoOnEvent.FINGER_ON) Then
                StatusBar.Text = "Device Message: Finger On"
            ElseIf (msg.WParam.ToInt32() = SGFPMAutoOnEvent.FINGER_OFF) Then
                StatusBar.Text = "Device Message: Finger Off"
            End If
        End If

        MyBase.WndProc(msg)
End Sub

My Attempt:

Imports System.Windows.Forms

Sub WndProc(ByRef msg As Message)
        If (msg.Msg = SGFPMMessages.DEV_AUTOONEVENT) Then
            If (msg.WParam.ToInt32() = SGFPMAutoOnEvent.FINGER_ON) Then
                Console.Title = "Device Message: Finger On"
            ElseIf (msg.WParam.ToInt32() = SGFPMAutoOnEvent.FINGER_OFF) Then
                Console.Title = "Device Message: Finger Off"
            End If
        End If

        //MyBase.WndProc(msg)
End Sub
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157
  • Well, that is not close. Calling Application.Run() is required to make this work in the first place. And you really do need a Form so you can override its WndProc() method. Can't exactly call it a console application anymore when you have to do that. Sample code [is here](http://stackoverflow.com/a/2061741/17034). – Hans Passant Apr 07 '16 at 17:30
  • @HansPassant Thanks! Also, lets say we choose not to use WndProc, we simply wish to detect when the (USB) device is plugged in or is removed. and handle the event in a similar fashion. Would that be possible? – Charles Okwuagwu Apr 07 '16 at 17:37
  • That's exactly what that linked post does. It requires WndProc. Really. – Hans Passant Apr 07 '16 at 17:38

0 Answers0