为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Windows应用程序中截屏?

如何在Windows应用程序中截屏?

C++
森栏 2019-09-21 15:22:27
如何使用Win32截屏当前屏幕?
查看完整描述

3 回答

?
墨色风雨

TA贡献1853条经验 获得超6个赞

// get the device context of the screen

HDC hScreenDC = CreateDC("DISPLAY", NULL, NULL, NULL);     

// and a device context to put it in

HDC hMemoryDC = CreateCompatibleDC(hScreenDC);


int width = GetDeviceCaps(hScreenDC, HORZRES);

int height = GetDeviceCaps(hScreenDC, VERTRES);


// maybe worth checking these are positive values

HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, width, height);


// get a new bitmap

HBITMAP hOldBitmap = (HBITMAP) SelectObject(hMemoryDC, hBitmap);


BitBlt(hMemoryDC, 0, 0, width, height, hScreenDC, 0, 0, SRCCOPY);

hBitmap = (HBITMAP) SelectObject(hMemoryDC, hOldBitmap);


// clean up

DeleteDC(hMemoryDC);

DeleteDC(hScreenDC);


// now your image is held in hBitmap. You can save it or do whatever with it


查看完整回答
反对 回复 2019-09-21
?
万千封印

TA贡献1891条经验 获得超3个赞

void GetScreenShot(void)

{

    int x1, y1, x2, y2, w, h;


    // get screen dimensions

    x1  = GetSystemMetrics(SM_XVIRTUALSCREEN);

    y1  = GetSystemMetrics(SM_YVIRTUALSCREEN);

    x2  = GetSystemMetrics(SM_CXVIRTUALSCREEN);

    y2  = GetSystemMetrics(SM_CYVIRTUALSCREEN);

    w   = x2 - x1;

    h   = y2 - y1;


    // copy screen to bitmap

    HDC     hScreen = GetDC(NULL);

    HDC     hDC     = CreateCompatibleDC(hScreen);

    HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, w, h);

    HGDIOBJ old_obj = SelectObject(hDC, hBitmap);

    BOOL    bRet    = BitBlt(hDC, 0, 0, w, h, hScreen, x1, y1, SRCCOPY);


    // save bitmap to clipboard

    OpenClipboard(NULL);

    EmptyClipboard();

    SetClipboardData(CF_BITMAP, hBitmap);

    CloseClipboard();   


    // clean up

    SelectObject(hDC, old_obj);

    DeleteDC(hDC);

    ReleaseDC(NULL, hScreen);

    DeleteObject(hBitmap);

}


查看完整回答
反对 回复 2019-09-21
  • 3 回答
  • 0 关注
  • 505 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信