我想编写一个程序,可以动态截取屏幕,不知在VC++该如何实现?

解决方案 »

  1.   

    CDC   dc;   
    dc.CreateDC("DISPLAY",NULL,NULL,NULL);   

    char filename[128];
    memset(filename,0,sizeof(filename));

    int   nX = 0;
    int   nY = 0;
    int   Width=GetSystemMetrics(SM_CXSCREEN);   
    int   Height=GetSystemMetrics(SM_CYSCREEN);  

    CBitmap   bm;  
    bm.CreateCompatibleBitmap(&dc,Width,Height);   
    CDC   tdc;   
    tdc.CreateCompatibleDC(&dc);   
    CBitmap *pOld=tdc.SelectObject(&bm);   
    tdc.BitBlt(0,0,Width,Height,&dc,nX,nY,SRCCOPY);  
    tdc.SelectObject(pOld);    

    BITMAP   btm;   
    bm.GetBitmap(&btm);   
    DWORD   size=btm.bmWidthBytes*btm.bmHeight;   
    LPSTR   lpData=(LPSTR)GlobalAlloc(GPTR,size);   

    BITMAPINFOHEADER   bih;   
    bih.biBitCount=btm.bmBitsPixel;   
    bih.biClrImportant=0;   
    bih.biClrUsed=0;   
    bih.biCompression=0;   
    bih.biHeight=btm.bmHeight;   
    bih.biPlanes=1;   
    bih.biSize=sizeof(BITMAPINFOHEADER);   
    bih.biSizeImage=size;   
    bih.biWidth=btm.bmWidth;   
    bih.biXPelsPerMeter=0;   
    bih.biYPelsPerMeter=0;   

    GetDIBits(tdc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);  
    BITMAPFILEHEADER   bfh;   
    bfh.bfReserved1=bfh.bfReserved2=0;   
    bfh.bfType=((WORD)('M'<<   8)|'B');   
    bfh.bfSize=54+size;   
    bfh.bfOffBits=54;  
    bm.DeleteObject();
    tdc.DeleteDC();
    dc.DeleteDC();
    CFile   bf;   
    if(bf.Open(csFolder,CFile::modeCreate|CFile::modeWrite)){   
    bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));   
    bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));   
    bf.WriteHuge(lpData,size);   
    bf.Close();   
    }   
    else   
    return   ;   

    GlobalFree(lpData);    

    return  ;
      

  2.   

    在%DDKROOT%\src\video\displays\mirror下面。
      

  3.   

    When video mirroring is active, each time the system draws to the primary video device at a location inside the mirrored area, a copy of the draw operation is executed on the mirrored video device in real time. With this mirroring scheme, you can simultaneously draw the same output to several video devices.