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

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

Issue 10696185: Use GenericScopedHandle to implement ScopedCreateDC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_WIN_SCOPED_HDC_H_ 5 #ifndef BASE_WIN_SCOPED_HDC_H_
6 #define BASE_WIN_SCOPED_HDC_H_ 6 #define BASE_WIN_SCOPED_HDC_H_
7 #pragma once 7 #pragma once
8 8
9 #include <windows.h> 9 #include <windows.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/win/scoped_handle.h"
13 14
14 namespace base { 15 namespace base {
15 namespace win { 16 namespace win {
16 17
17 // Like ScopedHandle but for HDC. Only use this on HDCs returned from 18 // Like ScopedHandle but for HDC. Only use this on HDCs returned from
18 // GetDC. 19 // GetDC.
19 class ScopedGetDC { 20 class ScopedGetDC {
20 public: 21 public:
21 explicit ScopedGetDC(HWND hwnd) 22 explicit ScopedGetDC(HWND hwnd)
22 : hwnd_(hwnd), 23 : hwnd_(hwnd),
(...skipping 18 matching lines...) Expand all
41 42
42 private: 43 private:
43 HWND hwnd_; 44 HWND hwnd_;
44 HDC hdc_; 45 HDC hdc_;
45 46
46 DISALLOW_COPY_AND_ASSIGN(ScopedGetDC); 47 DISALLOW_COPY_AND_ASSIGN(ScopedGetDC);
47 }; 48 };
48 49
49 // Like ScopedHandle but for HDC. Only use this on HDCs returned from 50 // Like ScopedHandle but for HDC. Only use this on HDCs returned from
50 // CreateCompatibleDC, CreateDC and CreateIC. 51 // CreateCompatibleDC, CreateDC and CreateIC.
51 class ScopedCreateDC { 52 class CreateDCTraits {
52 public: 53 public:
53 ScopedCreateDC() : hdc_(NULL) { } 54 typedef HDC Handle;
54 explicit ScopedCreateDC(HDC h) : hdc_(h) { }
55 55
56 ~ScopedCreateDC() { 56 static bool CloseHandle(HDC handle) {
57 Close(); 57 return ::DeleteDC(handle) != FALSE;
58 } 58 }
59 59
60 HDC Get() { 60 static bool IsHandleValid(HDC handle) {
61 return hdc_; 61 return handle != NULL;
62 } 62 }
63 63
64 void Set(HDC h) { 64 static HDC NullHandle() {
65 Close(); 65 return NULL;
66 hdc_ = h;
67 } 66 }
68 67
69 operator HDC() { return hdc_; } 68 private:
69 DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits);
70 };
70 71
71 private: 72 typedef GenericScopedHandle<CreateDCTraits, VerifierTraits> ScopedCreateDC;
72 void Close() {
73 #ifdef NOGDI
alexeypa (please no reviews) 2012/07/12 18:18:00 This code was wrong BTW. When NOGDI is defined Del
74 assert(false);
75 #else
76 if (hdc_)
77 DeleteDC(hdc_);
78 #endif // NOGDI
79 }
80
81 HDC hdc_;
82
83 DISALLOW_COPY_AND_ASSIGN(ScopedCreateDC);
84 };
85 73
86 } // namespace win 74 } // namespace win
87 } // namespace base 75 } // namespace base
88 76
89 #endif // BASE_WIN_SCOPED_HDC_H_ 77 #endif // BASE_WIN_SCOPED_HDC_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698