From ce0e7246e92f2da8e6b865dd51ae626f9867ca4f Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Sat, 16 Oct 2010 03:46:05 +0000 Subject: Move the windows-specific scoped_* stuff from base to base/win and in the base::win namespace. This keeps old headers that forward to the new versions and have using declarations that allow the existing code to compile. I fixed all the callers in base to use the new ones, and also the other files I happened to touch. This splits out the stuff from scoped_handle into a few separate files. I just deleted ScopedFindFile since it was only used in one place and it wasn't even really helping there. I removed StackBstr which was a #define and used the "regular" ScopedBstr in the 7 places that used it. This is an optimization to avoid an extra allocation, but none of the callers are remotely performance critical. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3781009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62843 0039d316-1c4b-4281-b951-d872f2087c98 --- base/win/scoped_hdc.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 base/win/scoped_hdc.h (limited to 'base/win/scoped_hdc.h') diff --git a/base/win/scoped_hdc.h b/base/win/scoped_hdc.h new file mode 100644 index 0000000..73d369a7 --- /dev/null +++ b/base/win/scoped_hdc.h @@ -0,0 +1,55 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_WIN_SCOPED_HDC_H_ +#define BASE_WIN_SCOPED_HDC_H_ +#pragma once + +#include + +#include "base/basictypes.h" + +namespace base { +namespace win { + +// Like ScopedHandle but for HDC. Only use this on HDCs returned from +// CreateCompatibleDC. For an HDC returned by GetDC, use ReleaseDC instead. +class ScopedHDC { + public: + ScopedHDC() : hdc_(NULL) { } + explicit ScopedHDC(HDC h) : hdc_(h) { } + + ~ScopedHDC() { + Close(); + } + + HDC Get() { + return hdc_; + } + + void Set(HDC h) { + Close(); + hdc_ = h; + } + + operator HDC() { return hdc_; } + + private: + void Close() { +#ifdef NOGDI + assert(false); +#else + if (hdc_) + DeleteDC(hdc_); +#endif // NOGDI + } + + HDC hdc_; + DISALLOW_COPY_AND_ASSIGN(ScopedHDC); +}; + +} // namespace win +} // namespace base + +#endif // BASE_WIN_SCOPED_HDC_H_ -- cgit v1.1