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.
5 #ifndef BASE_WIN_SCOPED_HDC_H_
6 #define BASE_WIN_SCOPED_HDC_H_
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/win/scoped_handle.h"
17 // Like ScopedHandle but for HDC. Only use this on HDCs returned from
21 explicit ScopedGetDC(HWND hwnd
)
25 DCHECK(IsWindow(hwnd_
));
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.
37 ReleaseDC(hwnd_
, hdc_
);
40 operator HDC() { return hdc_
; }
46 DISALLOW_COPY_AND_ASSIGN(ScopedGetDC
);
49 // Like ScopedHandle but for HDC. Only use this on HDCs returned from
50 // CreateCompatibleDC, CreateDC and CreateIC.
51 class CreateDCTraits
{
55 static bool CloseHandle(HDC handle
) {
56 return ::DeleteDC(handle
) != FALSE
;
59 static bool IsHandleValid(HDC handle
) {
60 return handle
!= NULL
;
63 static HDC
NullHandle() {
68 DISALLOW_IMPLICIT_CONSTRUCTORS(CreateDCTraits
);
71 typedef GenericScopedHandle
<CreateDCTraits
, DummyVerifierTraits
> ScopedCreateDC
;
76 #endif // BASE_WIN_SCOPED_HDC_H_