一个看来的抓图程序!!!

类别:VC语言 点击:0 评论:0 推荐:

/////////////////////////////////////////////////////////////////////////////
// CAvitobmpDlg message handlers

BOOL CAvitobmpDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // 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
   
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CAvitobmpDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAvitobmpDlg::OnPaint()
{
    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::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAvitobmpDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CAvitobmpDlg::OnButtonok()
{
if(m_avifile==""||m_target=="")  //note fill in data first.
{
       MessageBox("PLS SELECT FILE OR FILL IN DATA FIRST!","NOTE",MB_ICONSTOP);
return;
}
      AfxGetApp()->DoWaitCursor(1);
      GetDlgItem(IDC_BUTTONOK)->EnableWindow(false);
       PAVIFILE  pfile;//Pointer  to  a  buffer  that  receives  the  new  IAVIFile  interface  pointer.                                     
           AVIFILEINFO    pfi;                         
           PAVISTREAM    pavi;                                                 
           PGETFRAME  pgf;                                                                                     
           long  length,  start; 

           //initializes  the  AVIFile  library,as AVIFileExit()。 
           //Call  AVIFileInit()  before  using  any  other  AVIFile  functions             
           AVIFileInit(); 
           AVIFileOpen(&pfile,m_avifile,OF_READ  |OF_SHARE_DENY_NONE,NULL); 
            
           //obtains  information  about  an  AVI  file 
           AVIFileInfo(pfile,&pfi,sizeof(AVIFILEINFO)); 
           AVIFileGetStream(pfile,&pavi,streamtypeVIDEO,0); 
           length=AVIStreamLength(pavi); 
           start=AVIStreamStart(pavi); 

           AVISTREAMINFO  si; 
           AVIStreamInfo(pavi,  &si,  sizeof(si)); 

           pgf  =  AVIStreamGetFrameOpen(pavi,  NULL); 
           //GET FIRST BMP
           LPBITMAPINFOHEADER  bmp1; 
           bmp1=  (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf,  1); 
           CClientDC  dc(this); 
         
           //DEFAUT HEAD
           BITMAPINFOHEADER  bmih; 
           memset(&bmih,0,sizeof(BITMAPINFOHEADER)); 
           bmih.biBitCount=bmp1->biBitCount; 
           bmih.biSize  =  sizeof(BITMAPINFOHEADER); 
         
          bmih.biWidth  =  pfi.dwWidth; 
          bmih.biHeight  =  pfi.dwHeight; 
          bmih.biPlanes  =bmp1->biPlanes;  //Modif By Deng Chun Ling
         
           bmih.biCompression  =BI_RGB; 
           bmih.biXPelsPerMeter  =  0; 
           bmih.biYPelsPerMeter  =  0; 
          
           BITMAPFILEHEADER  bmfh; 
       bmfh.bfSize  =  sizeof(bmfh); 
         //bmfh.bfSize=sizeof(bmp1);  //modi by deng chun ling  
       bmfh.bfOffBits  =  sizeof(bmfh)  +  sizeof(bmih); //BITMAPINFOHEADER+BITMAPINFOHEADER
       bmfh.bfType  =  (int)'M'  *  256  +  'B'; 
      // bmfh.bfType=0x424D;
       bmfh.bfReserved1  =  0; 
       bmfh.bfReserved2  =  0; 

           BYTE  *lpbuffa; 
          
           lpbuffa=new BYTE[(((pfi.dwWidth*bmih.biBitCount)+31)/8)*pfi.dwHeight];
   

           BYTE*  lpbuff;

 

   m_editqty=pfi.dwLength;
   UpdateData(false);
//Limite to 100 
//            if  (pfi.dwLength>100) pfi.dwLength=100;
            
                   
           for(LONG  i=1;i<(LONG)pfi.dwLength;i++) 
           { 
                       lpbuff=lpbuffa; 
                       lpbuff=(BYTE  *)AVIStreamGetFrame(pgf,i);// 
                       lpbuff+=40; 
                       //TranslationDIB1(lpbuff,bmih.biWidth,bmih.biHeight,10,50);//平移function 
                       char  name1[100]; 
                       strcpy(name1,m_target);//目的路徑 

                                         
                       TCHAR  name3[50]; 
                       wsprintf(name3, TEXT("Bitmap%5.5ld.bmp\0"),  long(i) ); 
                       strcat(name1,name3);
                     
                                           
                       ////Write BMP File。 
                      CFile  ff(name1,  CFile::modeWrite    |  CFile::modeCreate);  //?位? 
                      ff.Write(&bmfh,  sizeof(bmfh));//bmfh-->ff 
                      ff.Write(&bmih,  40); 
                     ff.Write(lpbuff, bmp1->biSizeImage); 
                        ff.Close(); 
                                  
                      Sleep(10);             
           } 
           
         

                       m_editw=i;
                       UpdateData(false);

       //release file
       AVIStreamGetFrameClose(pgf); 
        AVIFileRelease(pfile); 
            
           //Use  the  AVIFileExit()  function  to  release  the  AVIFile  library   
           //and  decrement  the  reference  count.同AVIFileInit()??。 
           AVIFileExit(); 
           ReleaseDC(&dc);
         AfxGetApp()->DoWaitCursor(1);
MessageBox("CONVERT COMPLETED!","NOTE",MB_ICONINFORMATION);
GetDlgItem(IDC_BUTTONOK)->EnableWindow(true);         

   


void CAvitobmpDlg::OnButtonabout()
{
CAboutDlg dlg;
dlg.DoModal ();   
}

void CAvitobmpDlg::OnButtonsource()
{

CFileDialog  FileDlg(TRUE,  "*.AVI",  NULL,   
                       OFN_HIDEREADONLY    |  OFN_OVERWRITEPROMPT,   
                       _T("AVI FILE(*.avi) |*.avi||")); 
         //  CString  m_avifile; 
           if(FileDlg.DoModal()  ==  IDOK){ 
          
           m_avifile=FileDlg.GetPathName(); 
           UpdateData(false);
           }
   
}

void CAvitobmpDlg::OnButtontarget()
{
CFileDialog filedlg(FALSE,NULL,"P",NULL,("BMP File(*.bmp)|*.bmp||"));
if (filedlg.DoModal()==IDOK){

//m_target=filedlg.GetFolderPath();
m_target=filedlg.GetPathName();
m_target.MakeUpper();
UpdateData(false);

}
}

本文地址:http://com.8s8s.com/it/it435.htm