如何捕捉针对&quot屏幕,工具提示"? [英] How to capture the screen with the "Tool Tips"?

查看:97
本文介绍了如何捕捉针对&quot屏幕,工具提示"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GDI捕捉屏幕,我已经注意到,工具提示中不包括的屏幕截图。这是我的基本code:

I am using GDI to capture the screen, and I have noticed that the "Tool Tips" are not included in the screenshot. This is my basic code:

HDC hdcDesk = GetDC(0);

HDC hdcMem = CreateCompatibleDC(hdcDesk);
HBITMAP hbmMem = CreateCompatibleBitmap(hdcDesk, 1920, 1080);
SelectObject(hdcMem, hbmMem);

StretchBlt(hdcMem, 0, 0, 1920, 1080, hdcDesk, 0, 0, 1920, 1080, SRCCOPY);

// Now save the bitmap...

这个问题能解决,或者我应该用另一种方法来捕捉屏幕(比GDI等)?

Can this be fixed, or should I use another approach to capture the screen (other than GDI)?

编辑:

这是我花了一个不显示工具提示的截图。

This is a screenshot that I took that does not display the Tool Tip.

推荐答案

更​​新:加入 CAPTUREBLT 作为由Alex K.,阿德里安·麦卡锡等人建议

Update: added CAPTUREBLT as suggested by Alex K., Adrian McCarthy et al.

我无法重现同样的问题。如果您在服用的桌面截图成功,然后一切都应该有!试试这个code来代替。注5秒的等待应该给时间手动激活工具提示。

I can't reproduce the same problem. If you succeed in taking screen shot of desktop then everything should be there! Try this code instead. Note the 5 second wait is supposed to give time to manually activate a tool tip.

#include "windows.h"

void capture(HWND hwnd, const wchar_t* filename)
{
    RECT rc;
    GetWindowRect(hwnd, &rc);
    int width = rc.right - rc.left;
    int height = rc.bottom - rc.top;
    if (width < 1 || height < 1)
        return;

    HDC hdc = GetDC(HWND_DESKTOP);
    HDC memdc = CreateCompatibleDC(hdc);
    HBITMAP bmp = CreateCompatibleBitmap(hdc, width, height);
    HGDIOBJ oldbitmap = SelectObject(memdc, bmp);
    BitBlt(memdc, 0, 0, width, height, hdc, rc.left, rc.top, CAPTUREBLT | SRCCOPY);
    SelectObject(memdc, oldbitmap);

    WORD bitCount = 32;
    DWORD size = ((width * bitCount + 31) / 32) * 4 * height;
    char *bits = new char[size];

    DWORD szFileHdr = sizeof(BITMAPFILEHEADER);
    DWORD szInfoHdr = sizeof(BITMAPINFOHEADER);

    BITMAPFILEHEADER bmpFileHeader = 
        { 'MB', szFileHdr + szInfoHdr + size, 0, 0, szFileHdr + szInfoHdr };

    BITMAPINFOHEADER bmpInfoHeader = 
        { szInfoHdr, width, height, 1, bitCount, BI_RGB, 0, 0, 0, 0, 0 };

    GetDIBits(hdc, bmp, 0, height, bits, (BITMAPINFO*)&bmpInfoHeader, DIB_RGB_COLORS);
    HANDLE hfile = CreateFileW(filename, 
        GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hfile != INVALID_HANDLE_VALUE)
    {
        DWORD temp;
        WriteFile(hfile, &bmpFileHeader, szFileHdr, &temp, NULL);
        WriteFile(hfile, &bmpInfoHeader, szInfoHdr, &temp, NULL);
        WriteFile(hfile, bits, size, &temp, NULL);
        CloseHandle(hfile);
    }

    DeleteObject(bmp);
    DeleteObject(memdc);
    ReleaseDC(HWND_DESKTOP, hdc);

    delete[]bits;

    ShellExecuteW(0, 0, filename, 0, 0, SW_SHOW);
}

int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
    Sleep(5000);
    capture(GetDesktopWindow(), "c:\\stuff\\test.bmp");
    return 0;
}

这篇关于如何捕捉针对&quot屏幕,工具提示&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆