Chromium Code Reviews| Index: base/win/scoped_hdc.h |
| diff --git a/base/win/scoped_hdc.h b/base/win/scoped_hdc.h |
| index 070c656b5494d14b506e609812c984524c49bcf3..6118fd4716465648860dd86e4428f491adce6a53 100644 |
| --- a/base/win/scoped_hdc.h |
| +++ b/base/win/scoped_hdc.h |
| @@ -10,6 +10,7 @@ |
| #include "base/basictypes.h" |
| #include "base/logging.h" |
| +#include "base/win/scoped_handle.h" |
| namespace base { |
| namespace win { |
| @@ -48,41 +49,28 @@ class ScopedGetDC { |
| // Like ScopedHandle but for HDC. Only use this on HDCs returned from |
| // CreateCompatibleDC, CreateDC and CreateIC. |
| -class ScopedCreateDC { |
| +class CreateDCTraits { |
| public: |
| - ScopedCreateDC() : hdc_(NULL) { } |
| - explicit ScopedCreateDC(HDC h) : hdc_(h) { } |
| + typedef HDC Handle; |
| - ~ScopedCreateDC() { |
| - Close(); |
| + static bool CloseHandle(HDC handle) { |
| + return ::DeleteDC(handle) != FALSE; |
| } |
| - HDC Get() { |
| - return hdc_; |
| + static bool IsHandleValid(HDC handle) { |
| + return handle != NULL; |
| } |
| - void Set(HDC h) { |
| - Close(); |
| - hdc_ = h; |
| + static HDC NullHandle() { |
| + return NULL; |
| } |
| - operator HDC() { return hdc_; } |
| - |
| private: |
| - void Close() { |
| -#ifdef NOGDI |
|
alexeypa (please no reviews)
2012/07/12 18:18:00
This code was wrong BTW. When NOGDI is defined Del
|
| - assert(false); |
| -#else |
| - if (hdc_) |
| - DeleteDC(hdc_); |
| -#endif // NOGDI |
| - } |
| - |
| - HDC hdc_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ScopedCreateDC); |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits); |
| }; |
| +typedef GenericScopedHandle<CreateDCTraits, VerifierTraits> ScopedCreateDC; |
| + |
| } // namespace win |
| } // namespace base |