ContainerWindow * Window::GetRootOwner() { assert(IsDefined()); #ifndef USE_WINUSER if (parent == nullptr) /* no parent? We must be a ContainerWindow instance */ return (ContainerWindow *)this; ContainerWindow *root = parent; while (root->parent != nullptr) root = root->parent; return root; #else /* USE_WINUSER */ HWND hRoot = ::GetAncestor(hWnd, GA_ROOTOWNER); if (hRoot == nullptr) return nullptr; /* can't use the "checked" method get() because hRoot may be a dialog, and uses Dialog::DlgProc() */ return (ContainerWindow *)GetUnchecked(hRoot); #endif /* USE_WINUSER */ }
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 }; AssertNoneLocked(); 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->SetUserData(window); } else { window = GetUnchecked(_hWnd); } LRESULT result = window->OnMessage(_hWnd, message, wParam, lParam); AssertNoneLocked(); 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 *)GetUnchecked(hRoot); #endif /* USE_GDI */ }
/** * Converts a #HWND into a #Window pointer. Returns nullptr if the * HWND is not a Window peer. This only works for windows which * use our WndProc. */ gcc_const static Window *GetChecked(HWND hWnd) { WNDPROC wndproc = (WNDPROC)::GetWindowLongPtr(hWnd, GWLP_WNDPROC); return wndproc == WndProc ? GetUnchecked(hWnd) : nullptr; }
/** * 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 InstallWndProc(). */ gcc_const static Window *GetChecked(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 ? GetUnchecked(hWnd) : NULL; }