1#include "DisplayWindows.h"
3#include <QLoggingCategory>
5Q_DECLARE_LOGGING_CATEGORY(logDW)
6CDisplayWindows::CDisplayWindows(QObject *parent) :
CDesktop(parent)
11 m_Width = m_Height = 0;
14CDisplayWindows::~CDisplayWindows()
16 DeleteObject(m_Bitmap);
18 ReleaseDC(NULL, m_DC);
28HDC CDisplayWindows::GetDesktopDC()
31 m_DC = GetDC(GetDesktopWindow());
35int CDisplayWindows::Width()
37 return GetDeviceCaps(m_DC, HORZRES);
40int CDisplayWindows::Height()
42 return GetDeviceCaps(m_DC, VERTRES);
45QImage CDisplayWindows::GetDisplay(
int width,
int height,
int x,
int y)
59 if(width != m_Width || height != m_Height
60 || NULL == m_MemDc || NULL == m_Bitmap)
65 if(-1 == width) m_Width = Width();
66 if(-1 == height) m_Height = Height();
71 DeleteObject(m_Bitmap);
74 m_MemDc = CreateCompatibleDC(m_DC);
78 "CreateCompatibleDC fail: %d",
83 m_Bitmap = CreateCompatibleBitmap(m_DC, m_Width, m_Height);
87 "CreateCompatibleBitmap fail: %d",
91 HGDIOBJ oldBitmap = SelectObject(m_MemDc, m_Bitmap);
95 "SelectObject fail: %d",
100 if(!BitBlt(m_MemDc, 0, 0, m_Width, m_Height, m_DC, x, y, SRCCOPY))
112 memset(&bi, 0,
sizeof(bi));
113 bi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
114 bi.bmiHeader.biBitCount = 0;
116 bi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
117 bi.bmiHeader.biWidth = m_Width;
118 bi.bmiHeader.biHeight = m_Height;
119 bi.bmiHeader.biPlanes = 1;
120 bi.bmiHeader.biBitCount = 32;
121 bi.bmiHeader.biCompression = BI_RGB;
122 bi.bmiHeader.biSizeImage = 0;
123 bi.bmiHeader.biXPelsPerMeter = 0;
124 bi.bmiHeader.biYPelsPerMeter = 0;
125 bi.bmiHeader.biClrUsed = 0;
126 bi.bmiHeader.biClrImportant = 0;
128 img = QImage(m_Width, m_Height, QImage::Format_ARGB32);
131 if (!::GetDIBits(m_MemDc, m_Bitmap, 0, m_Height,
132 img.bits(), (BITMAPINFO*)&bi, DIB_RGB_COLORS))
135 "Get image fail: %d",
140 img = img.mirrored();
143 DeleteObject(m_Bitmap);