Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在.Net控制台应用程序中拦截WndProc事件_.net_Console Application_Wndproc - Fatal编程技术网

如何在.Net控制台应用程序中拦截WndProc事件

如何在.Net控制台应用程序中拦截WndProc事件,.net,console-application,wndproc,.net,Console Application,Wndproc,我有一个单页Winforms应用程序的示例代码 我想在控制台应用程序中重复使用它 示例代码: Protected Overrides Sub WndProc(ByRef msg As Message) If (msg.Msg = SGFPMMessages.DEV_AUTOONEVENT) Then If (msg.WParam.ToInt32() = SGFPMAutoOnEvent.FINGER_ON) Then Sta

我有一个单页Winforms应用程序的示例代码

我想在控制台应用程序中重复使用它

示例代码:

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
我的尝试:

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

好吧,这还不接近。首先需要调用Application.Run()才能使其正常工作。您确实需要一个表单,以便可以重写它的WndProc()方法。当你不得不这么做的时候,不能再确切地称它为控制台应用程序了。示例代码。@HansPassant谢谢!另外,假设我们选择不使用WndProc,我们只是希望检测(USB)设备何时插入或移除。并以类似的方式处理事件。这可能吗?那正是链接帖子的作用。它需要WndProc。真正地