#include "stdafx.h" #include "EventRevWnd.h" #include static CHAR szClassName[MAX_PATH] = "ScannerEvtRevWnd"; static TCHAR szTitle[MAX_PATH] = "ScannerEvtRevWnd_Title"; HWND gEventRevWnd = NULL; IMediaEventEx *pME = NULL; BOOL fAlreadyCreated = FALSE; BOOL WndDlgInit() { LOG_FUNCTION(); RegisterWndClass(NULL); HWND hWnd; hWnd = CreateWindow(szClassName, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL); if (!hWnd) { return FALSE; } gEventRevWnd = hWnd; fAlreadyCreated = TRUE; MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, NULL, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } fAlreadyCreated = FALSE; gEventRevWnd = NULL; return (BOOL) msg.wParam; } ATOM RegisterWndClass(HINSTANCE hInstance) { WNDCLASSEX wcex = {0}; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.lpszMenuName = NULL; wcex.lpszClassName = szClassName; return RegisterClassEx(&wcex); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: break; case WM_DESTROY: PostQuitMessage(0); break; case WM_CLOSE: break; case WM_ENDSESSION: //Session is being ended or the use is logging. if(wParam || (lParam & ENDSESSION_LOGOFF)) { } break; case WM_TIMER: break; case WM_FGNOTIFY: // uh-oh, something went wrong while capturing - the filtergraph // will send us events like EC_COMPLETE, EC_USERABORT and the one // we care about, EC_ERRORABORT. if(pME) { LONG event; LONG_PTR l1, l2; HRESULT hrAbort = S_OK; BOOL bAbort = FALSE; while(pME->GetEvent(&event, &l1, &l2, 0) == S_OK) { pME->FreeEventParams(event, l1, l2); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetEvent %d, %d, %d", event, l1, l2); if(event == EC_ERRORABORT) { bAbort = TRUE; hrAbort = static_cast(l1); continue; } else if(event == EC_DEVICE_LOST) { // Check if we have lost a capture filter being used. // lParam2 of EC_DEVICE_LOST event == 1 indicates device added // == 0 indicates device removed if(l2 == 0) { IBaseFilter *pf; IUnknown *punk = (IUnknown *) l1; if(S_OK == punk->QueryInterface(IID_IBaseFilter, (void **) &pf)) { //if(::IsEqualObject(gcap.pVCap, pf)) { pf->Release(); bAbort = FALSE; break; } pf->Release(); } } } } // end while if(bAbort) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ERROR during capture, error code=0x%08X", hrAbort); } } break; case WM_DEVICECHANGE: // We are interested in only device arrival & removal events if(DBT_DEVICEARRIVAL != wParam && DBT_DEVICEREMOVECOMPLETE != wParam) break; PDEV_BROADCAST_HDR pdbh = (PDEV_BROADCAST_HDR) lParam; if(pdbh->dbch_devicetype != DBT_DEVTYP_DEVICEINTERFACE) { break; } PDEV_BROADCAST_DEVICEINTERFACE pdbi = (PDEV_BROADCAST_DEVICEINTERFACE) lParam; // Check for capture devices. if(pdbi->dbcc_classguid != AM_KSCATEGORY_CAPTURE) { break; } // Check for device arrival/removal. if(DBT_DEVICEARRIVAL == wParam || DBT_DEVICEREMOVECOMPLETE == wParam) { } break; } return (LONG) DefWindowProc(hWnd, message, wParam, lParam); } UINT WINAPI EventRevThread(PVOID Param) { if(!fAlreadyCreated) { WndDlgInit(); } return (UINT)NULL; }