发一个摄像头捕捉程序,带截图功能。 By MengXP(于2007-12-19发表)

以前有人发过的,但代码太乱…………
相关资料
下载...

.386
.Model Flat,StdCall
Option CaseMap :None

Include Windows.inc
Include User32.inc
Include Kernel32.inc


IncludeLib User32.lib
IncludeLib Kernel32.lib

.Data

.Data?
hInstance    dd ?
hDlg        dd ?
hAvicap32    dd ?
capCreate    dd ?
capGet        dd ?
hCapture    dd ?
bi        BITMAPINFO <>

.Code
FrameCallback    Proc    hWnd,lpVHdr
        invoke    SendMessage,hCapture,WM_CAP_FILE_SAVEDIBA,0,CTEXT("Capture.bmp")
        mov    eax,1
        ret
FrameCallback    EndP

WndProc    Proc    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
        Local    szDeviceName[256]:BYTE
        Local    szDeviceVersion[256]:BYTE
        
        .if    uMsg == WM_CLOSE
            invoke    EndDialog,hWnd,0
            
        .elseif uMsg == WM_INITDIALOG
            m2m    hDlg,hWnd
            invoke    LoadLibrary,CTEXT("Avicap32.dll")
            mov    hAvicap32,eax
            invoke    GetProcAddress,hAvicap32,CTEXT("capCreateCaptureWindowA")
            mov    capCreate,eax
            invoke    GetProcAddress,hAvicap32,CTEXT("capGetDriverDescriptionA")
            mov    capGet,eax
            push    0
            push    hWnd
            push    240
            push    320
            push    0
            push    0
            push    WS_CHILD or WS_VISIBLE
            push    CTEXT("Camera Example")
            call    capCreate
            .if    eax
                mov    hCapture,eax
                xor    ebx,ebx
                .While    ebx < 10
                    push    256
                    lea    eax,szDeviceVersion
                    push    eax
                    push    256
                    lea    eax,szDeviceName
                    push    eax
                    push    ebx
                    call    capGet
                    .if    eax
                        invoke    SendMessage,hCapture,WM_CAP_SET_CALLBACK_FRAME,0,offset FrameCallback
                        invoke    SendMessage,hCapture,WM_CAP_DRIVER_CONNECT,ebx,0
                        invoke    SendMessage,hCapture,WM_CAP_GET_VIDEOFORMAT,sizeof BITMAPINFO,addr bi
                        invoke    SetTimer,hWnd,0,40,0
                        ;使用定时器而不使用 Preview 消息是因为当程序窗口被盖住的时候无法继续 Preview (-_-)不知道我说没说明白
                        .Break
                    .endif
                    inc    ebx
                .EndW
            .endif
            
        .elseif    uMsg == WM_TIMER
            invoke    SendMessage,hCapture,WM_CAP_GRAB_FRAME,0,0
            
        .else
            mov    eax,FALSE
            ret
        .endif
        mov    eax,TRUE
        ret
WndProc    EndP

Start:
    invoke    GetModuleHandle,0
    mov    hInstance,eax
    invoke    DialogBoxParam,eax,1000,0,WndProc,0
    invoke    ExitProcess,0
End Start

#include "resource.h"
#include "ole.h"

1000 DIALOGEX 0, 0, 223, 162
STYLE DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Camera example"
LANGUAGE LANG_CHINESE, 0x2
FONT 9, "宋体"
{
}

并不是所有的贴子都是原创,此时作者均指发表的人而不是文章的作者,作者会说明是否是转贴