How to capture the screen with the “Tool Tips”?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 02:53:31

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

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 3 second wait is supposed to give time to manually activate a tool tip.

int main()
{
    Sleep(3000);
    TCHAR* filename = TEXT("c:\\test\\_bmp.bmp");
    int width = GetSystemMetrics(SM_CXFULLSCREEN); 
    int height = GetSystemMetrics(SM_CYFULLSCREEN); 

    HDC hdc = GetDC(HWND_DESKTOP);
    HBITMAP hbitmap = CreateCompatibleBitmap(hdc, width, height);
    HDC memdc = CreateCompatibleDC(hdc);
    HGDIOBJ oldbmp = SelectObject(memdc, hbitmap);
    BitBlt(memdc, 0, 0, width, height, hdc, 0, 0, CAPTUREBLT | SRCCOPY);

    WORD bpp = 24; //24-bit bitmap
    DWORD size = ((width * bpp + 31) / 32) * 4 * height;
    BITMAPFILEHEADER filehdr = { 'MB', 54 + size, 0, 0, 54 };
    BITMAPINFOHEADER infohdr = { 40, width, height, 1, bpp };

    std::vector<BYTE> bits(size);
    GetDIBits(hdc, hbitmap, 0, height, &bits[0], (BITMAPINFO*)&infohdr, DIB_RGB_COLORS);

    std::ofstream f(filename, std::ios::binary);
    f.write((char*)&filehdr, sizeof(filehdr));
    f.write((char*)&infohdr, sizeof(infohdr));
    f.write((char*)bits.data(), size);

    SelectObject(memdc, oldbmp);
    DeleteObject(memdc);
    DeleteObject(hbitmap);
    ReleaseDC(HWND_DESKTOP, hdc);
    ShellExecute(0, 0, filename, 0, 0, SW_SHOW);

    return 0;
}
FastAl

I had the exact problem a few years ago with a windows XP system. The code in the answer to my question solved the problem:

Capture screenshot Including Semitransparent windows in .NET

For you, you should be able to just change your stretchblt line to bitblt and add captureblt:

HDC hdcDesk = GetDC(0);

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

BitBlt(hdcMem, 0, 0, 1920, 1080, hdcDesk, 0, 0, SRCCOPY | CAPTUREBLT);

// Now save the bitmap...

Tooltips, like transparent windows, are skipped by spec of bitblt. Plus, you're not resizing, so use bitblt. If that doesn't work, there might be something else wrong with what you are doing as the other commenters hint, so you can convert the answer to my question from C# to C, that did work for me on XP. (of course I don't have XP any more to test but that was definitely the issue).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!