#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);
}
}
阅读(4298) | 评论(0) | 转发(0) |