怎么样判断有手机通过USB连接到电脑?
怎么样判断有手机通过USB连接到电脑? 怎么样捕获这一事件的? 谢谢。
[解决办法]
给连接注册一个消息
查下这些东西
SHChangeNotifyEntry
SHGetSpecialFolderLocation CSIDL_CONNECTIONS
SHChangeNotifyRegister SHCNE_CREATE | SHCNE_DELETE
[解决办法]
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\AutoStartOnConnect
里面写你想启动的程序路径,当连接时,你指定的程序会自动启动。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\AutoStartOnDisconnect
下指定的程序就是断开连接时运行的程序了~~~
[解决办法]
PC端可以用CeRapiInitEx来判断是否已经连接。可以开启一个线程去监听。
HRESULT TryRapiConnect(DWORD dwTimeOut){ HRESULT hr = E_FAIL; RAPIINIT riCopy; bool fInitialized = false; ZeroMemory(&riCopy, sizeof(riCopy)); riCopy.cbSize = sizeof(riCopy); hr = CeRapiInitEx(&riCopy); if (SUCCEEDED(hr)) { DWORD dwRapiInit = 0; fInitialized = true; dwRapiInit = WaitForSingleObject( riCopy.heRapiInit, dwTimeOut); if (WAIT_OBJECT_0 == dwRapiInit) { // heRapiInit signaled: // set return error code to return value of RAPI Init function hr = riCopy.hrRapiInit; } else if (WAIT_TIMEOUT == dwRapiInit) { // timed out: device is probably not connected // or not responding hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT); } else { // WaitForSingleObject failed hr = HRESULT_FROM_WIN32(GetLastError()); } } if (fInitialized && FAILED(hr)) { CeRapiUninit(); } return hr;}