| 169 | } |
| 170 | |
| 171 | QPixmap os::grabWindow(WId winId) |
| 172 | { |
| 173 | #ifdef Q_OS_WIN |
| 174 | RECT rcWindow; |
| 175 | |
| 176 | HWND hwndId = (HWND)winId; |
| 177 | |
| 178 | GetWindowRect(hwndId, &rcWindow); |
| 179 | |
| 180 | int margin = GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER) / 2; |
| 181 | |
| 182 | rcWindow.right -= margin; |
| 183 | rcWindow.left += margin; |
| 184 | |
| 185 | if (IsZoomed(hwndId)) { |
| 186 | rcWindow.top += margin; |
| 187 | } else { |
| 188 | rcWindow.top += GetSystemMetrics(SM_CXPADDEDBORDER); |
| 189 | } |
| 190 | |
| 191 | rcWindow.bottom -= margin; |
| 192 | |
| 193 | int width, height; |
| 194 | width = rcWindow.right - rcWindow.left; |
| 195 | height = rcWindow.bottom - rcWindow.top; |
| 196 | |
| 197 | RECT rcScreen; |
| 198 | GetWindowRect(GetDesktopWindow(), &rcScreen); |
| 199 | |
| 200 | RECT rcResult; |
| 201 | UnionRect(&rcResult, &rcWindow, &rcScreen); |
| 202 | |
| 203 | QPixmap pixmap; |
| 204 | |
| 205 | // Comparing the rects to determine if the window is outside the boundaries of the screen, |
| 206 | // the window DC method has the disadvantage that it does not show Aero glass transparency, |
| 207 | // so we'll avoid it for the screenshots that don't need it. |
| 208 | |
| 209 | HDC hdcMem; |
| 210 | HBITMAP hbmCapture; |
| 211 | |
| 212 | if (EqualRect(&rcScreen, &rcResult)) { |
| 213 | // Grabbing the window from the Screen DC. |
| 214 | HDC hdcScreen = GetDC(NULL); |
| 215 | |
| 216 | BringWindowToTop(hwndId); |
| 217 | |
| 218 | hdcMem = CreateCompatibleDC(hdcScreen); |
| 219 | hbmCapture = CreateCompatibleBitmap(hdcScreen, width, height); |
| 220 | SelectObject(hdcMem, hbmCapture); |
| 221 | |
| 222 | BitBlt(hdcMem, 0, 0, width, height, hdcScreen, rcWindow.left, rcWindow.top, SRCCOPY); |
| 223 | } else { |
| 224 | // Grabbing the window by its own DC |
| 225 | HDC hdcWindow = GetWindowDC(hwndId); |
| 226 | |
| 227 | hdcMem = CreateCompatibleDC(hdcWindow); |
| 228 | hbmCapture = CreateCompatibleBitmap(hdcWindow, width, height); |