7 imss_win32(unsigned hwnd_u, int include_decor, int left, int top,
8 int right, int bottom) {
9 HWND hwnd = (HWND)hwnd_u;
12 HBITMAP work_bmp, old_dc_bmp;
13 int window_width, window_height;
15 unsigned char *di_bits;
22 hwnd = GetDesktopWindow();
25 wdc = GetWindowDC(hwnd);
26 GetWindowRect(hwnd, &rect);
30 GetClientRect(hwnd, &rect);
33 i_push_error(0, "Cannot get window DC - invalid hwnd?");
37 window_width = rect.right - rect.left;
38 window_height = rect.bottom - rect.top;
40 /* adjust negative/zero values to window size */
46 right += window_width;
48 bottom += window_height;
53 if (right > window_width)
57 if (bottom > window_height)
58 bottom = window_height;
61 if (right <= left || bottom <= top) {
62 i_push_error(0, "image would be empty");
66 height = bottom - top;
68 work_bmp = CreateCompatibleBitmap(wdc, width, height);
69 bmdc = CreateCompatibleDC(wdc);
70 old_dc_bmp = SelectObject(bmdc, work_bmp);
71 BitBlt(bmdc, 0, 0, width, height, wdc, left, top, SRCCOPY);
74 memset(&bmi, 0, sizeof(bmi));
75 bmi.bmiHeader.biSize = sizeof(bmi);
76 bmi.bmiHeader.biWidth = width;
77 bmi.bmiHeader.biHeight = -height;
78 bmi.bmiHeader.biPlanes = 1;
79 bmi.bmiHeader.biBitCount = 32;
80 bmi.bmiHeader.biCompression = BI_RGB;
82 di_bits = mymalloc(4 * width * height);
83 if (GetDIBits(bmdc, work_bmp, 0, height, di_bits, &bmi, DIB_RGB_COLORS)) {
84 i_color *line = mymalloc(sizeof(i_color) * width);
87 unsigned char *ch_pp = di_bits;
88 result = i_img_8_new(width, height, 3);
90 for (y = 0; y < height; ++y) {
92 for (x = 0; x < width; ++x) {
99 i_plin(result, 0, width, y, line);
104 i_tags_setn(&result->tags, "ss_window_width", window_width);
105 i_tags_setn(&result->tags, "ss_window_height", window_height);
106 i_tags_set(&result->tags, "ss_type", "Win32", 5);
107 i_tags_setn(&result->tags, "ss_left", left);
108 i_tags_setn(&result->tags, "ss_top", top);
112 SelectObject(bmdc, old_dc_bmp);
114 DeleteObject(work_bmp);
115 ReleaseDC(hwnd, wdc);