Index: user32/windows/nonclient.c =================================================================== --- user32/windows/nonclient.c (revision 47295) +++ user32/windows/nonclient.c (working copy) @@ -161,7 +161,7 @@ * - Center the buttons verticaly in the rect */ VOID -UserDrawCaptionButton(LPRECT Rect, DWORD Style, DWORD ExStyle, HDC hDC, BOOL bDown, ULONG Type) +UserDrawCaptionButton(LPRECT Rect, DWORD Style, DWORD ExStyle, HDC hDC, BOOL bDown, BOOL bGray, ULONG Type) { RECT TempRect; @@ -191,7 +191,7 @@ DrawFrameControl(hDC, &TempRect, DFC_CAPTION, ((Style & WS_MINIMIZE) ? DFCS_CAPTIONRESTORE : DFCS_CAPTIONMIN) | (bDown ? DFCS_PUSHED : 0) | - ((Style & WS_MINIMIZEBOX) ? 0 : DFCS_INACTIVE)); + (bGray ? DFCS_INACTIVE : 0)); break; } case DFCS_CAPTIONMAX: @@ -209,7 +209,7 @@ DrawFrameControl(hDC, &TempRect, DFC_CAPTION, ((Style & WS_MAXIMIZE) ? DFCS_CAPTIONRESTORE : DFCS_CAPTIONMAX) | (bDown ? DFCS_PUSHED : 0) | - ((Style & WS_MAXIMIZEBOX) ? 0 : DFCS_INACTIVE)); + (bGray ? DFCS_INACTIVE : 0)); break; } case DFCS_CAPTIONCLOSE: @@ -231,14 +231,14 @@ DrawFrameControl(hDC, &TempRect, DFC_CAPTION, (DFCS_CAPTIONCLOSE | (bDown ? DFCS_PUSHED : 0) | - ((Style & WS_SYSMENU) ? 0 : DFCS_INACTIVE))); + (bGray ? DFCS_INACTIVE : 0))); break; } } } VOID -UserDrawCaptionButtonWnd(HWND hWnd, HDC hDC, BOOL bDown, ULONG Type) +UserDrawCaptionButtonWnd(HWND hWnd, HDC hDC, BOOL bDown, BOOL bGray, ULONG Type) { RECT WindowRect; SIZE WindowBorder; @@ -252,7 +252,7 @@ ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE); UserGetWindowBorders(Style, ExStyle, &WindowBorder, FALSE); InflateRect(&WindowRect, -WindowBorder.cx, -WindowBorder.cy); - UserDrawCaptionButton(&WindowRect, Style, ExStyle, hDC, bDown, Type); + UserDrawCaptionButton(&WindowRect, Style, ExStyle, hDC, bDown, bGray, Type); } // Note from Wine: @@ -419,11 +419,22 @@ /* Draw buttons */ if (Style & WS_SYSMENU) { - UserDrawCaptionButton(&TempRect, Style, ExStyle, hDC, FALSE, DFCS_CAPTIONCLOSE); + BOOL bGray; + if (Style & WS_SYSMENU) + { + HMENU SysMenu = GetSystemMenu(hWnd, FALSE); + UINT State = GetMenuState(SysMenu, SC_CLOSE, MF_BYCOMMAND); + bGray = (State == 0xFFFFFFFF || (State & MF_GRAYED) || + (State & MF_DISABLED) || + (GetClassLong(hWnd, GCL_STYLE) & CS_NOCLOSE)); + } + else + bGray = TRUE; + UserDrawCaptionButton(&TempRect, Style, ExStyle, hDC, FALSE, bGray, DFCS_CAPTIONCLOSE); if ((Style & (WS_MAXIMIZEBOX | WS_MINIMIZEBOX)) && !(ExStyle & WS_EX_TOOLWINDOW)) { - UserDrawCaptionButton(&TempRect, Style, ExStyle, hDC, FALSE, DFCS_CAPTIONMIN); - UserDrawCaptionButton(&TempRect, Style, ExStyle, hDC, FALSE, DFCS_CAPTIONMAX); + UserDrawCaptionButton(&TempRect, Style, ExStyle, hDC, FALSE, !(Style & WS_MINIMIZEBOX), DFCS_CAPTIONMIN); + UserDrawCaptionButton(&TempRect, Style, ExStyle, hDC, FALSE, !(Style & WS_MAXIMIZEBOX), DFCS_CAPTIONMAX); } } if(!(Style & WS_MINIMIZE)) @@ -875,6 +886,8 @@ { MSG Msg; HDC WindowDC; + HMENU SysMenu; + UINT State; BOOL Pressed = TRUE, OldState; WPARAM SCMsg; ULONG ButtonType, Style; @@ -885,6 +898,12 @@ case HTCLOSE: if (!(Style & WS_SYSMENU)) return; + SysMenu = GetSystemMenu(hWnd, FALSE); + State = GetMenuState(SysMenu, SC_CLOSE, MF_BYCOMMAND); + if (State == 0xFFFFFFFF || (State & MF_GRAYED) || + (State & MF_DISABLED) || + (GetClassLong(hWnd, GCL_STYLE) & CS_NOCLOSE)) + return; ButtonType = DFCS_CAPTIONCLOSE; SCMsg = SC_CLOSE; break; @@ -915,7 +934,7 @@ UpdateWindow(hWnd); WindowDC = GetWindowDC(hWnd); - UserDrawCaptionButtonWnd(hWnd, WindowDC, TRUE, ButtonType); + UserDrawCaptionButtonWnd(hWnd, WindowDC, TRUE, TRUE, ButtonType); SetCapture(hWnd); @@ -933,11 +952,11 @@ OldState = Pressed; Pressed = (DefWndNCHitTest(hWnd, Msg.pt) == wParam); if (Pressed != OldState) - UserDrawCaptionButtonWnd(hWnd, WindowDC, Pressed, ButtonType); + UserDrawCaptionButtonWnd(hWnd, WindowDC, Pressed, TRUE, ButtonType); } if (Pressed) - UserDrawCaptionButtonWnd(hWnd, WindowDC, FALSE, ButtonType); + UserDrawCaptionButtonWnd(hWnd, WindowDC, FALSE, TRUE, ButtonType); ReleaseCapture(); ReleaseDC(hWnd, WindowDC); if (Pressed)