Zig*_*gma 3 c# windows-messages
我正在尝试检测usb到达事件.我试图覆盖wndproc()以获取我的消息.但我正面临着Windows消息的错误.
错误是:
The name 'WM_DEVICECHANGE' does not exist in the current context
The name 'DBT_DEVICEARRIVAL' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
这也是我尝试过的代码.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32.SafeHandles;
namespace USBCheckerApp
{
public partial class Form1 : Form
{
bool bDeviceFound = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (!bDeviceFound)
{
button1.Enabled = false;
}
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_DEVICECHANGE:
if (m.WParam == DBT_DEVICEARRIVAL)
{
MessageBox.Show("MEDIA FOUND");
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
添加,以便您可以建议相同的更新.谢谢
您必须声明并定义常量的值:
private const int DBT_DEVICEARRIVAL = 0x8000;
private const int WM_DEVICECHANGE = 0x0219;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2561 次 |
| 最近记录: |