[Reprint] VC-camera control SDK source code

Source: Internet
Author: User

Reprinted] VC-camera control SDK source code

Information Source: FIG http://www.cnasm.com/

# Include <windows. h>
# Include <stdio. h>
# Include <VFW. h>
# Pragma comment (Lib, "vfw32.lib ")

Hwnd ghwndcap; // capture window handle
Capdrivercaps gcapdrivercaps; // video drive capability
Capstatus gcapstatus; // The status of the capture window.
Char szcapturefile [] = "mycap. Avi ";
Char gachbuffer [20];

Lresult callback wndproc (hwnd, uint, wparam, lparam );

Lresult callback statuscallbackproc (hwnd, int NID, lpstr lpstatustext)
{
If (! Ghwndcap) return false; // get the capture window status
Capgetstatus (ghwndcap, & gcapstatus, sizeof (capstatus); // update the size of the capture window.
Setwindowpos (ghwndcap, null, 0, 0, gcapstatus. uiimagewidth, gcapstatus. uiimageheight, swp_nozorder | swp_nomove );
If (nid = 0) {// clear the old status information
Setwindowtext (ghwndcap, (lpstr) "Hello ");
Return (lresult) true;
} // Display status ID and status text
Wsprintf (gachbuffer, "status # % d: % s", NID, lpstatustext );
Setwindowtext (ghwndcap, (lpstr) gachbuffer );
Return (lresult) true;
}
Lresult callback errorcallbackproc (hwnd, int nerrid, lpstr lperrortext)
{
If (! Ghwndcap) return false;
If (nerrid = 0) return true; // clear the old error
Wsprintf (gachbuffer, "Error # % d", nerrid); // display the error ID and text
MessageBox (hwnd, lperrortext, gachbuffer, mb_ OK | mb_iconexclamation );
Return (lresult) true;
}

Lresult callback framecallbackproc (hwnd, lpvideohdr lpvhdr)
{
File * FP;
Fp = fopen ("CARAM. dat", "W ");
If (! Ghwndcap) return false; // assume FP is an open. dat file pointer.
Fwrite (lpvhdr-> lpdata, 1, lpvhdr-> dwbufferlength, FP );
Return (lresult) true;
}

Int winapi winmain (hinstance, hinstance hprevinstance, pstr sz1_line, int icmdshow)
{
Static tchar szappname [] = text ("hellowin ");
Hwnd;
MSG;
Wndclass;
Wndclass. Style = cs_hredraw | cs_vredraw;
Wndclass. lpfnwndproc = wndproc;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hinstance = hinstance;
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. lpszmenuname = NULL;
Wndclass. lpszclassname = szappname;
If (! Registerclass (& wndclass ))
{
MessageBox (null, text ("this program requires WindowsNT! "), Szappname, mb_iconerror );
Return 0;
}
Hwnd = createwindow (szappname, text ("the hello program"), ws_overlappedwindow, cw_usedefault, null, null, hinstance, null );
Showwindow (hwnd, icmdshow );
Updatewindow (hwnd );
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return msg. wparam;
}

Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
HDC;
Paintstruct pS;
Rect;
Switch (Message)
{
Case wm_create:
{
Ghwndcap = capcreatecapturewindow (lpstr) "Capture window", ws_child | ws_visible, 300,240, (hwnd) hwnd, (INT) 0 );
Capsetcallbackonerror (ghwndcap, (farproc) errorcallbackproc );
Capsetcallbackonstatus (ghwndcap, (farproc) statuscallbackproc );
Capsetcallbackonframe (ghwndcap, (farproc) framecallbackproc );
Capdriverconnect (ghwndcap, 0); // connect the capture window to the drive
// Obtain the drive capability and put the relevant information in the Structure Variable gcapdrivercaps.
Capdrivergetcaps (ghwndcap, & gcapdrivercaps, sizeof (capdrivercaps ));
Cappreviewrate (ghwndcap, 66); // sets the display rate in preview mode.
Cappreview (ghwndcap, true); // start Preview mode
If (gcapdrivercaps. fhasoverlay) // check whether the drive has the overlay capability
Capoverlay (ghwndcap, true); // enable overlay Mode
If (gcapdrivercaps. fhasdlgvideosource) capdlgvideosource (ghwndcap); // video source dialog box
If (gcapdrivercaps. fhasdlgvideoformat) capdlgvideoformat (ghwndcap); // video format dialog box
If (gcapdrivercaps. fhasdlgvideodisplay) capdlgvideodisplay (ghwndcap); // video display dialog box
Capfilesetcapturefile (ghwndcap, szcapturefile); // specify the capture file name
Capfilealloc (ghwndcap, (1024l * 1024l * 5); // allocate storage space for captured files
Capcapturesequence (ghwndcap); // starts to capture the video sequence
Capgrabframe (ghwndcap); // capture a single-frame image

}

Return 0;
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Getclientrect (hwnd, & rect );
Drawtext (HDC, text ("Hello, Windows98! "),-1, & rect, dt_singleline | dt_center | dt_vcenter );
Endpaint (hwnd, & PS );
Return 0;
Case wm_destroy:
{
Capsetcallbackonstatus (ghwndcap, null );
Capsetcallbackonerror (ghwndcap, null );
Capsetcallbackonframe (ghwndcap, null );
Capcaptureabort (ghwndcap); // stop capture
Capdriverdisconnect (ghwndcap); // disconnect the capture window from the drive
Postquitmessage (0 );
}
Return 0;
}
Return defwindowproc (hwnd, message, wparam, lparam );
}

Http://blog.163.com/cshzxing@126/blog/static/37732930200711685722265/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.