1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include <windows.h>
#include <dshow.h>
LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wndClass;
ATOM classAtom;
HWND m_hWnd;
// Register class
ZeroMemory(&wndClass,sizeof(wndClass));
wndClass.cbSize = sizeof(wndClass);
wndClass.style = 0;
wndClass.lpfnWndProc = WindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = NULL;
wndClass.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW));
wndClass.hbrBackground = NULL;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "test";
wndClass.hIconSm = NULL;
classAtom = RegisterClassEx(&wndClass);
if (!classAtom) {
return 0;
}
// Create window
m_hWnd = CreateWindowEx(0, "test", "test", WS_VISIBLE/*|WS_POPUP|WS_SYSMENU*/, 0, 0, 700, 700, NULL, NULL, hInstance, NULL);
/****************************************************************************************/
IVideoWindow* m_pVW ;
IMediaControl* m_pMC ;
IGraphBuilder* m_pGraph ;
ICaptureGraphBuilder2* m_pCapture ;
IBaseFilter * m_pSourceFilter;
CoInitialize(NULL);
HRESULT hr;
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void **)&m_pGraph);
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,NULL,CLSCTX_INPROC_SERVER,IID_ICaptureGraphBuilder2,(void **)&m_pCapture);
// Obtain interfaces for media control and Video Window
hr = m_pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &m_pMC);
hr = m_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &m_pVW);
m_pCapture->SetFiltergraph(m_pGraph);
ICreateDevEnum *pEnumerator;
hr = CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC_SERVER,IID_ICreateDevEnum,(void **)&pEnumerator);
IEnumMoniker *pDeviceEnum;
pEnumerator->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pDeviceEnum,0);
IMoniker *pMoniker;
ULONG cFetched;
while (pDeviceEnum->Next(1,&pMoniker,&cFetched) == S_OK) {
IPropertyBag *pBag;
hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void **)&pBag);
if (SUCCEEDED(hr)) {
pMoniker->BindToObject(NULL,NULL,IID_IBaseFilter,(void **)&m_pSourceFilter);
}
}
hr = m_pGraph->AddFilter(m_pSourceFilter,L"ConvertX");
hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,m_pSourceFilter,NULL,NULL);
hr = m_pVW->put_Owner((OAHWND)m_hWnd);
hr = m_pVW->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
hr = m_pVW->put_Width(640) ;
hr = m_pVW->put_Height(480) ;
hr = m_pVW->put_Visible(OATRUE);
hr = m_pVW->put_MessageDrain((OAHWND)m_hWnd);
hr = m_pMC->Run();
/****************************************************************************************/
MSG msg;
BOOL bRet;
while ((bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) {
if (bRet != -1) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) {
switch(msg)
{
case WM_CREATE :
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
case WM_HOTKEY :
break;
case WM_PAINT :
break;
case WM_TIMER :
break;
case WM_COMMAND :
break;
case WM_LBUTTONDOWN :
break;
case WM_LBUTTONUP :
break;
case WM_LBUTTONDBLCLK :
break;
case WM_RBUTTONDOWN :
break;
case WM_MOUSEMOVE :
break;
case WM_KEYDOWN :
switch(wp) {
case VK_ESCAPE :
// quitter
DestroyWindow(hwnd);
break;
}
break;
case WM_QUIT :
break;
}
return DefWindowProc(hwnd,msg,wp,lp);
} |
Partager