diff --git a/reactos/dll/win32/user32/controls/button.c b/reactos/dll/win32/user32/controls/button.c index 760d8149aaa..bc5cb41efe4 100644 --- a/reactos/dll/win32/user32/controls/button.c +++ b/reactos/dll/win32/user32/controls/button.c @@ -270,7 +270,7 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg, { if (pWnd->fnid != FNID_BUTTON) { - ERR("Wrong window class for Button!\n"); + ERR("Wrong window class for Button! fnId 0x%x\n",pWnd->fnid); return 0; } } @@ -321,9 +321,9 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg, return 0; #ifdef __REACTOS__ - case WM_DESTROY: case WM_NCDESTROY: NtUserSetWindowFNID(hWnd, FNID_DESTROY); + case WM_DESTROY: break; #endif @@ -442,27 +442,38 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg, case WM_SETTEXT: { /* Clear an old text here as Windows does */ - HDC hdc = GetDC(hWnd); - HBRUSH hbrush; - RECT client, rc; - HWND parent = GetParent(hWnd); +// +// wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790 +// Patch: http://source.winehq.org/patches/data/70889 +// By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR* +// + if (style & WS_VISIBLE) + { + HDC hdc = GetDC(hWnd); + HBRUSH hbrush; + RECT client, rc; + HWND parent = GetParent(hWnd); + UINT ctlMessage=(btn_type == BS_PUSHBUTTON || + btn_type == BS_DEFPUSHBUTTON || + btn_type == BS_PUSHLIKE || + btn_type == BS_USERBUTTON || + btn_type == BS_OWNERDRAW) ? + WM_CTLCOLORBTN : WM_CTLCOLORSTATIC; - if (!parent) parent = hWnd; - hbrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc, (LPARAM)hWnd); - if (!hbrush) /* did the app forget to call DefWindowProc ? */ - hbrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc, (LPARAM)hWnd); + if (!parent) parent = hWnd; - GetClientRect(hWnd, &client); - rc = client; - BUTTON_CalcLabelRect(hWnd, hdc, &rc); - /* Clip by client rect bounds */ - if (rc.right > client.right) rc.right = client.right; - if (rc.bottom > client.bottom) rc.bottom = client.bottom; - FillRect(hdc, &rc, hbrush); - ReleaseDC(hWnd, hdc); + hbrush = GetControlColor( parent, hWnd, hdc, ctlMessage); + GetClientRect(hWnd, &client); + rc = client; + BUTTON_CalcLabelRect(hWnd, hdc, &rc); + /* Clip by client rect bounds */ + if (rc.right > client.right) rc.right = client.right; + if (rc.bottom > client.bottom) rc.bottom = client.bottom; + FillRect(hdc, &rc, hbrush); + ReleaseDC(hWnd, hdc); + } +//// if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam ); else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam ); if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */ @@ -974,11 +985,7 @@ static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) parent = GetParent(hwnd); if (!parent) parent = hwnd; - hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)hwnd); - if (!hBrush) /* did the app forget to call defwindowproc ? */ - hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)hwnd ); + hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC); setup_clipping( hwnd, hDC ); if (style & BS_LEFTTEXT) @@ -1118,10 +1125,7 @@ static void GB_Paint( HWND hwnd, HDC hDC, UINT action ) /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */ parent = GetParent(hwnd); if (!parent) parent = hwnd; - hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); - if (!hbr) /* did the app forget to call defwindowproc ? */ - hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)hwnd); + hbr = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC); setup_clipping( hwnd, hDC ); GetClientRect( hwnd, &rc); diff --git a/reactos/dll/win32/user32/controls/combo.c b/reactos/dll/win32/user32/controls/combo.c index 1c474ec66d9..6d053f5a58d 100644 --- a/reactos/dll/win32/user32/controls/combo.c +++ b/reactos/dll/win32/user32/controls/combo.c @@ -867,9 +867,7 @@ static HBRUSH COMBO_PrepareColors( */ if (CB_DISABLED(lphc)) { - hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)lphc->self ); - + hBkgBrush = GetControlColor(lphc->owner, lphc->self, hDC, WM_CTLCOLORSTATIC); /* * We have to change the text color since WM_CTLCOLORSTATIC will * set it to the "enabled" color. This is the same behavior as the @@ -880,8 +878,7 @@ static HBRUSH COMBO_PrepareColors( else { /* FIXME: In which cases WM_CTLCOLORLISTBOX should be sent? */ - hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT, - (WPARAM)hDC, (LPARAM)lphc->self ); + hBkgBrush = GetControlColor(lphc->owner, lphc->self, hDC, WM_CTLCOLOREDIT); } /* @@ -1847,7 +1844,7 @@ LRESULT WINAPI ComboWndProc_common( HWND hwnd, UINT message, { if (pWnd->fnid != FNID_COMBOBOX) { - ERR("Wrong window class for ComboBox!\n"); + ERR("Wrong window class for ComboBox! fnId 0x%x\n",pWnd->fnid); return 0; } } diff --git a/reactos/dll/win32/user32/controls/edit.c b/reactos/dll/win32/user32/controls/edit.c index eef6d5e1ef4..3fd65ef8883 100644 --- a/reactos/dll/win32/user32/controls/edit.c +++ b/reactos/dll/win32/user32/controls/edit.c @@ -228,9 +228,7 @@ static HBRUSH EDIT_NotifyCtlColor(EDITSTATE *es, HDC hdc) msg = WM_CTLCOLOREDIT; /* why do we notify to es->hwndParent, and we send this one to GetParent()? */ - hbrush = (HBRUSH)SendMessageW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf); - if (!hbrush) - hbrush = (HBRUSH)DefWindowProcW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf); + hbrush = GetControlBrush(es->hwndSelf, hdc, msg); return hbrush; } @@ -4481,7 +4479,7 @@ LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP { if (pWnd->fnid != FNID_EDIT) { - ERR("Wrong window class for Edit!\n"); + ERR("Wrong window class for Edit! fnId 0x%x\n",pWnd->fnid); return 0; } } diff --git a/reactos/dll/win32/user32/controls/icontitle.c b/reactos/dll/win32/user32/controls/icontitle.c index f5f66f7aa84..aaaf5e4a172 100644 --- a/reactos/dll/win32/user32/controls/icontitle.c +++ b/reactos/dll/win32/user32/controls/icontitle.c @@ -224,8 +224,9 @@ LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, } return (hIconTitleFont ? 0 : -1); #ifdef __REACTOS__ - case WM_DESTROY: + case WM_NCDESTROY: NtUserSetWindowFNID(hWnd, FNID_DESTROY); + case WM_DESTROY: break; #endif case WM_NCHITTEST: diff --git a/reactos/dll/win32/user32/controls/listbox.c b/reactos/dll/win32/user32/controls/listbox.c index 3dddb3bf5a2..2dafc9217dd 100644 --- a/reactos/dll/win32/user32/controls/listbox.c +++ b/reactos/dll/win32/user32/controls/listbox.c @@ -2588,7 +2588,7 @@ LRESULT WINAPI ListBoxWndProc_common( HWND hwnd, UINT msg, { if (pWnd->fnid != FNID_LISTBOX) { - ERR("Wrong window class for listbox!\n"); + ERR("Wrong window class for listbox! fnId 0x%x\n",pWnd->fnid); return 0; } } @@ -3008,9 +3008,6 @@ LRESULT WINAPI ListBoxWndProc_common( HWND hwnd, UINT msg, return 0; case WM_DESTROY: -#ifdef __REACTOS__ - NtUserSetWindowFNID(hwnd, FNID_DESTROY); -#endif return LISTBOX_Destroy( descr ); case WM_ENABLE: @@ -3185,6 +3182,9 @@ LRESULT WINAPI ListBoxWndProc_common( HWND hwnd, UINT msg, case WM_NCDESTROY: if( lphc && (lphc->dwStyle & CBS_DROPDOWNLIST) != CBS_SIMPLE ) lphc->hWndLBox = 0; +#ifdef __REACTOS__ + NtUserSetWindowFNID(hwnd, FNID_DESTROY); +#endif break; case WM_NCACTIVATE: diff --git a/reactos/dll/win32/user32/controls/scrollbar.c b/reactos/dll/win32/user32/controls/scrollbar.c index 64dced5ef4b..545d2cee145 100644 --- a/reactos/dll/win32/user32/controls/scrollbar.c +++ b/reactos/dll/win32/user32/controls/scrollbar.c @@ -1277,8 +1277,11 @@ ScrollBarWndProc(WNDPROC DefWindowProc, HWND Wnd, UINT Msg, WPARAM wParam, LPARA #ifdef __REACTOS__ case WM_DESTROY: - NtUserSetWindowFNID(Wnd, FNID_DESTROY); return DefWindowProc(Wnd, Msg, wParam, lParam ); + + case WM_NCDESTROY: + NtUserSetWindowFNID(Wnd, FNID_DESTROY); + break; #endif //#if 0 /* FIXME */ diff --git a/reactos/dll/win32/user32/controls/static.c b/reactos/dll/win32/user32/controls/static.c index 3b2491e48d2..3a38820ef1c 100644 --- a/reactos/dll/win32/user32/controls/static.c +++ b/reactos/dll/win32/user32/controls/static.c @@ -324,33 +324,9 @@ static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style) } } -BOOL WINAPI GdiValidateHandle(HGDIOBJ hobj); - static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc) { - PWND pwnd; - HBRUSH hBrush; - HWND parent = GetParent(hwnd); - - if (!parent) parent = hwnd; - // ReactOS - pwnd = ValidateHwnd(parent); - if (pwnd && !TestWindowProcess(pwnd)) - { - return (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd); - } - //// - hBrush = (HBRUSH) SendMessageW( parent, - WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd ); - if (!hBrush || /* did the app forget to call DefWindowProc ? */ - !GdiValidateHandle(hBrush)) // ReactOS - { - /* FIXME: DefWindowProc should return different colors if a - manifest is present */ - hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc, (LPARAM)hwnd); - } - return hBrush; + return GetControlBrush( hwnd, hdc, WM_CTLCOLORSTATIC); } static VOID STATIC_InitColours(void) @@ -403,7 +379,7 @@ LRESULT WINAPI StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM { if (pWnd->fnid != FNID_STATIC) { - ERR("Wrong window class for Static!\n"); + ERR("Wrong window class for Static! fnId 0x%x\n",pWnd->fnid); return 0; } } @@ -642,6 +618,7 @@ LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style ) { DRAWITEMSTRUCT dis; + HBRUSH hBrush; HFONT font, oldFont = NULL; UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID ); @@ -657,7 +634,7 @@ static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style ) font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET ); if (font) oldFont = SelectObject( hdc, font ); - SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd ); + hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc); SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis ); if (font) SelectObject( hdc, oldFont ); } diff --git a/reactos/dll/win32/user32/include/user32p.h b/reactos/dll/win32/user32/include/user32p.h index c69b2277db4..82f68722400 100644 --- a/reactos/dll/win32/user32/include/user32p.h +++ b/reactos/dll/win32/user32/include/user32p.h @@ -99,5 +99,8 @@ void DrawCaret(HWND hWnd, PTHRDCARETINFO CaretInfo); BOOL UserDrawSysMenuButton( HWND hWnd, HDC hDC, LPRECT, BOOL down ); HWND* WIN_ListChildren (HWND hWndparent); VOID DeleteFrameBrushes(VOID); +BOOL WINAPI GdiValidateHandle(HGDIOBJ); +HBRUSH FASTCALL GetControlColor(HWND,HWND,HDC,UINT); +HBRUSH FASTCALL GetControlBrush(HWND,HDC,UINT); /* EOF */ diff --git a/reactos/dll/win32/user32/misc/misc.c b/reactos/dll/win32/user32/misc/misc.c index b729f3d889d..33e1ca74ed8 100644 --- a/reactos/dll/win32/user32/misc/misc.c +++ b/reactos/dll/win32/user32/misc/misc.c @@ -481,6 +481,45 @@ ValidateHwndOrDesk(HWND hwnd) return ValidateHwnd(hwnd); } +HBRUSH +FASTCALL +GetControlColor( + HWND hwndParent, + HWND hwnd, + HDC hdc, + UINT CtlMsg) +{ + PWND pwnd; + HBRUSH hBrush; + + if (!hwndParent) hwndParent = hwnd; + + pwnd = ValidateHwnd(hwndParent); + if (pwnd && !TestWindowProcess(pwnd)) + { + return (HBRUSH)DefWindowProcW( hwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)hwnd); + } + + hBrush = (HBRUSH)SendMessageW( hwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)hwnd); + + if (!hBrush || !GdiValidateHandle(hBrush)) + { + hBrush = (HBRUSH)DefWindowProcW( hwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)hwnd); + } + return hBrush; +} + +HBRUSH +FASTCALL +GetControlBrush( + HWND hwnd, + HDC hdc, + UINT ctlType) +{ + HWND hwndParent = GetParent(hwnd); + return GetControlColor( hwndParent, hwnd, hdc, ctlType); +} + /* * @implemented */ diff --git a/reactos/dll/win32/user32/windows/defwnd.c b/reactos/dll/win32/user32/windows/defwnd.c index 280aeff50aa..e5a9160fdea 100644 --- a/reactos/dll/win32/user32/windows/defwnd.c +++ b/reactos/dll/win32/user32/windows/defwnd.c @@ -1901,6 +1901,15 @@ RealDefWindowProcA(HWND hWnd, LRESULT Result = 0; PWND Wnd; + Wnd = ValidateHwnd(hWnd); + + if ( !Wnd && + Msg != WM_CTLCOLORMSGBOX && + Msg != WM_CTLCOLORBTN && + Msg != WM_CTLCOLORDLG && + Msg != WM_CTLCOLORSTATIC ) + return 0; + SPY_EnterMessage(SPY_DEFWNDPROC, hWnd, Msg, wParam, lParam); switch (Msg) { @@ -1925,7 +1934,6 @@ RealDefWindowProcA(HWND hWnd, PWSTR buf; ULONG len; - Wnd = ValidateHwnd(hWnd); if (Wnd != NULL && Wnd->strName.Length != 0) { buf = DesktopPtrToUser(Wnd->strName.Buffer); @@ -1948,7 +1956,6 @@ RealDefWindowProcA(HWND hWnd, PSTR outbuf = (PSTR)lParam; UINT copy; - Wnd = ValidateHwnd(hWnd); if (Wnd != NULL && wParam != 0) { if (Wnd->strName.Buffer != NULL) @@ -2061,6 +2068,15 @@ RealDefWindowProcW(HWND hWnd, LRESULT Result = 0; PWND Wnd; + Wnd = ValidateHwnd(hWnd); + + if ( !Wnd && + Msg != WM_CTLCOLORMSGBOX && + Msg != WM_CTLCOLORBTN && + Msg != WM_CTLCOLORDLG && + Msg != WM_CTLCOLORSTATIC ) + return 0; + SPY_EnterMessage(SPY_DEFWNDPROC, hWnd, Msg, wParam, lParam); switch (Msg) { @@ -2085,7 +2101,6 @@ RealDefWindowProcW(HWND hWnd, PWSTR buf; ULONG len; - Wnd = ValidateHwnd(hWnd); if (Wnd != NULL && Wnd->strName.Length != 0) { buf = DesktopPtrToUser(Wnd->strName.Buffer); @@ -2107,7 +2122,6 @@ RealDefWindowProcW(HWND hWnd, PWSTR buf = NULL; PWSTR outbuf = (PWSTR)lParam; - Wnd = ValidateHwnd(hWnd); if (Wnd != NULL && wParam != 0) { if (Wnd->strName.Buffer != NULL) diff --git a/reactos/dll/win32/user32/windows/mdi.c b/reactos/dll/win32/user32/windows/mdi.c index e7c091aa383..d24eb037af8 100644 --- a/reactos/dll/win32/user32/windows/mdi.c +++ b/reactos/dll/win32/user32/windows/mdi.c @@ -1161,11 +1161,18 @@ LRESULT WINAPI MDIClientWndProc_common( HWND hwnd, UINT message, WPARAM wParam, #ifdef __REACTOS__ HeapFree( GetProcessHeap(), 0, ci ); SetWindowLongPtrW( hwnd, 0, 0 ); - NtUserSetWindowFNID(hwnd, FNID_DESTROY); #endif return 0; } +#ifdef __REACTOS__ + case WM_NCDESTROY: + { + NtUserSetWindowFNID(hwnd, FNID_DESTROY); + return 0; + } +#endif + case WM_MDIACTIVATE: { if( ci->hwndActiveChild != (HWND)wParam ) diff --git a/reactos/dll/win32/user32/windows/menu.c b/reactos/dll/win32/user32/windows/menu.c index d6727b779a9..3e46264846e 100644 --- a/reactos/dll/win32/user32/windows/menu.c +++ b/reactos/dll/win32/user32/windows/menu.c @@ -1852,11 +1852,14 @@ LRESULT WINAPI PopupMenuWndProcA(HWND Wnd, UINT Message, WPARAM wParam, LPARAM l top_popup = NULL; top_popup_hmenu = NULL; } -#ifdef __REACTOS__ - NtUserSetWindowFNID(Wnd, FNID_DESTROY); -#endif break; +#ifdef __REACTOS__ + case WM_NCDESTROY: + NtUserSetWindowFNID(Wnd, FNID_DESTROY); + break; +#endif + case WM_SHOWWINDOW: if (0 != wParam) { @@ -1949,11 +1952,14 @@ PopupMenuWndProcW(HWND Wnd, UINT Message, WPARAM wParam, LPARAM lParam) top_popup = NULL; top_popup_hmenu = NULL; } -#ifdef __REACTOS__ - NtUserSetWindowFNID(Wnd, FNID_DESTROY); -#endif break; +#ifdef __REACTOS__ + case WM_NCDESTROY: + NtUserSetWindowFNID(Wnd, FNID_DESTROY); + break; +#endif + case WM_SHOWWINDOW: if (0 != wParam) {