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

后端 未结 2 2006
Happy的楠姐
Happy的楠姐 2020-12-15 16:31

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 = GetD         


        
2条回答
  •  被撕碎了的回忆
    2020-12-15 17:19

    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 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;
    }
    

提交回复
热议问题