LRESULT CALLBACK Window::WndProc(HWND _hWnd, UINT message, WPARAM wParam, LPARAM lParam) { enum { #ifndef _WIN32_WCE WM_VERY_FIRST = WM_NCCREATE, #else WM_VERY_FIRST = WM_CREATE, #endif }; assert_none_locked(); if (message == WM_GETMINMAXINFO) /* WM_GETMINMAXINFO is called before WM_CREATE, and we havn't set a Window pointer yet - let DefWindowProc() handle it */ return ::DefWindowProc(_hWnd, message, wParam, lParam); Window *window; if (message == WM_VERY_FIRST) { LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam; window = (Window *)cs->lpCreateParams; window->created(_hWnd); window->set_userdata(window); } else { window = get_unchecked(_hWnd); } LRESULT result = window->on_message(_hWnd, message, wParam, lParam); assert_none_locked(); return result; }
ContainerWindow * Window::GetRootOwner() { #ifndef USE_GDI if (parent == NULL) /* no parent? We must be a ContainerWindow instance */ return (ContainerWindow *)this; ContainerWindow *root = parent; while (root->parent != NULL) root = root->parent; return root; #else /* USE_GDI */ #ifndef _WIN32_WCE HWND hRoot = ::GetAncestor(hWnd, GA_ROOTOWNER); if (hRoot == NULL) return NULL; #else HWND hRoot = hWnd; while (true) { HWND hParent = ::GetParent(hRoot); if (hParent == NULL) break; hRoot = hParent; } #endif /* can't use the "checked" method get() because hRoot may be a dialog, and uses Dialog::DlgProc() */ return (ContainerWindow *)get_unchecked(hRoot); #endif /* USE_GDI */ }
/** * Converts a #HWND into a #Window pointer. Returns NULL if the * HWND is not a Window peer. This only works for windows which * have called install_wndproc(). */ gcc_const static Window *get(HWND hWnd) { WNDPROC wndproc = (WNDPROC)::GetWindowLongPtr(hWnd, GWLP_WNDPROC); return wndproc == WndProc #ifdef _WIN32_WCE /* Windows CE seems to put WNDPROC pointers into some other segment (0x22000000 added); this is a dirty workaround which will be implemented properly once we understand what this really means */ || ((DWORD)wndproc & 0xffffff) == (DWORD)WndProc #endif ? get_unchecked(hWnd) : NULL; }
INT_PTR CALLBACK Dialog::DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { Dialog *dialog; if (message == WM_INITDIALOG) { dialog = (Dialog *)lParam; dialog->created(hwndDlg); dialog->set_userdata((Window *)dialog); } else { dialog = (Dialog *)get_unchecked(hwndDlg); if (dialog == NULL && message == WM_SETFONT) return false; } assert(dialog != NULL); return dialog->on_message(hwndDlg, message, wParam, lParam) == 0; }