1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
base / win / scoped_gdi_object.h [blame]
// Copyright 2010 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_WIN_SCOPED_GDI_OBJECT_H_
#define BASE_WIN_SCOPED_GDI_OBJECT_H_
#include <windows.h>
#include "base/scoped_generic.h"
namespace base {
namespace win {
namespace internal {
template <class T>
struct ScopedGDIObjectTraits {
static T InvalidValue() { return nullptr; }
static void Free(T object) { DeleteObject(object); }
};
// An explicit specialization for HICON because we have to call DestroyIcon()
// instead of DeleteObject() for HICON.
template <>
void inline ScopedGDIObjectTraits<HICON>::Free(HICON icon) {
DestroyIcon(icon);
}
} // namespace internal
// Like ScopedHandle but for GDI objects.
template <class T>
using ScopedGDIObject = ScopedGeneric<T, internal::ScopedGDIObjectTraits<T>>;
// Typedefs for some common use cases.
typedef ScopedGDIObject<HBITMAP> ScopedBitmap;
typedef ScopedGDIObject<HRGN> ScopedRegion;
typedef ScopedGDIObject<HFONT> ScopedHFONT;
typedef ScopedGDIObject<HICON> ScopedHICON;
} // namespace win
} // namespace base
#endif // BASE_WIN_SCOPED_GDI_OBJECT_H_