检测U盘插入、拨出状态

头文件

#include

 

关键代码:

 1 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 2  3 
 4       switch (message)
 5        {
 6          case WM_DEVICECHANGE:   
 7             if (DBT_DEVICEARRIVAL==wParam )  
 8                 MessageBox(NULL,TEXT("U盘插入"),TEXT(""),MB_ICONWARNING);  
 9             else if (DBT_DEVICEREMOVEPENDING==wParam || DBT_DEVICEREMOVECOMPLETE ==wParam)   
10                 MessageBox(NULL,TEXT("U盘拔出"),TEXT(""),MB_ICONWARNING);  
11             break;
12          case WM_DESTROY:
13                 PostQuitMessage(0);
14                 break;
15             default:return DefWindowProc(hWnd, message, wParam, lParam);
16 17 }

在窗口消息处理函数中,响应WM_DEVICECHANGE消息。

转载于:https://www.cnblogs.com/Open-Source/p/6329525.html

你可能感兴趣的:(检测U盘插入、拨出状态)