Вот со старого васма сохранился сорц. Автор некто t1park . Вроде не выкладывали этот сорц? Дальше текст автора, копипаст оригинальной темы. Давно хотелось иметь простой и быстрый инструмент для работы с вебкамерой на масме, но ничего подобного к сожалению небыло создано. Вот решил исправить проблему. Вот описание функций моей библиотеки: Код (ASM): InitLib proto ;Инициализирует библиотеку, вызывается в начале работы с библиотекой UninitLib proto ;Вызывается в завершении работы CreateVideoWindow proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD ;Создаёт окно ;Параметры: ;[in]номер привязанной камеры (1,2,...) ;[in]заголовок ;[in]WS_ ;[in]X верхнего левого угла ;[in]Y тогоже ;[in]ширина ;[in]высота ;[in]идентификатор окна владельца ;[in]Instance ;Возвращает идентификатор, если камера не найдена окно не создаётся и eax=0 StartVideo proto :DWORD ;Вывод видео. ;Параметр: ;[in]идентификатор окна ;Возвращает: 1- если успешно выполнена, 0- камера потеряна или занята. StopVideo proto :DWORD ;Останавливает вывод. ;Параметр: ;[in]идентификатор окна dWebCam proto :DWORD ;Диалог управления камерой. ;Параметр: ;[in]идентификатор окна GetWebCamName proto :DWORD ;Перечисляет имена камер. ;Параметр: ;[out]буфер ,1024 байт ;Возвращает номер камеры. ;Вызывается в цикле, пока eax!=0 PhotoSave proto :DWORD, :DWORD ;Сохраняет фотографию(bmp). ;Параметры: ;[in]идентификатор окна ;[in]указатель на имя. Если имя не содержит путь, то используется путь программы. ;Если ошибка, eax=0 GetBuffer proto :DWORD, :DWORD ;Возвращает указатель на буфер с кадром. ;Параметры: ;[in]идентификатор окна ;[out]указатель на структуру BITMAPINFOHEADER ;Если ошибка, eax=0 GetVWInfo proto :DWORD ;Возвращает указатель на структуру содержащую информацию об окне. ;Параметр: ;[in]идентификатор окна ;Структура: ;(dd)состояние 1-Stop\2-Start , ;(dd)номер камеры , ;(dd)максимальная ширина ;(dd)и высота видеокадра GetTime proto :DWORD ;Возвращает указатель на строчку. ;Параметр: ;[in]указатель на присоединяемое расширение comment * -------------------------------------------------------------------------------------------------------- Все функции, которым передаётся недействительный идентификатор окна, вернут eax=-2 Возвращаемый функцией CreateVideoWindow идентификатор можно использовать некоторыми стандартными WinAPI функциями, такими как: DestroyWindow, MoveWindow, ShowWindow... Созданное окно посылает родительскому окну сообщения от клавиатуры и мыши, через сообщение VWM_COMMAND (WM_USER + 160). wParam содержит идентификатор окна, lParam - указатель на структуру: (dd)vw_uMsg (dd)vw_wParam (dd)vw_lParam --------------------------------------------------------------------------------------------------------------------- Библиотека поддерживает одновременную работу с несколькими окнами (следует учитывать особенность directshow транслировать видео с одной камеры только в одно окно) В этой версии стабильная работа возможна лиш с статичным составом камер, поэтому при подключении\отключении следует тестовую программу перезапускать --------------------------------------------------------------------------------------------------------------------- * А это демка: Код (ASM): .486 .model flat,stdcall option casemap:none include \masm32\include\Gdi32.inc include \masm32\include\windows.inc include \masm32\include\masm32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\Comctl32.inc include \masm32\include\comdlg32.inc include \masm32\include\shell32.inc include \masm32\include\dialogs.inc include \masm32\include\advapi32.inc include \masm32\macros\macros.asm include \masm32\include\ole32.inc include \masm32\include\oleaut32.inc include \masm32\include\winmm.inc includelib \masm32\lib\winmm.lib includelib \masm32\lib\ole32.lib includelib \masm32\lib\oleaut32.lib includelib \masm32\lib\Gdi32.lib includelib \masm32\lib\masm32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\Comctl32.lib includelib \masm32\lib\comdlg32.lib includelib \masm32\lib\shell32.lib includelib \masm32\lib\advapi32.lib ;----------------------------- includelib webcam32.lib include webcam32.inc ;----------------------------- WinMain proto :DWORD, :DWORD, :DWORD, :DWORD alig_window proto :DWORD, :DWORD, :DWORD, :DWORD .const VWM_COMMAND equ WM_USER + 160 .data stepvw dd 5 align dword ClassName db "Test_Video_Window",0 ClassNameP db "E_WEBCAM",0 listbox db "listbox",0 .data? hInstance dd ? CommandLine dd ? hWin dd ? hmenu dd ? focus_hwnd dd ? listbox_hwnd dd ? buffer db 1024 dup(?) poin POINT <> rct RECT <> wc WNDCLASSEX <> iccex INITCOMMONCONTROLSEX <> seci SHELLEXECUTEINFO <> bmpinf BITMAPINFOHEADER <> .code start: invoke GetCommandLine mov CommandLine, eax invoke GetModuleHandle, 0 mov hInstance, eax mov iccex.dwSize, sizeof INITCOMMONCONTROLSEX mov iccex.dwICC, ICC_WIN95_CLASSES invoke InitCommonControlsEx, addr iccex invoke WinMain, hInstance, 0, CommandLine, SW_SHOWDEFAULT invoke ExitProcess, eax ;################################################################################# WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD LOCAL msg:MSG mov wc.cbSize, sizeof WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, offset WndProc mov wc.cbClsExtra, 0 mov wc.cbWndExtra, 0 mrm wc.hInstance, hInstance invoke LoadIcon, hInstance, 1101 mov wc.hIcon, eax mov wc.hIconSm, eax invoke LoadCursor, 0, IDC_ARROW mov wc.hCursor, eax mov wc.hbrBackground, COLOR_BTNFACE+1 mov wc.lpszMenuName, 0 mov wc.lpszClassName, offset ClassName invoke RegisterClassEx, addr wc invoke CreateWindowEx, 0, addr ClassName, SADD("webcam32.lib test"), WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN, 0, 0, 950, 550, 0, 0, hInst, 0 mov hWin, eax invoke alig_window, eax, 950, 550, SW_SHOWMAXIMIZED invoke UpdateWindow, eax .WHILE TRUE invoke GetMessage, addr msg, 0, 0, 0 .BREAK .IF (!eax) invoke TranslateMessage, addr msg invoke DispatchMessage, addr msg .ENDW mov eax, msg.wParam ret WinMain endp ;################################################################################# WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL buff:DWORD LOCAL hdc:DWORD LOCAL hdc1:DWORD LOCAL bmap:DWORD .IF uMsg== WM_CREATE invoke InitLib invoke CreatePopupMenu mov hmenu, eax invoke AppendMenu, hmenu, MF_STRING, 3001, SADD("Старт") invoke AppendMenu, hmenu, MF_STRING, 3002, SADD("Стоп") invoke AppendMenu, hmenu, MF_SEPARATOR, 0, 0 invoke AppendMenu, hmenu, MF_STRING, 3005, SADD("Фотография") invoke AppendMenu, hmenu, MF_STRING, 3006, SADD("GetBuffer") invoke AppendMenu, hmenu, MF_SEPARATOR, 0, 0 invoke AppendMenu, hmenu, MF_STRING, 3004, SADD("Настройка") invoke AppendMenu, hmenu, MF_STRING, 3007, SADD("Цвет окна") mov wc.cbSize, SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_NOCLOSE mov wc.lpfnWndProc, OFFSET WndProcP mov wc.hIcon, 0 mov wc.hIconSm, 0 mov wc.lpszClassName, OFFSET ClassNameP invoke RegisterClassEx, addr wc invoke CreateWindowEx, 0, addr ClassNameP, SADD("Список камер:"), WS_CAPTION or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or WS_THICKFRAME, 0, 0, 250, 250, hWnd, 0, hInstance, 0 invoke alig_window, eax, 250, 250, SW_SHOW ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\обработка сообщений .ELSEIF uMsg== VWM_COMMAND mov eax, lParam mov ebx, dword ptr[eax] .IF ebx== WM_RBUTTONDOWN ;меню mrm focus_hwnd, wParam invoke GetCursorPos, addr poin invoke TrackPopupMenu, hmenu, 0, poin.x, poin.y, 0, hWnd, 0 .ENDIF ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .ELSEIF uMsg== WM_COMMAND mov eax, wParam ror eax, 16 .IF ax== BN_CLICKED ror eax, 16 .IF ax== 3001 ;старт invoke StartVideo, focus_hwnd .IF eax== 0 invoke MessageBox, hWnd, SADD("Камера занята или отключена!"), SADD("Информация"), MB_OK .ENDIF .ELSEIF ax== 3002 ;стоп invoke StopVideo, focus_hwnd .ELSEIF ax== 3004 ;настройка камеры invoke dWebCam, focus_hwnd .ELSEIF ax== 3005 ;фотография invoke GetTime, SADD("bmp") mov bmap, eax invoke PhotoSave, focus_hwnd, eax .IF eax!= 0 invoke PlaySound, 1100, 0, SND_RESOURCE or SND_ASYNC mov seci.cbSize, sizeof SHELLEXECUTEINFO mrm seci.lpFile, bmap mov seci.fMask, SEE_MASK_NOCLOSEPROCESS mov seci.nShow, SW_SHOWMAXIMIZED invoke ShellExecuteEx, addr seci .ENDIF .ELSEIF ax== 3006 ;кадр выводится в окно invoke GetBuffer, focus_hwnd, addr bmpinf .IF eax!= 0 mov buff, eax invoke CreateCompatibleDC, 0 mov hdc1, eax invoke CreateDIBSection, hdc1, addr bmpinf, 0, 0, 0, 0 mov bmap, eax invoke SelectObject, hdc1, bmap invoke GetDC, hWnd mov hdc, eax invoke SetDIBits, hdc1, bmap, 0, bmpinf.biHeight, buff, addr bmpinf, 0 invoke GetClientRect, hWnd, addr rct invoke StretchBlt, hdc, 0, 0, rct.right, rct.bottom, hdc1, 0, 0, bmpinf.biWidth, bmpinf.biHeight, SRCCOPY invoke DeleteDC, hdc invoke DeleteDC, hdc1 invoke DeleteObject, bmap .ENDIF .ELSEIF ax== 3007 ;цвет фона invoke ColorDialog, focus_hwnd, 0, 0 invoke CreateSolidBrush, eax invoke SetClassLong, focus_hwnd, GCL_HBRBACKGROUND, eax invoke GetClientRect, focus_hwnd, addr rct invoke InvalidateRect, focus_hwnd, addr rct, 1 .ENDIF .ENDIF .ELSEIF uMsg== WM_CLOSE || uMsg== WM_DESTROY invoke UninitLib invoke PostQuitMessage, 0 .ELSE invoke DefWindowProc, hWnd, uMsg, wParam, lParam ret .ENDIF return 0 WndProc endp ;################################################################################# WndProcP proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL i_str:DWORD .IF uMsg== WM_CREATE invoke RetFontHandle, SADD("Verdana"), 20, 0 mov i_str, eax invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr listbox, 0, WS_CHILD or WS_VISIBLE or WS_VSCROLL or LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or LBS_DISABLENOSCROLL or LBS_MULTIPLESEL or LBS_NOTIFY, 0, 0, 0, 0, hWnd, 3030, hInstance, 0 mov listbox_hwnd, eax invoke SendMessage, listbox_hwnd, WM_SETFONT, i_str, 01h mov i_str, 0 create_vw: invoke GetWebCamName, addr buffer .IF eax== 0 jmp end_create_vw .ENDIF mov i_str, eax invoke SendMessage, listbox_hwnd, LB_ADDSTRING, 0, addr buffer jmp create_vw end_create_vw: .IF i_str== 0 invoke SetWindowText, hWnd, SADD("Нет камер") invoke EnableWindow, hWnd, 0 .ENDIF .ELSEIF uMsg== WM_COMMAND mov eax, wParam .IF ax== 3030 ror eax, 16 .IF ax== LBN_SELCHANGE invoke SendMessage, listbox_hwnd, LB_GETLISTBOXINFO, 0, 0 mov i_str, eax list_c: cmp i_str, -1 je list_e invoke SendMessage, listbox_hwnd, LB_GETSEL, i_str, 0 .IF eax== 1 invoke SendMessage, listbox_hwnd, LB_GETITEMDATA, i_str, 0 .IF eax== 0 invoke SendMessage, listbox_hwnd, LB_GETTEXT, i_str, addr buffer mov ebx, i_str inc ebx invoke CreateVideoWindow, ebx, addr buffer, WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or WS_THICKFRAME or WS_CAPTION, stepvw, stepvw, 250, 220, hWin, hInstance .IF eax== 0 invoke SendMessage, listbox_hwnd, LB_SETSEL, i_str, 0 invoke SendMessage, listbox_hwnd, LB_SETITEMDATA, i_str, 0 .ELSE invoke SendMessage, listbox_hwnd, LB_SETITEMDATA, i_str, eax add stepvw, 10 .ENDIF .ENDIF .ELSEIF eax== 0 invoke SendMessage, listbox_hwnd, LB_GETITEMDATA, i_str, 0 .IF eax> 0 invoke DestroyWindow, eax invoke SendMessage, listbox_hwnd, LB_SETITEMDATA, i_str, 0 .ENDIF .ENDIF dec i_str jmp list_c list_e: .ENDIF .ENDIF .ELSEIF uMsg== WM_SIZE invoke GetClientRect, hWnd, addr rct invoke MoveWindow, listbox_hwnd, 0, 0, rct.right, rct.bottom, 1 .ELSE invoke DefWindowProc, hWnd, uMsg, wParam, lParam ret .ENDIF return 0 WndProcP endp ;################################################################################# alig_window proc hwind:DWORD, vol1:DWORD, vol2:DWORD, show:DWORD LOCAL poi:POINT invoke GetSystemMetrics, SM_CXSCREEN mov poi.x, eax shr poi.x, 01h mov eax, vol1 shr eax, 01h sub poi.x ,eax invoke GetSystemMetrics, SM_CYSCREEN mov poi.y, eax shr poi.y, 01h mov eax, vol2 shr eax, 01h sub poi.y ,eax invoke MoveWindow, hwind, poi.x, poi.y, vol1, vol2, 1 invoke ShowWindow, hwind, show mov eax, hwind ret alig_window endp ;################################################################################# end start
webcam32.lib: Код (ASM): .486 .model flat, stdcall option casemap :none include \masm32\include\windows.inc include \masm32\include\gdi32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\ole32.inc include \masm32\include\oleaut32.inc include \masm32\include\masm32.inc includelib \masm32\lib\masm32.lib include \masm32\macros\macros.asm .const WM_GRAPHNOTIFY equ WM_USER + 161 .data include directshow.inc InfoStr db 42h,4Dh,36h,20h,1Ch,0,0,0,0,0,36h,0,0,0 num dd 0 maxdev dd 0 .data? h_buf dd ? ClassEnum dd ? DevEnum dd ? AM_MEDIA_TYPE STRUCT majortype GUID <> subtype GUID <> bFixedSizeSamples dd ? bTemporalCompression dd ? lSampleSize dd ? formattype GUID <> pUnk dd ? cbFormat dd ? pbFormat dd ? AM_MEDIA_TYPE ENDS amt AM_MEDIA_TYPE <> CAUUID STRUCT cElems dd ? pElems dd ? CAUUID ENDS cauuid CAUUID <> VARIANT STRUCT vt dw ? wReserved1 dw ? wReserved2 dw ? wReserved3 dw ? parray dd ? xyz dd ? VARIANT ENDS vt VARIANT <> rct_1 RECT <> rct_2 RECT <> bmpinf BITMAPINFOHEADER <> VWInfoBuffer db 32 dup (?) TimeBuffer db 512 dup (?) wcBuffer db 1024 dup (?) .code ;##################################################################### CreateVideoWindow proc WebCamNum:DWORD, wvName:DWORD, wvwc:DWORD, wvs_vol:DWORD, wvx:DWORD, wvy:DWORD, wvw:DWORD, wvh:DWORD, hParent:DWORD, n_rend:DWORD LOCAL hVWindow:DWORD LOCAL GrabberF:DWORD LOCAL Grabber:DWORD LOCAL NulleG:DWORD LOCAL Graph:DWORD LOCAL Builder:DWORD LOCAL VidWin:DWORD LOCAL ControlVideo:DWORD LOCAL MedVed:DWORD LOCAL Src:DWORD LOCAL Fetched:DWORD LOCAL Moniker:DWORD LOCAL ClassEnum1:DWORD LOCAL DevEnum1:DWORD LOCAL wc:WNDCLASSEX LOCAL numstr[8]:BYTE LOCAL buffer[1024]:BYTE LOCAL buffer1[1024]:BYTE invoke CoCreateInstance, addr CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER, addr IID_IGraphBuilder, addr Graph cmp eax, 0 jne error_cvw invoke CoCreateInstance, addr CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER, addr IID_ICaptureGraphBuilder2, addr Builder cmp eax, 0 jne error_cvw mov eax, Builder mov ebx, [eax] invoke (ICaptureGraphBuilder2 PTR [ebx]).SetFiltergraph, Builder, Graph cmp eax, 0 jne error_cvw invoke CoCreateInstance, addr CLSID_SystemDeviceEnum, 0, CLSCTX_INPROC_SERVER, addr IID_ICreateDevEnum, addr DevEnum1 cmp eax, 0 jne error_cvw mov eax, DevEnum1 mov ebx, [eax] invoke (ICreateDevEnum PTR [ebx]).CreateClassEnumerator, DevEnum1, addr CLSID_VideoInputDeviceCategory, addr ClassEnum1, 0 cmp eax, 0 jne error_cvw mov eax, ClassEnum1 mov ebx, [eax] invoke (IEnumMoniker PTR [ebx]).Reset, ClassEnum1 cmp eax, 0 jne error_cvw dec WebCamNum invoke (IEnumMoniker PTR [ebx]).Skip, ClassEnum1, WebCamNum invoke (IEnumMoniker PTR [ebx]).Next, ClassEnum1, 1, addr Moniker, addr Fetched cmp eax, 0 jne error_cvw cmp Fetched, 1 jne error_cvw mov eax, Moniker mov ebx, [eax] invoke (IMoniker PTR [ebx]).BindToObject, Moniker, 0, 0, addr IID_IBaseFilter, addr Src cmp eax, 0 jne error_cvw invoke (IEnumMoniker PTR [ebx]).Release, Moniker mov eax, ClassEnum1 mov ebx, [eax] invoke (ICreateDevEnum PTR [ebx]).Release, ClassEnum1 mov eax, DevEnum1 mov ebx, [eax] invoke (ICreateDevEnum PTR [ebx]).Release, DevEnum1 mov buffer[0], 0 invoke szMultiCat, 2, addr buffer, SADD("Videocamera_"), addr numstr invoke MultiByteToWideChar, CP_ACP, 0, addr buffer, -1, addr buffer1, MAX_PATH mov eax, Graph mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).AddFilter, Graph, Src, addr buffer1 cmp eax, 0 jne error_cvw mov eax, Graph mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).QueryInterface, Graph, addr IID_IVideoWindow, addr VidWin cmp eax, 0 jne error_cvw mov eax, Graph mov ebx,[eax] invoke (IGraphBuilder PTR [ebx]).QueryInterface, Graph, addr IID_IMediaControl, addr ControlVideo cmp eax, 0 jne error_cvw mov eax, Graph mov ebx,[eax] invoke (IGraphBuilder PTR [ebx]).QueryInterface, Graph, addr IID_IMediaEventEx, addr MedVed cmp eax, 0 jne error_cvw invoke CoCreateInstance, addr CLSID_SampleGrabber, 0, CLSCTX_INPROC_SERVER, addr IID_IBaseFilter, addr GrabberF mov eax, Graph mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).AddFilter, Graph, GrabberF, SADD("Sample_Grabber") .IF n_rend== 1 invoke CoCreateInstance, addr CLSID_NullRenderer, 0, CLSCTX_INPROC_SERVER, addr IID_IBaseFilter, addr NulleG mov eax, Graph mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).AddFilter, Graph, NulleG, SADD("Null_Renderer") .ELSE mov NulleG, 0 .ENDIF mov eax, GrabberF mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).QueryInterface, GrabberF, addr IID_ISampleGrabber, addr Grabber lea esi, MEDIATYPE_Video lea edi, amt.majortype mov ecx, 4 rep movsd lea esi, MEDIASUBTYPE_RGB24 lea edi, amt.subtype mov ecx, 4 rep movsd lea esi, FORMAT_VideoInfo lea edi, amt.formattype mov ecx, 4 rep movsd mov eax, Grabber mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).SetMediaType, Grabber, addr amt invoke (ISampleGrabber PTR [ebx]).SetOneShot, Grabber, 0 invoke (ISampleGrabber PTR [ebx]).SetBufferSamples, Grabber, 1 mov eax, Builder mov ebx, [eax] invoke (ICaptureGraphBuilder2 PTR [ebx]).RenderStream, Builder, addr PIN_CATEGORY_PREVIEW, addr MEDIATYPE_Video, Src, GrabberF, NulleG jmp ok_cvw error_cvw: mov eax, Builder mov ebx, [eax] invoke (ICaptureGraphBuilder2 PTR [ebx]).Release, Builder mov eax, Graph mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).Release, Graph return 0 ok_cvw: mov buffer[0], 0 inc num invoke dwtoa, num, addr numstr invoke szMultiCat, 2, addr buffer, SADD("video_window_class_"), addr numstr mov esi, wvwc lea edi, wc mov ecx, 12 rep movsd mov wc.cbSize, sizeof WNDCLASSEX mov wc.lpfnWndProc, OFFSET VideoWindowProc mov wc.cbClsExtra, 0 mov wc.cbWndExtra, 56 invoke LoadCursor, 0, IDC_ARROW mov wc.hCursor, eax mov wc.lpszMenuName, 0 lea eax, buffer mov wc.lpszClassName, eax mrm wc.hIconSm, wc.hIcon invoke RegisterClassEx, addr wc mov eax, wvs_vol or eax, WS_CLIPCHILDREN or eax, WS_CHILD invoke CreateWindowEx, 0, addr buffer, wvName, eax, wvx, wvy, wvw, wvh, hParent, 0, wc.hInstance, 0 mov hVWindow, eax invoke GetClientRect, hVWindow, addr rct_1 inc WebCamNum invoke SetWindowLong, hVWindow, 0, WebCamNum ;номер камеры invoke SetWindowLong, hVWindow, 4, NulleG invoke SetWindowLong, hVWindow, 48, 1 ;1- стоп, 2- старт invoke SetWindowLong, hVWindow, 16, Graph invoke SetWindowLong, hVWindow, 20, Builder invoke SetWindowLong, hVWindow, 24, Src invoke SetWindowLong, hVWindow, 8, ControlVideo invoke SetWindowLong, hVWindow, 12, VidWin invoke SetWindowLong, hVWindow, 28, GrabberF invoke SetWindowLong, hVWindow, 32, Grabber invoke SetWindowLong, hVWindow, 44, MedVed mov eax, MedVed mov ebx,[eax] invoke (IMediaEvent PTR [ebx]).SetNotifyWindow, MedVed, hVWindow, WM_GRAPHNOTIFY, 0 mov eax, VidWin mov ebx, [eax] invoke (IVideoWindow PTR [ebx]).put_Owner, VidWin, hVWindow invoke (IVideoWindow PTR [ebx]).put_MessageDrain, VidWin, hVWindow invoke (IVideoWindow PTR [ebx]).put_WindowStyle, VidWin, WS_CHILD or WS_CLIPSIBLINGS invoke (IVideoWindow PTR [ebx]).SetWindowPosition, VidWin, 0, 0, rct_1.right, rct_1.bottom invoke (IVideoWindow PTR [ebx]).put_Visible, VidWin, 0 mov eax, Grabber mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).GetConnectedMediaType, Grabber, addr amt mov esi, amt.pbFormat add esi, 48 lea edi, bmpinf mov ecx, 10 rep movsd invoke CoTaskMemFree, amt.pbFormat invoke SetWindowLong, hVWindow, 36, bmpinf.biWidth invoke SetWindowLong, hVWindow, 40, bmpinf.biHeight mov eax, hVWindow ret CreateVideoWindow endp ;##################################################################### VideoWindowProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD LOCAL SubConst:DWORD .IF uMsg== WM_SIZE invoke GetClientRect, hWin, addr rct_1 invoke GetWindowLong, hWin, 12 .if eax== 0 ret .endif mov ebx,[eax] invoke (IVideoWindow PTR [ebx]).SetWindowPosition, eax, 0, 0, rct_1.right, rct_1.bottom invoke GetParent, hWin mov ebx, eax mrm rct_2.left, uMsg mrm rct_2.top, wParam mrm rct_2.right, lParam invoke SendMessage, ebx, WM_USER+160, hWin, addr rct_2 .ELSEIF uMsg== WM_DESTROY invoke GetWindowLong, hWin, 8 mov SubConst, eax mov ebx, [eax] invoke (IMediaControl PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 44 mov SubConst, eax mov ebx,[eax] invoke (IMediaEvent PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 12 mov SubConst, eax mov ebx, [eax] invoke (IVideoWindow PTR [ebx]).put_Visible, SubConst, 0 invoke (IVideoWindow PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 20 mov SubConst, eax mov ebx, [eax] invoke (ICaptureGraphBuilder2 PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 24 mov SubConst, eax mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 16 mov SubConst, eax mov ebx, [eax] invoke (IGraphBuilder PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 32 mov SubConst, eax mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).Release, SubConst invoke GetWindowLong, hWin, 28 mov SubConst, eax mov ebx, [eax] invoke (IBaseFilter PTR [ebx]).Release, SubConst .ELSEIF uMsg== WM_LBUTTONDOWN || uMsg== WM_LBUTTONUP || uMsg== WM_LBUTTONDBLCLK || uMsg== WM_RBUTTONDOWN || uMsg== WM_RBUTTONUP || uMsg== WM_RBUTTONDBLCLK || uMsg== WM_MBUTTONDOWN || uMsg== WM_MBUTTONUP || uMsg== WM_MBUTTONDBLCLK || uMsg== WM_MOUSEMOVE || uMsg== WM_MOUSEACTIVATE || uMsg== WM_KEYDOWN || uMsg== WM_KEYUP || uMsg== WM_CHAR invoke GetParent, hWin mov SubConst, eax mrm rct_2.left, uMsg mrm rct_2.top, wParam mrm rct_2.right, lParam invoke SendMessage, SubConst, WM_USER+160, hWin, addr rct_2 .ELSEIF uMsg== WM_SYSKEYDOWN || uMsg== WM_SYSKEYUP || uMsg== WM_SYSCHAR || uMsg== WM_CLOSE || uMsg== WM_SHOWWINDOW || uMsg== WM_MOVE || uMsg== WM_ACTIVATE || uMsg== WM_GETMINMAXINFO || uMsg== WM_POWER || uMsg== WM_SETCURSOR || uMsg== WM_PAINT || uMsg== WM_HELP || uMsg== WM_TIMER invoke GetParent, hWin mov SubConst, eax mrm rct_2.left, uMsg mrm rct_2.top, wParam mrm rct_2.right, lParam invoke SendMessage, SubConst, WM_USER+160, hWin, addr rct_2 .ELSEIF uMsg== WM_GRAPHNOTIFY invoke GetWindowLong, hWin, 44 .if eax== 0 ret .endif mov SubConst, eax mov ebx,[eax] invoke (IMediaEvent PTR [ebx]).GetEvent, SubConst, addr rct_2.left, addr rct_2.top, addr rct_2.right, 0 invoke GetParent, hWin invoke SendMessage, eax, WM_GRAPHNOTIFY, hWin, addr rct_2 ; invoke (IMediaEvent PTR [ebx]).FreeEventParams, SubConst, addr rct_2.left, addr rct_2.top, addr rct_2.right return 0 .ENDIF invoke DefWindowProc, hWin, uMsg, wParam, lParam ret VideoWindowProc endp ;##################################################################### InitLib proc invoke CoInitializeEx, 0, COINIT_APARTMENTTHREADED invoke LocalAlloc, 040h, 30000000 mov h_buf, eax return 1 InitLib endp ;##################################################################### UninitLib proc invoke CoUninitialize invoke LocalFree, h_buf return 1 UninitLib endp ;##################################################################### StartVideo proc hWin:DWORD invoke GetWindowLong, hWin, 48 .IF eax== 0 return -2 .ENDIF invoke GetWindowLong, hWin, 8 mov ebx, [eax] invoke (IMediaControl PTR [ebx]).Run, eax .IF eax== 1 ;успешно invoke GetWindowLong, hWin, 12 mov ebx, [eax] invoke (IVideoWindow PTR [ebx]).put_Visible, eax, -1 invoke SetWindowLong, hWin, 48, 2 .ELSEIF eax== 0 return -1 .ELSE invoke GetWindowLong, hWin, 12 mov ebx, [eax] invoke (IVideoWindow PTR [ebx]).put_Visible, eax, 0 invoke SetWindowLong, hWin, 48, 1 return 0 .ENDIF return 1 StartVideo endp ;##################################################################### StopVideo proc hWin:DWORD invoke GetWindowLong, hWin, 48 .IF eax== 0 return -2 .ENDIF invoke SetWindowLong, hWin, 48, 1 invoke GetWindowLong, hWin, 8 mov ebx, [eax] invoke (IMediaControl PTR [ebx]).Stop, eax invoke GetWindowLong, hWin, 12 mov ebx, [eax] invoke (IVideoWindow PTR [ebx]).put_Visible, eax, 0 return 1 StopVideo endp ;##################################################################### GetTime proc exName:DWORD LOCAL stmt:SYSTEMTIME LOCAL loc_time_buffer[16]:BYTE invoke GetLocalTime, addr stmt movzx ebx, stmt.wYear invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcpy, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("-") movzx ebx, stmt.wMonth invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("-") movzx ebx, stmt.wDay invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("_") movzx ebx, stmt.wHour invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("h") invoke lstrcat, addr TimeBuffer, SADD("-") movzx ebx, stmt.wMinute invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("m") invoke lstrcat, addr TimeBuffer, SADD("-") movzx ebx, stmt.wSecond invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("s") invoke lstrcat, addr TimeBuffer, SADD("-") movzx ebx, stmt.wMilliseconds invoke dwtoa, ebx, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, addr loc_time_buffer invoke lstrcat, addr TimeBuffer, SADD("ms.") invoke lstrcat, addr TimeBuffer, exName lea eax, TimeBuffer ret GetTime endp ;##################################################################### dWebCam proc hWin:DWORD LOCAL spec:DWORD LOCAL Src:DWORD LOCAL buffer[1024]:BYTE LOCAL buffer1[1024]:BYTE invoke GetWindowLong, hWin, 0 .IF eax== 0 return -2 .ENDIF invoke GetWindowLong, hWin, 24 mov Src, eax mov ebx, [eax] invoke (IAMVideoProcAmp PTR [ebx]).QueryInterface, Src, addr IID_ISpecifyPropertyPages, addr spec mov eax, spec mov ebx, [eax] invoke (ISpecifyPropertyPages PTR [ebx]).GetPages, spec, addr cauuid invoke (ISpecifyPropertyPages PTR [ebx]).Release, spec invoke GetWindowText, hWin, addr buffer, 1024 invoke MultiByteToWideChar, CP_ACP, 0, addr buffer, -1, addr buffer1, MAX_PATH cmp eax, 0 je endDlgWebCam invoke OleCreatePropertyFrame, hWin, 0, 0, addr buffer1, 1, addr Src, cauuid.cElems, cauuid.pElems, 0, 0, 0 cmp eax, S_OK jne endDlgWebCam invoke CoTaskMemFree, cauuid.pElems return 1 endDlgWebCam: return 0 dWebCam endp ;##################################################################### GetWebCamName proc wcName:DWORD LOCAL Fetched:DWORD LOCAL PropBag:DWORD LOCAL Moniker:DWORD LOCAL wcBuffer1[1024]:BYTE .IF maxdev== 0 invoke CoCreateInstance, addr CLSID_SystemDeviceEnum, 0, CLSCTX_INPROC_SERVER, addr IID_ICreateDevEnum, addr DevEnum .IF eax!= 0 return 0 .ENDIF mov eax, DevEnum mov ebx, [eax] invoke (ICreateDevEnum PTR [ebx]).CreateClassEnumerator, DevEnum, addr CLSID_VideoInputDeviceCategory, addr ClassEnum, 0 .IF ClassEnum== 0 || eax!= 0 return 0 .ENDIF .ENDIF mov eax, ClassEnum mov ebx, [eax] invoke (IEnumMoniker PTR [ebx]).Next, ClassEnum, 1, addr Moniker, addr Fetched cmp eax, S_OK jne endEnumDevice cmp Fetched, 1 jne endEnumDevice mov eax, Moniker mov ebx, [eax] invoke (IMoniker PTR [ebx]).BindToStorage, Moniker, 0, 0, addr IID_IPropertyBag, addr PropBag cmp eax, S_OK jne endEnumDevice invoke MultiByteToWideChar, CP_ACP, 0, SADD("FriendlyName"), -1, addr wcBuffer1, MAX_PATH mov vt.vt, VT_BSTR mov vt.parray, 0 mov eax, PropBag mov ebx, [eax] invoke (IPropertyBag PTR [ebx]).Read, PropBag, addr wcBuffer1, addr vt, 0 invoke WideCharToMultiByte, CP_ACP, 0, vt.parray, -1, addr wcBuffer, MAX_PATH, 0, 0 invoke SysFreeString, vt.parray mov eax, PropBag mov ebx, [eax] invoke (IPropertyBag PTR [ebx]).Release, PropBag mov eax, Moniker mov ebx, [eax] invoke (IEnumMoniker PTR [ebx]).Release, Moniker inc maxdev cmp maxdev, 101 je endEnumDevice invoke lstrcpy, wcName, addr wcBuffer mov eax, maxdev ret endEnumDevice: mov eax, ClassEnum mov ebx, [eax] invoke (ICreateDevEnum PTR [ebx]).Release, ClassEnum mov eax, DevEnum mov ebx, [eax] invoke (ICreateDevEnum PTR [ebx]).Release, DevEnum invoke lstrcpy, wcName, SADD("end") mov maxdev, 0 return 0 GetWebCamName endp ;##################################################################### PhotoSave proc hWin:DWORD, fName:DWORD LOCAL size_buf:DWORD LOCAL rzv:DWORD LOCAL hend:DWORD LOCAL Grabber:DWORD invoke GetWindowLong, hWin, 48 .IF eax== 0 return -2 .ELSEIF eax== 1 return 0 .ENDIF invoke GetWindowLong, hWin, 32 mov Grabber, eax mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).GetConnectedMediaType, Grabber, addr amt .IF eax!= 0 return 0 .ENDIF mov esi, amt.pbFormat add esi, 48 lea edi, bmpinf mov ecx, 10 rep movsd invoke CoTaskMemFree, amt.pbFormat mov eax, Grabber mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).GetCurrentBuffer, Grabber, addr size_buf, 0 .IF eax!= 0 return 0 .ENDIF invoke (ISampleGrabber PTR [ebx]).GetCurrentBuffer, Grabber, addr size_buf, h_buf .IF eax!= 0 return 0 .ENDIF invoke CreateFile, fName, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 .IF eax== INVALID_HANDLE_VALUE return 0 .ENDIF mov hend, eax invoke WriteFile, hend, addr InfoStr, 14, addr rzv, 0 invoke WriteFile, hend, addr bmpinf, 40, addr rzv, 0 invoke WriteFile, hend, h_buf, size_buf, addr rzv, 0 invoke CloseHandle, hend return 1 PhotoSave endp ;##################################################################### GetBuffer proc hWin:DWORD, bufStruct:DWORD LOCAL wWidth:DWORD LOCAL wHeight:DWORD LOCAL size_buf:DWORD LOCAL Grabber:DWORD invoke GetWindowLong, hWin, 48 .IF eax== 0 return -2 .ELSEIF eax== 1 return 0 .ENDIF invoke GetWindowLong, hWin, 32 mov Grabber, eax mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).GetConnectedMediaType, Grabber, addr amt .IF eax!= 0 return 0 .ENDIF mov esi, amt.pbFormat add esi, 48 mov edi, bufStruct mov ecx, 10 rep movsd invoke CoTaskMemFree, amt.pbFormat mov eax, Grabber mov ebx, [eax] invoke (ISampleGrabber PTR [ebx]).GetCurrentBuffer, Grabber, addr size_buf, 0 .IF eax!= 0 return 0 .ENDIF invoke (ISampleGrabber PTR [ebx]).GetCurrentBuffer, Grabber, addr size_buf, h_buf .IF eax!= 0 return 0 .ENDIF mov eax, h_buf ret GetBuffer endp ;##################################################################### GetVWInfo proc hWin:DWORD LOCAL SubConst:DWORD lea eax, VWInfoBuffer mov SubConst, eax invoke GetWindowLong, hWin, 48 ;1- стоп, 2- старт .IF eax== 0 return -2 .ENDIF mov ebx, SubConst mov dword ptr[ebx], eax invoke GetWindowLong, hWin, 0 ;WebCamNum mov ebx, SubConst mov dword ptr[ebx+4], eax invoke GetWindowLong, hWin, 36 ;w mov ebx, SubConst mov dword ptr[ebx+8], eax invoke GetWindowLong, hWin, 40 ; h mov ebx, SubConst mov dword ptr[ebx+12], eax mov eax, ebx ret GetVWInfo endp ;##################################################################### end