Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
Mark Mentovai
2011/10/06 03:52:25
The issue description becomes part of the check-in
| |
| 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" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 28 ~ScopedGetDC() { | 28 ~ScopedGetDC() { |
| 29 if (hdc_) | 29 if (hdc_) |
| 30 ReleaseDC(hwnd_, hdc_); | 30 ReleaseDC(hwnd_, hdc_); |
| 31 } | 31 } |
| 32 | 32 |
| 33 operator HDC() { return hdc_; } | 33 operator HDC() { return hdc_; } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 HWND hwnd_; | 36 HWND hwnd_; |
| 37 HDC hdc_; | 37 HDC hdc_; |
| 38 | |
| 38 DISALLOW_COPY_AND_ASSIGN(ScopedGetDC); | 39 DISALLOW_COPY_AND_ASSIGN(ScopedGetDC); |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 // Like ScopedHandle but for HDC. Only use this on HDCs returned from | 42 // Like ScopedHandle but for HDC. Only use this on HDCs returned from |
| 42 // CreateCompatibleDC. | 43 // CreateCompatibleDC, CreateDC and CreateIC. |
| 43 // TODO(yosin) To eliminate confusion with ScopedGetDC, we should rename | 44 class ScopedCreateDC { |
| 44 // ScopedHDC to ScopedCreateDC. | |
| 45 class ScopedHDC { | |
| 46 public: | 45 public: |
| 47 ScopedHDC() : hdc_(NULL) { } | 46 ScopedCreateDC() : hdc_(NULL) { } |
| 48 explicit ScopedHDC(HDC h) : hdc_(h) { } | 47 explicit ScopedCreateDC(HDC h) : hdc_(h) { } |
| 49 | 48 |
| 50 ~ScopedHDC() { | 49 ~ScopedCreateDC() { |
| 51 Close(); | 50 Close(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 HDC Get() { | 53 HDC Get() { |
| 55 return hdc_; | 54 return hdc_; |
| 56 } | 55 } |
| 57 | 56 |
| 58 void Set(HDC h) { | 57 void Set(HDC h) { |
| 59 Close(); | 58 Close(); |
| 60 hdc_ = h; | 59 hdc_ = h; |
| 61 } | 60 } |
| 62 | 61 |
| 63 operator HDC() { return hdc_; } | 62 operator HDC() { return hdc_; } |
| 64 | 63 |
| 65 private: | 64 private: |
| 66 void Close() { | 65 void Close() { |
| 67 #ifdef NOGDI | 66 #ifdef NOGDI |
| 68 assert(false); | 67 assert(false); |
| 69 #else | 68 #else |
| 70 if (hdc_) | 69 if (hdc_) |
| 71 DeleteDC(hdc_); | 70 DeleteDC(hdc_); |
| 72 #endif // NOGDI | 71 #endif // NOGDI |
| 73 } | 72 } |
| 74 | 73 |
| 75 HDC hdc_; | 74 HDC hdc_; |
| 76 DISALLOW_COPY_AND_ASSIGN(ScopedHDC); | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(ScopedCreateDC); | |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace win | 79 } // namespace win |
| 80 } // namespace base | 80 } // namespace base |
| 81 | 81 |
| 82 #endif // BASE_WIN_SCOPED_HDC_H_ | 82 #endif // BASE_WIN_SCOPED_HDC_H_ |
| OLD | NEW |