Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/ui/window_snapshot/window_snapshot_win.cc

Issue 6386009: Remove app/win/win_util.h,cc etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code cleanup Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
6
7 #include "base/win/scoped_gdi_object.h"
8 #include "base/win/scoped_hdc.h"
9 #include "gfx/codec/png_codec.h"
10 #include "gfx/gdi_util.h"
11
12 namespace browser {
13
14 void GrabWindowSnapshot(gfx::NativeWindow window_handle,
15 std::vector<unsigned char>* png_representation) {
16 // Create a memory DC that's compatible with the window.
17 HDC window_hdc = GetWindowDC(window_handle);
18 base::win::ScopedHDC mem_hdc(CreateCompatibleDC(window_hdc));
19
20 // Create a DIB that's the same size as the window.
21 RECT content_rect = {0, 0, 0, 0};
22 ::GetWindowRect(window_handle, &content_rect);
23 content_rect.right++; // Match what PrintWindow wants.
24 int width = content_rect.right - content_rect.left;
25 int height = content_rect.bottom - content_rect.top;
26 BITMAPINFOHEADER hdr;
27 gfx::CreateBitmapHeader(width, height, &hdr);
28 unsigned char *bit_ptr = NULL;
29 base::win::ScopedBitmap bitmap(
30 CreateDIBSection(mem_hdc,
31 reinterpret_cast<BITMAPINFO*>(&hdr),
32 DIB_RGB_COLORS,
33 reinterpret_cast<void **>(&bit_ptr),
34 NULL, 0));
35
36 SelectObject(mem_hdc, bitmap);
37 // Clear the bitmap to white (so that rounded corners on windows
38 // show up on a white background, and strangely-shaped windows
39 // look reasonable). Not capturing an alpha mask saves a
40 // bit of space.
41 PatBlt(mem_hdc, 0, 0, width, height, WHITENESS);
42 // Grab a copy of the window
43 // First, see if PrintWindow is defined (it's not in Windows 2000).
44 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT);
45 PrintWindowPointer print_window =
46 reinterpret_cast<PrintWindowPointer>(
47 GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow"));
48
49 // If PrintWindow is defined, use it. It will work on partially
50 // obscured windows, and works better for out of process sub-windows.
51 // Otherwise grab the bits we can get with BitBlt; it's better
52 // than nothing and will work fine in the average case (window is
53 // completely on screen).
54 if (print_window)
55 (*print_window)(window_handle, mem_hdc, 0);
56 else
57 BitBlt(mem_hdc, 0, 0, width, height, window_hdc, 0, 0, SRCCOPY);
58
59 // We now have a copy of the window contents in a DIB, so
60 // encode it into a useful format for posting to the bug report
61 // server.
62 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA,
63 width, height, width * 4, true,
64 png_representation);
65
66 ReleaseDC(window_handle, window_hdc);
67 }
68
69 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698