当我的表单应用程序收到WM_DEVICECHANGE消息并且wParam设置为DBT_DEVNODES_CHANGED且lParam设置为零时,如何获取有关设备的更多信息。 [英] How can I get more information about the device when my Form Application receives the WM_DEVICECHANGE message with wParam set to DBT_DEVNODES_CHANGED and lParam set to zero.

查看:279
本文介绍了当我的表单应用程序收到WM_DEVICECHANGE消息并且wParam设置为DBT_DEVNODES_CHANGED且lParam设置为零时,如何获取有关设备的更多信息。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的表单应用程序收到WM_DEVICECHANGE消息并且wParam设置为DBT_DEVNODES_CHANGED且lParam设置为零时,如何获取有关设备的更多信息?我只知道MSDN说需要更多信息的应用程序应该使用RegisterDeviceNotification函数注册设备通知。如何通过使用registerDeviceNotification或其他方式解决这个问题。你能给我一些代码或提示。谢谢你。





以下是一些代码。





protected override void WndProc(ref message m)

{

base.WndProc(ref m);

if(m.Msg == WM_DEVICECHANGE )

{

if(m.WParam.ToInt32()== DBT_DEVNODECHANGE)

{

if( test!= null&& test.IsAlive)

{

return;

}



Thread.Sleep(1000);

System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;

test = new Thread(new ThreadStart(this .startTest));

test.Start();

adbBtn.Enabled = false;

UartDebugBtn.Enabled = false;

SN.Text ="" ;;

}

}

}

How can I get more information about the device when my Form Application receives the WM_DEVICECHANGE message with wParam set to DBT_DEVNODES_CHANGED and lParam set to zero? I just know MSDN says Applications that require more information should register for device notification using the RegisterDeviceNotification function.How can I work out this problem by using registerDeviceNotification or some other way.Can you give me some codes or tips.Thanks advancely.


Here are some code.


protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_DEVICECHANGE)
{
if (m.WParam.ToInt32() == DBT_DEVNODECHANGE)
{
if (test != null && test.IsAlive)
{
return;
}

Thread.Sleep(1000);
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
test = new Thread(new ThreadStart(this.startTest));
test.Start();
adbBtn.Enabled = false;
UartDebugBtn.Enabled = false;
SN.Text = "";
}
}
}

推荐答案

正如文档明确指出的那样,您需要实现 https:/ /msdn.microsoft.com/en-us/library/windows/desktop/aa363431(v=vs.85).aspx [ ^ ]。
As the documentation clearly states, you need to implement https://msdn.microsoft.com/en-us/library/windows/desktop/aa363431(v=vs.85).aspx[^].


这篇关于当我的表单应用程序收到WM_DEVICECHANGE消息并且wParam设置为DBT_DEVNODES_CHANGED且lParam设置为零时,如何获取有关设备的更多信息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆