资源简介
c++监控USB插拔状态源码,在控制台上实现的,比较简单
代码片段和文件信息
#include
#include
#include
#include
LRESULT CALLBACK WndProc(HWND h UINT msg WPARAM wp LPARAM lp)
{
if (msg == WM_DEVICECHANGE) {
if ((DWORD)wp == DBT_DEVICEARRIVAL) {
DEV_BROADCAST_VOLUME* p = (DEV_BROADCAST_VOLUME*)lp;
if (p->dbcv_devicetype == DBT_DEVTYP_VOLUME) {
int l = (int)(log(double(p->dbcv_unitmask)) / log(double(2)));
printf(“啊……%c盘插进来了\n“ ‘A‘ + l);
}
}
else if ((DWORD)wp == DBT_DEVICEREMOVECOMPLETE) {
DEV_BROADCAST_VOLUME* p = (DEV_BROADCAST_VOLUME*)lp;
if (p->dbcv_devicetype == DBT_DEVTYP_VOLUME) {
int l = (int)(log(double(p->dbcv_unitmask)) / log(double(2)));
printf(“啊……%c盘被拔掉了\n“ ‘A‘ + l);
}
}
return TRUE;
}
else return DefWindowProc(h msg wp lp);
}
int main() {
WNDCLASS wc;
ZeroMemory(&wc sizeof(wc));
wc.lpszClassName = TEXT(“myusbmsg“);
wc.lpfnWndProc = WndProc;
RegisterClass(&wc);
HWND h = CreateWindow(TEXT(“myusbmsg“) TEXT(““) 0 0 0 0 0
0 0 GetModuleHandle(0) 0);
MSG msg;
while (GetMessage(&msg 0 0 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1172 2018-01-19 17:38 test.cpp
----------- --------- ---------- ----- ----
1172 1
- 上一篇:大富翁源代码
- 下一篇:多功能计算器实现C++代码以及代码详解
评论
共有 条评论