| 
 | 
[VC++] [经验][菜鸟的初级阶段]一个巨简单的视频程序 
| 不用qq,自己写代码,就能使用摄相头录一录你的帅脸,怎么样?想不想试?下面提供一个巨简单的方法,只要了解一点vc的人(像我的水平)就能掌握: 1,创建一个基于对话框的程序。(具体步骤我不用说了吧?)
 2,在对话框上画一个“picture”框,最好能画得大一点,id就不用变了。
 3,在菜单栏中点击“工程->设置”,出现一个对话框,在对话框的选项卡“link"中有一项是“对象/库模块”(反正e文不好,照着中文版的直说了),在该文本框中填入“vfw32.lib",不要引号。
 4,在对话框的cpp文件中,开头部分的几条“include"后面再加一条:#include "vfw.h"。
 5,定义一个全局变量:hwnd hwndc;最好写在一堆“#......”的后面一点。
 6,在对话框的初始化函数中写入几条代码,如下:
 bool cmy2dlg:
  ninitdialog() {
 cdialog:
  ninitdialog(); 
 // add "about..." menu item to system menu.
 
 // idm_aboutbox must be in the system command range.
 assert((idm_aboutbox & 0xfff0) == idm_aboutbox);
 assert(idm_aboutbox < 0xf000);
 
 cmenu* psysmenu = getsystemmenu(false);
 if (psysmenu != null)
 {
 cstring straboutmenu;
 straboutmenu.loadstring(ids_aboutbox);
 if (!straboutmenu.isempty())
 {
 psysmenu->appendmenu(mf_separator);
 psysmenu->appendmenu(mf_string, idm_aboutbox, straboutmenu);
 }
 }
 
 // set the icon for this dialog.  the framework does this automatically
 //  when the application's main window is not a dialog
 seticon(m_hicon, true);                        // set big icon
 seticon(m_hicon, false);                // set small icon
 
 // todo: add extra initialization here
 //下面就是要加的代码:
 hwndc=capcreatecapturewindow ( "my own capture window",
 ws_child | ws_visible , 2, 26, 602, 426, getdlgitem(idc_static)->getsafehwnd(), 0);
 capdriverconnect(hwndc,0);
 cappreview(hwndc, true);
 //以上是要加的代码
 return true;  // return true  unless you set the focus to a control
 }
 7,别急,最后一步,在对话框的“onpaint"函数中加入一条,如下:
 void cmy2dlg:
  npaint() {
 if (isiconic())
 {
 cpaintdc dc(this); // device context for painting
 
 sendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);
 
 // center icon in client rectangle
 int cxicon = getsystemmetrics(sm_cxicon);
 int cyicon = getsystemmetrics(sm_cyicon);
 crect rect;
 getclientrect(&rect);
 int x = (rect.width() - cxicon + 1) / 2;
 int y = (rect.height() - cyicon + 1) / 2;
 
 // draw the icon
 dc.drawicon(x, y, m_hicon);
 }
 else
 {
 cdialog:
  npaint(); }
 capcapturesequencenofile(hwndc);//在这里,就这一句,这是不录到文件的情况,只是在界面上看看自己的尊容而已。
 //如果要录到文件中就要用这条:capcapturesequence(hwndc);默认录到c盘根目录下,你找一找,一个很大的avi文件,就是它!
 }
 ok!完成!把摄相头插上,启动程序,你的超级大帅脸就呈现在屏幕上了!
 | 
 |