こんにちは、ユーザーがポータブル デバイスを system に接続したときにポータブル デバイス通知を取得するには、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;
}
}
上記のコードは大容量記憶装置には最適ですが、これをポータブル デバイスに拡張したいので、私のコードを調べて、ポータブル デバイスで何をすべきかを提案してください。前もって感謝します ..