1
// Copyright (c) 2010 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_GDI_OBJECT_H_
6
#define BASE_WIN_SCOPED_GDI_OBJECT_H_
10
#include "base/basictypes.h"
11
#include "base/logging.h"
16
// Like ScopedHandle but for GDI objects.
18
class ScopedGDIObject {
20
ScopedGDIObject() : object_(NULL) {}
21
explicit ScopedGDIObject(T object) : object_(object) {}
32
if (object_ && object != object_)
37
ScopedGDIObject& operator=(T object) {
48
operator T() { return object_; }
53
DeleteObject(object_);
57
DISALLOW_COPY_AND_ASSIGN(ScopedGDIObject);
60
// An explicit specialization for HICON because we have to call DestroyIcon()
61
// instead of DeleteObject() for HICON.
63
void inline ScopedGDIObject<HICON>::Close() {
68
// Typedefs for some common use cases.
69
typedef ScopedGDIObject<HBITMAP> ScopedBitmap;
70
typedef ScopedGDIObject<HRGN> ScopedRegion;
71
typedef ScopedGDIObject<HFONT> ScopedHFONT;
72
typedef ScopedGDIObject<HICON> ScopedHICON;
77
#endif // BASE_WIN_SCOPED_GDI_OBJECT_H_