2 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
27 #include "ComCtl32Util.h"
29 ComCtl32Util::ComCtl32Util() {
32 ComCtl32Util::~ComCtl32Util() {
35 void ComCtl32Util::InitLibraries() {
36 INITCOMMONCONTROLSEX iccex;
37 memset(&iccex, 0, sizeof(INITCOMMONCONTROLSEX));
38 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
39 ::InitCommonControlsEx(&iccex);
42 WNDPROC ComCtl32Util::SubclassHWND(HWND hwnd, WNDPROC _WindowProc) {
44 const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc
45 ::SetWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc, NULL); // _WindowProc is used as subclass ID
48 return (WNDPROC)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_WindowProc);
52 void ComCtl32Util::UnsubclassHWND(HWND hwnd, WNDPROC _WindowProc, WNDPROC _DefWindowProc) {
54 const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc
55 ::RemoveWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc); // _WindowProc is used as subclass ID
57 ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_DefWindowProc);
61 LRESULT ComCtl32Util::DefWindowProc(WNDPROC _DefWindowProc, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
63 return ::DefSubclassProc(hwnd, msg, wParam, lParam);
64 } else if (_DefWindowProc != NULL) {
65 return ::CallWindowProc(_DefWindowProc, hwnd, msg, wParam, lParam);
67 return ::DefWindowProc(hwnd, msg, wParam, lParam);
71 LRESULT ComCtl32Util::SharedWindowProc(HWND hwnd, UINT msg,
72 WPARAM wParam, LPARAM lParam,
73 UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
77 WNDPROC _WindowProc = (WNDPROC)uIdSubclass;
78 return ::CallWindowProc(_WindowProc, hwnd, msg, wParam, lParam);
80 CATCH_BAD_ALLOC_RET(0);