| Index: app/win/hwnd_util.cc
|
| ===================================================================
|
| --- app/win/hwnd_util.cc (revision 0)
|
| +++ app/win/hwnd_util.cc (revision 0)
|
| @@ -0,0 +1,59 @@
|
| +// 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.
|
| +
|
| +#include "app/win/hwnd_util.h"
|
| +
|
| +#include "base/string_util.h"
|
| +
|
| +namespace app {
|
| +namespace win {
|
| +
|
| +string16 GetClassName(HWND window) {
|
| + // GetClassNameW will return a truncated result (properly null terminated) if
|
| + // the given buffer is not large enough. So, it is not possible to determine
|
| + // that we got the entire class name if the result is exactly equal to the
|
| + // size of the buffer minus one.
|
| + DWORD buffer_size = MAX_PATH;
|
| + while (true) {
|
| + std::wstring output;
|
| + DWORD size_ret =
|
| + GetClassNameW(window, WriteInto(&output, buffer_size), buffer_size);
|
| + if (size_ret == 0)
|
| + break;
|
| + if (size_ret < (buffer_size - 1)) {
|
| + output.resize(size_ret);
|
| + return output;
|
| + }
|
| + buffer_size *= 2;
|
| + }
|
| + return std::wstring(); // error
|
| +}
|
| +
|
| +#pragma warning(push)
|
| +#pragma warning(disable:4312 4244)
|
| +
|
| +WNDPROC SetWindowProc(HWND hwnd, WNDPROC proc) {
|
| + // The reason we don't return the SetwindowLongPtr() value is that it returns
|
| + // the orignal window procedure and not the current one. I don't know if it is
|
| + // a bug or an intended feature.
|
| + WNDPROC oldwindow_proc =
|
| + reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwnd, GWLP_WNDPROC));
|
| + SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(proc));
|
| + return oldwindow_proc;
|
| +}
|
| +
|
| +void* SetWindowUserData(HWND hwnd, void* user_data) {
|
| + return
|
| + reinterpret_cast<void*>(SetWindowLongPtr(hwnd, GWLP_USERDATA,
|
| + reinterpret_cast<LONG_PTR>(user_data)));
|
| +}
|
| +
|
| +void* GetWindowUserData(HWND hwnd) {
|
| + return reinterpret_cast<void*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
| +}
|
| +
|
| +#pragma warning(pop)
|
| +
|
| +} // namespace win
|
| +} // namespace app
|
|
|