我想实现截取屏幕的一个小区域,各位请指教一下,不胜感激

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc/?id=181
      

  2.   

    我想截取屏幕中的指定区域,同时显示出来,各位有什么好的方法,最好用api实现
      

  3.   

    HDC m_hMemDC;
    HBITMAP m_hMemBmp, m_hOldBmp;
    //申明一个类成员变量或者全局变量void Capture()
    {
    HDC hScreenDC = ::CreateDC("DISPLAY", NULL, NULL, NULL);
    // 获得屏幕DC
    m_hMemDC = ::CreateCompatibleDC(hScreenDC);
    // 创建兼容DC
    m_hMemBmp = CreateCompatibleBitmap(hScreenDC, 1024, 768);
    // 创建兼容位图
    m_hOldBmp = ::SelectObject(m_hMemDC , m_hMemBmp);
    // 选入兼容DC
    BitBlt(m_hMemDC , 0, 0, 1024, 768, hScreenDC, 0, 0, SRCCOPY);
    // 把桌面截图保存到兼容DC中,上面的数字就是设定要复制的区域的
    }再显示出来就用:
    ::BitBlt(hDC, 0, 0, 1024, 768, m_hMemDC, 0, 0, SRCCOPY);
    // hDC是窗口的DC句柄,自己设定要显示的区域。最后,别忘了DeleteDC。
      

  4.   

    汗~~我自己的代码中都忘了DeleteDC~~
      

  5.   

    HBITMAP WCDc::CopyDCToBitmap(HDC hScrDC, LPRECT lpRect)
    { HDC        hMemDC;      
    // 屏幕和内存设备描述表
    HBITMAP    hBitmap,hOldBitmap;   
    // 位图句柄
    int       nX, nY, nX2, nY2;      
    // 选定区域坐标
    int       nWidth, nHeight;      
    // 位图宽度和高度 // 确保选定区域不为空矩形
    if (IsRectEmpty(lpRect))
    return NULL;

    //为屏幕创建设备描述表
    // hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
    // 获得选定区域坐标
    nX = lpRect->left;
    nY = lpRect->top;
    nX2 = lpRect->right;
    nY2 = lpRect->bottom;
    // 获得屏幕分辨率
    //xScrn = GetDeviceCaps(hScrDC, HORZRES);
    //yScrn = GetDeviceCaps(hScrDC, VERTRES);
    // CGraphDoc* pDoc = m_hWnd->GetDocument();
    // ASSERT_VALID(pDoc); //CRect rcClient;
    //GetClientRect(m_hWnd,&rcClient);

    //xScrn = (rcClient.right - rcClient.left);//pDoc->BoardWidth/10;
    //yScrn=(rcClient.bottom - rcClient.top);//pDoc->BoardHeight/10;//否则图形显示不全
    /*
      //确保选定区域是可见的
    if (nX < 0)
    nX = 0;
    if (nY < 0)
    nY = 0;
    if (nX2 > xScrn)
    nX2 = xScrn;
    if (nY2 > yScrn)
    nY2 = yScrn;
    */
    nWidth = nX2 - nX;
    nHeight = nY2 - nY;
    //为屏幕设备描述表创建兼容的内存设备描述表
    hMemDC = CreateCompatibleDC(hScrDC);
    // 创建一个与屏幕设备描述表兼容的位图
    hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
    // 把新位图选到内存设备描述表中
    hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
    // 把屏幕设备描述表拷贝到内存设备描述表中
    StretchBlt(hMemDC,0,0,nWidth,nHeight,hScrDC,nX,nY,nWidth,nHeight,SRCCOPY);
    //BitBlt(hMemDC, 0, 0, nWidth, nHeight,hScrDC, nX, nY, SRCCOPY);
    //得到屏幕位图的句柄  hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
    //清除 

    // DeleteDC(hScrDC);
    DeleteDC(hMemDC);
    DeleteObject(hOldBitmap);
    // 返回位图句柄
    return hBitmap;
    }
      

  6.   

    我现在利用Timer每隔100ms截一次屏,这样可以达到实时截屏的效果,但是,十分占用系统资源,不知各位有什么好的方法,可以避免呢