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. 4 5 #ifndef UI_BASE_WIN_HWND_UTIL_H_ 6 #define UI_BASE_WIN_HWND_UTIL_H_ 7 8 #include <windows.h> 9 10 #include "base/strings/string16.h" 11 #include "ui/base/ui_export.h" 12 13 namespace gfx { 14 class Point; 15 class Size; 16 } 17 18 namespace ui { 19 20 // A version of the GetClassNameW API that returns the class name in an 21 // string16. An empty result indicates a failure to get the class name. 22 UI_EXPORT string16 GetClassName(HWND hwnd); 23 24 // Useful for subclassing a HWND. Returns the previous window procedure. 25 UI_EXPORT WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc); 26 27 // Pointer-friendly wrappers around Get/SetWindowLong(..., GWLP_USERDATA, ...) 28 // Returns the previously set value. 29 UI_EXPORT void* SetWindowUserData(HWND hwnd, void* user_data); 30 UI_EXPORT void* GetWindowUserData(HWND hwnd); 31 32 // Returns true if the specified window is the current active top window or one 33 // of its children. 34 UI_EXPORT bool DoesWindowBelongToActiveWindow(HWND window); 35 36 // Sizes the window to have a window size of |pref|, then centers the window 37 // over |parent|, ensuring the window fits on screen. 38 UI_EXPORT void CenterAndSizeWindow(HWND parent, 39 HWND window, 40 const gfx::Size& pref); 41 42 // If |hwnd| is NULL logs various thing and CHECKs. Invoke right after calling 43 // CreateWindow. 44 UI_EXPORT void CheckWindowCreated(HWND hwnd); 45 46 // Shows |window|'s system menu (at a specified |point| in screen coordinates). 47 UI_EXPORT void ShowSystemMenu(HWND window); 48 UI_EXPORT void ShowSystemMenuAtPoint(HWND window, const gfx::Point& point); 49 50 // Returns the window you can use to parent a top level window. 51 // Note that in some cases we create child windows not parented to its final 52 // container so in those cases you should pass true in |get_real_hwnd|. 53 UI_EXPORT HWND GetWindowToParentTo(bool get_real_hwnd); 54 55 } // namespace ui 56 57 #endif // UI_BASE_WIN_HWND_UTIL_H_ 58