大家好我需要一个C ++代码来获取用户将某些便携式设备连接到系统时的便携式设备通知。获取大容量存储设备通知的代码部分如下,请仔细阅读并建议我如何为便携式设备进行操作。
LRESULT CALLBACK DLLWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HDEVNOTIFY hDeviceNotify;
__int32 devType;
char c;
char buf[5]={0};
PawCallBack *callbackHandle;
char Buffer[10];
switch (message)
{
case WM_CREATE:
RegisterHotKey(hwnd, 1, MOD_ALT , VK_SNAPSHOT);
RegisterHotKey(hwnd, 2, 0 , VK_SNAPSHOT);
if ( ! DoRegisterDeviceInterfaceToHwnd(WceusbshGUID, hwnd, &hDeviceNotify) )
{
// Terminate on failure.
ExitProcess(1);
}
break;
case WM_HOTKEY:
LPSTR temppath;
CaptureScreen(GetDesktopWindow());
UnicodeToAnsi(temp_filename, &temppath);
callbackHandle = new PawCallBack;
strcpy(callbackHandle->ImageSavePath,temppath);
callbackHandle->servicecode = 111;
if(!myPipe.SendMsg(_T("PAWAGENT"), callbackHandle, sizeof(PawCallBack), Buffer, 10,0))
{
//MessageBoxA(NULL,"Cannot Send to pipe","Drive Info",MB_OK);
}
delete callbackHandle;
break;
case WM_DEVICECHANGE:
{
PDEV_BROADCAST_HDR pHdr;
PDEV_BROADCAST_VOLUME vol;
// Output some messages to the window.
switch (wParam)
{
case DBT_DEVICEARRIVAL:
//MessageBoxA(NULL,"Device Arrived", "Info", MB_OK);
pHdr = (PDEV_BROADCAST_HDR)lParam;
if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
vol = (PDEV_BROADCAST_VOLUME)pHdr;
c = DriveMaskToLetter(vol->dbcv_unitmask);
memset(buf,0,5);
sprintf(buf,"%c:", c);
//MessageBoxA(NULL,&c, "Device Arrived", MB_OK);
callbackHandle = new PawCallBack;
strcpy(callbackHandle->DriveName, buf);
callbackHandle->servicecode = 109;
if(!myPipe.SendMsg(_T("PAWAGENT"), callbackHandle, sizeof(PawCallBack), Buffer, 10, 0))
{
//MessageBoxA(NULL,"Cannot Send to pipe","Drive Info",MB_OK);
}
delete callbackHandle;
}
break;
case DBT_DEVICEREMOVECOMPLETE:
pHdr = (PDEV_BROADCAST_HDR)lParam;
if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
vol = (PDEV_BROADCAST_VOLUME)pHdr;
c = DriveMaskToLetter(vol->dbcv_unitmask);
memset(buf,0,5);
sprintf(buf,"%c:",c);
callbackHandle = new PawCallBack;
strcpy(callbackHandle->DriveName,buf);
callbackHandle->servicecode = 110;
if(!myPipe.SendMsg(_T("PAWAGENT"), callbackHandle, sizeof(PawCallBack), Buffer, 10, 0))
{
//MessageBoxA(NULL,"Cannot Send to pipe","Drive Info",MB_OK);
}
delete callbackHandle;
}
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_CLOSE:
if ( ! UnregisterDeviceNotification(hDeviceNotify) )
{
MessageBoxA(NULL, "UnregisterDeviceNotification Failed", "Info",MB_OK);
}
UnregisterHotKey(hwnd, 1);
UnregisterHotKey(hwnd, 2);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
}
上面的代码适用于大容量存储设备,但现在我想为便携式设备扩展它,所以请仔细阅读我的代码,并建议我为便携式设备做些什么。提前谢谢..
答案 0 :(得分:0)