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

Side by Side Diff: base/win/scoped_hdc.h

Issue 1446363003: Deleted OS_WIN and all Windows specific files from base. (Closed) Base URL: https://github.com/domokit/mojo.git@base_tests
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « base/win/scoped_handle.cc ('k') | base/win/scoped_hglobal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #ifndef BASE_WIN_SCOPED_HDC_H_
6 #define BASE_WIN_SCOPED_HDC_H_
7
8 #include <windows.h>
9
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/win/scoped_handle.h"
13
14 namespace base {
15 namespace win {
16
17 // Like ScopedHandle but for HDC. Only use this on HDCs returned from
18 // GetDC.
19 class ScopedGetDC {
20 public:
21 explicit ScopedGetDC(HWND hwnd)
22 : hwnd_(hwnd),
23 hdc_(GetDC(hwnd)) {
24 if (hwnd_) {
25 DCHECK(IsWindow(hwnd_));
26 DCHECK(hdc_);
27 } else {
28 // If GetDC(NULL) returns NULL, something really bad has happened, like
29 // GDI handle exhaustion. In this case Chrome is going to behave badly no
30 // matter what, so we may as well just force a crash now.
31 CHECK(hdc_);
32 }
33 }
34
35 ~ScopedGetDC() {
36 if (hdc_)
37 ReleaseDC(hwnd_, hdc_);
38 }
39
40 operator HDC() { return hdc_; }
41
42 private:
43 HWND hwnd_;
44 HDC hdc_;
45
46 DISALLOW_COPY_AND_ASSIGN(ScopedGetDC);
47 };
48
49 // Like ScopedHandle but for HDC. Only use this on HDCs returned from
50 // CreateCompatibleDC, CreateDC and CreateIC.
51 class CreateDCTraits {
52 public:
53 typedef HDC Handle;
54
55 static bool CloseHandle(HDC handle) {
56 return ::DeleteDC(handle) != FALSE;
57 }
58
59 static bool IsHandleValid(HDC handle) {
60 return handle != NULL;
61 }
62
63 static HDC NullHandle() {
64 return NULL;
65 }
66
67 private:
68 DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits);
69 };
70
71 typedef GenericScopedHandle<CreateDCTraits, DummyVerifierTraits> ScopedCreateDC;
72
73 } // namespace win
74 } // namespace base
75
76 #endif // BASE_WIN_SCOPED_HDC_H_
OLDNEW
« no previous file with comments | « base/win/scoped_handle.cc ('k') | base/win/scoped_hglobal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698