3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/window.c
6 * PURPOSE: Window management
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
12 /* INCLUDES ******************************************************************/
18 #include <user32/wininternal.h>
21 /* GLOBALS *******************************************************************/
23 static HBITMAP hbitmapClose;
24 static HBITMAP hbitmapMinimize;
25 static HBITMAP hbitmapMinimizeD;
26 static HBITMAP hbitmapMaximize;
27 static HBITMAP hbitmapMaximizeD;
28 static HBITMAP hbitmapRestore;
29 static HBITMAP hbitmapRestoreD;
31 static COLORREF SysColours[] =
33 RGB(224, 224, 224) /* COLOR_SCROLLBAR */,
34 RGB(192, 192, 192) /* COLOR_BACKGROUND */,
35 RGB(0, 64, 128) /* COLOR_ACTIVECAPTION */,
36 RGB(255, 255, 255) /* COLOR_INACTIVECAPTION */,
37 RGB(255, 255, 255) /* COLOR_MENU */,
38 RGB(255, 255, 255) /* COLOR_WINDOW */,
39 RGB(0, 0, 0) /* COLOR_WINDOWFRAME */,
40 RGB(0, 0, 0) /* COLOR_MENUTEXT */,
41 RGB(0, 0, 0) /* COLOR_WINDOWTEXT */,
42 RGB(255, 255, 255) /* COLOR_CAPTIONTEXT */,
43 RGB(128, 128, 128) /* COLOR_ACTIVEBORDER */,
44 RGB(255, 255, 255) /* COLOR_INACTIVEBORDER */,
45 RGB(255, 255, 232) /* COLOR_APPWORKSPACE */,
46 RGB(224, 224, 224) /* COLOR_HILIGHT */,
47 RGB(0, 0, 0) /* COLOR_HILIGHTTEXT */,
48 RGB(192, 192, 192) /* COLOR_BTNFACE */,
49 RGB(128, 128, 128) /* COLOR_BTNSHADOW */,
50 RGB(192, 192, 192) /* COLOR_GRAYTEXT */,
51 RGB(0, 0, 0) /* COLOR_BTNTEXT */,
52 RGB(0, 0, 0) /* COLOR_INACTIVECAPTIONTEXT */,
53 RGB(255, 255, 255) /* COLOR_BTNHILIGHT */,
54 RGB(32, 32, 32) /* COLOR_3DDKSHADOW */,
55 RGB(192, 192, 192) /* COLOR_3DLIGHT */,
56 RGB(0, 0, 0) /* COLOR_INFOTEXT */,
57 RGB(255, 255, 192) /* COLOR_INFOBK */,
58 RGB(184, 180, 184) /* COLOR_ALTERNATEBTNFACE */,
59 RGB(0, 0, 255) /* COLOR_HOTLIGHT */,
60 RGB(16, 132, 208) /* COLOR_GRADIENTACTIVECAPTION */,
61 RGB(181, 181, 181) /* COLOR_GRADIENTINACTIVECAPTION */,
64 static ATOM AtomInternalPos;
66 /* FUNCTIONS *****************************************************************/
69 UserSetupInternalPos(VOID)
72 AtomInternalPos = GlobalAddAtomA(Str);
75 /* ReactOS extension */
77 GetSysColorPen(int nIndex)
79 return(CreatePen(PS_SOLID, 1, SysColours[nIndex]));
83 GetSysColorBrush(int nIndex)
85 return(CreateSolidBrush(SysColours[nIndex]));
90 DefFrameProcA(HWND hWnd,
100 DefFrameProcW(HWND hWnd,
111 DefWndRedrawIconTitle(HWND hWnd)
113 PINTERNALPOS lpPos = (PINTERNALPOS)GetPropA(hWnd,
114 (LPSTR)(DWORD)AtomInternalPos);
117 if (lpPos->IconTitle != NULL)
119 SendMessageA(lpPos->IconTitle, WM_SHOWWINDOW, TRUE, 0);
120 InvalidateRect(lpPos->IconTitle, NULL, TRUE);
128 UserHasMenu(HWND hWnd, ULONG Style)
130 return(!(Style & WS_CHILD) && GetWindowLong(hWnd, GWL_ID) != 0);
134 UserHasAnyFrameStyle(ULONG Style, ULONG ExStyle)
136 return((Style & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) ||
137 (ExStyle & WS_EX_DLGMODALFRAME) ||
138 (!(Style & (WS_CHILD | WS_POPUP))));
142 UserHasDlgFrameStyle(ULONG Style, ULONG ExStyle)
144 return((ExStyle & WS_EX_DLGMODALFRAME) ||
145 ((Style & WS_DLGFRAME) && (!(Style & WS_THICKFRAME))));
149 UserHasThickFrameStyle(ULONG Style, ULONG ExStyle)
151 return((Style & WS_THICKFRAME) &&
152 (!((Style & (WS_DLGFRAME | WS_BORDER)) == WS_DLGFRAME)));
156 UserHasThinFrameStyle(ULONG Style, ULONG ExStyle)
158 return((Style & WS_BORDER) ||
159 (!(Style & (WS_CHILD | WS_POPUP))));
163 UserHasBigFrameStyle(ULONG Style, ULONG ExStyle)
165 return((Style & (WS_THICKFRAME | WS_DLGFRAME)) ||
166 (ExStyle & WS_EX_DLGMODALFRAME));
169 static void UserGetInsideRectNC( HWND hwnd, RECT *rect )
175 Style = GetWindowLong(hwnd, GWL_STYLE);
176 ExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
177 GetWindowRect(hwnd, &WindowRect);
178 rect->top = rect->left = 0;
179 rect->right = WindowRect.right - WindowRect.left;
180 rect->bottom = WindowRect.bottom - WindowRect.top;
182 if (Style & WS_ICONIC)
187 /* Remove frame from rectangle */
188 if (UserHasThickFrameStyle(Style, ExStyle ))
190 InflateRect( rect, -GetSystemMetrics(SM_CXFRAME),
191 -GetSystemMetrics(SM_CYFRAME) );
195 if (UserHasDlgFrameStyle(Style, ExStyle ))
197 InflateRect( rect, -GetSystemMetrics(SM_CXDLGFRAME),
198 -GetSystemMetrics(SM_CYDLGFRAME));
199 /* FIXME: this isn't in NC_AdjustRect? why not? */
200 if (ExStyle & WS_EX_DLGMODALFRAME)
201 InflateRect( rect, -1, 0 );
205 if (UserHasThinFrameStyle(Style, ExStyle))
207 InflateRect(rect, -GetSystemMetrics(SM_CXBORDER),
208 -GetSystemMetrics(SM_CYBORDER));
214 void UserDrawSysButton( HWND hwnd, HDC hdc, BOOL down )
221 Style = GetWindowLong(hwnd, GWL_STYLE);
222 UserGetInsideRectNC( hwnd, &rect );
223 hdcMem = CreateCompatibleDC( hdc );
224 hbitmap = SelectObject( hdcMem, hbitmapClose );
225 BitBlt(hdc, rect.left, rect.top, GetSystemMetrics(SM_CXSIZE),
226 GetSystemMetrics(SM_CYSIZE), hdcMem,
227 (Style & WS_CHILD) ? GetSystemMetrics(SM_CXSIZE) : 0, 0,
228 down ? NOTSRCCOPY : SRCCOPY );
229 SelectObject( hdcMem, hbitmap );
233 static void UserDrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
238 UserGetInsideRectNC( hwnd, &rect );
239 hdcMem = CreateCompatibleDC( hdc );
240 SelectObject( hdcMem, (IsZoomed(hwnd)
241 ? (down ? hbitmapRestoreD : hbitmapRestore)
242 : (down ? hbitmapMaximizeD : hbitmapMaximize)) );
243 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSMSIZE) - 1, rect.top,
244 GetSystemMetrics(SM_CXSMSIZE) + 1, GetSystemMetrics(SM_CYSMSIZE), hdcMem, 0, 0,
249 static void UserDrawMinButton( HWND hwnd, HDC hdc, BOOL down)
254 UserGetInsideRectNC(hwnd, &rect);
255 hdcMem = CreateCompatibleDC(hdc);
256 SelectObject(hdcMem, (down ? hbitmapMinimizeD : hbitmapMinimize));
257 if (GetWindowLong(hwnd, GWL_STYLE) & WS_MAXIMIZEBOX)
259 rect.right -= GetSystemMetrics(SM_CXSMSIZE)+1;
261 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSMSIZE) - 1, rect.top,
262 GetSystemMetrics(SM_CXSMSIZE) + 1, GetSystemMetrics(SM_CYSMSIZE),
268 static void UserDrawCaptionNC( HDC hdc, RECT *rect, HWND hwnd,
269 DWORD style, BOOL active )
276 hbitmapClose = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_CLOSE));
277 hbitmapMinimize = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCE) );
278 hbitmapMinimizeD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCED) );
279 hbitmapMaximize = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOM) );
280 hbitmapMaximizeD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
281 hbitmapRestore = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORE) );
282 hbitmapRestoreD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORED) );
285 if (GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_DLGMODALFRAME)
287 HBRUSH hbrushOld = SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW) );
288 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
289 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
290 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
293 SelectObject( hdc, hbrushOld );
296 MoveToEx( hdc, r.left, r.bottom, NULL );
297 LineTo( hdc, r.right, r.bottom );
299 if (style & WS_SYSMENU)
301 UserDrawSysButton( hwnd, hdc, FALSE );
302 r.left += GetSystemMetrics(SM_CXSIZE) + 1;
303 MoveToEx( hdc, r.left - 1, r.top, NULL );
304 LineTo( hdc, r.left - 1, r.bottom );
306 if (style & WS_MAXIMIZEBOX)
308 UserDrawMaxButton( hwnd, hdc, FALSE );
309 r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
311 if (style & WS_MINIMIZEBOX)
313 UserDrawMinButton( hwnd, hdc, FALSE );
314 r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
317 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
318 COLOR_INACTIVECAPTION) );
320 if (GetWindowTextA( hwnd, buffer, sizeof(buffer) ))
322 NONCLIENTMETRICS nclm;
323 HFONT hFont, hOldFont;
325 nclm.cbSize = sizeof(NONCLIENTMETRICS);
326 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
327 if (style & WS_EX_TOOLWINDOW)
328 hFont = CreateFontIndirectW(&nclm.lfSmCaptionFont);
330 hFont = CreateFontIndirectW(&nclm.lfCaptionFont);
331 hOldFont = SelectObject(hdc, hFont);
333 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
334 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
335 SetBkMode( hdc, TRANSPARENT );
336 /*DrawTextA( hdc, buffer, -1, &r,
337 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );*/
338 TextOutA(hdc, r.left+5, r.top+2, buffer, strlen(buffer));
339 DeleteObject (SelectObject (hdc, hOldFont));
344 UserDrawFrameNC(HDC hdc, RECT* rect, BOOL dlgFrame, BOOL active)
350 width = GetSystemMetrics(SM_CXDLGFRAME) - 1;
351 height = GetSystemMetrics(SM_CYDLGFRAME) - 1;
352 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
353 COLOR_INACTIVECAPTION) );
357 width = GetSystemMetrics(SM_CXFRAME) - 2;
358 height = GetSystemMetrics(SM_CYFRAME) - 2;
359 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
360 COLOR_INACTIVEBORDER) );
364 PatBlt( hdc, rect->left, rect->top,
365 rect->right - rect->left, height, PATCOPY );
366 PatBlt( hdc, rect->left, rect->top,
367 width, rect->bottom - rect->top, PATCOPY );
368 PatBlt( hdc, rect->left, rect->bottom - 1,
369 rect->right - rect->left, -height, PATCOPY );
370 PatBlt( hdc, rect->right - 1, rect->top,
371 -width, rect->bottom - rect->top, PATCOPY );
375 InflateRect( rect, -width, -height );
379 INT decYOff = GetSystemMetrics(SM_CXFRAME) +
380 GetSystemMetrics(SM_CXSIZE) - 1;
381 INT decXOff = GetSystemMetrics(SM_CYFRAME) +
382 GetSystemMetrics(SM_CYSIZE) - 1;
384 /* Draw inner rectangle */
386 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
387 Rectangle( hdc, rect->left + width, rect->top + height,
388 rect->right - width , rect->bottom - height );
390 /* Draw the decorations */
392 MoveToEx( hdc, rect->left, rect->top + decYOff, NULL );
393 LineTo( hdc, rect->left + width, rect->top + decYOff );
394 MoveToEx( hdc, rect->right - 1, rect->top + decYOff, NULL );
395 LineTo( hdc, rect->right - width - 1, rect->top + decYOff );
396 MoveToEx( hdc, rect->left, rect->bottom - decYOff, NULL );
397 LineTo( hdc, rect->left + width, rect->bottom - decYOff );
398 MoveToEx( hdc, rect->right - 1, rect->bottom - decYOff, NULL );
399 LineTo( hdc, rect->right - width - 1, rect->bottom - decYOff );
401 MoveToEx( hdc, rect->left + decXOff, rect->top, NULL );
402 LineTo( hdc, rect->left + decXOff, rect->top + height);
403 MoveToEx( hdc, rect->left + decXOff, rect->bottom - 1, NULL );
404 LineTo( hdc, rect->left + decXOff, rect->bottom - height - 1 );
405 MoveToEx( hdc, rect->right - decXOff, rect->top, NULL );
406 LineTo( hdc, rect->right - decXOff, rect->top + height );
407 MoveToEx( hdc, rect->right - decXOff, rect->bottom - 1, NULL );
408 LineTo( hdc, rect->right - decXOff, rect->bottom - height - 1 );
410 InflateRect( rect, -width - 1, -height - 1 );
415 DefWndDoPaintNC(HWND hWnd, HRGN clip)
423 Active = GetWindowLongW(hWnd, GWL_STYLE) & WIN_NCACTIVATED;
424 Style = GetWindowLong(hWnd, GWL_STYLE);
425 ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
427 hDc = GetDCEx(hWnd, (clip > (HRGN)1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
428 ((clip > (HRGN)1) ? (DCX_INTERSECTRGN | DCX_KEEPCLIPRGN) : 0));
434 /* FIXME: Test whether we need to draw anything at all. */
436 GetWindowRect(hWnd, &rect);
437 rect.right = rect.right - rect.left;
438 rect.bottom = rect.bottom - rect.top;
439 rect.top = rect.left = 0;
441 SelectObject(hDc, GetSysColorPen(COLOR_WINDOWFRAME));
442 if (UserHasAnyFrameStyle(Style, ExStyle))
444 SelectObject(hDc, GetStockObject(NULL_BRUSH));
445 Rectangle(hDc, 0, 0, rect.right, rect.bottom);
446 InflateRect(&rect, -1, -1);
449 if (UserHasThickFrameStyle(Style, ExStyle))
451 UserDrawFrameNC(hDc, &rect, FALSE, Active);
453 else if (UserHasDlgFrameStyle(Style, ExStyle))
455 UserDrawFrameNC(hDc, &rect, TRUE, Active);
458 if (Style & WS_CAPTION)
461 r.bottom = rect.top + GetSystemMetrics(SM_CYSIZE);
462 rect.top += GetSystemMetrics(SM_CYSIZE) +
463 GetSystemMetrics(SM_CYBORDER);
464 UserDrawCaptionNC(hDc, &r, hWnd, Style, Active);
467 /* FIXME: Draw menu bar. */
469 /* FIXME: Draw scroll bars. */
471 /* FIXME: Draw size box. */
473 ReleaseDC(hWnd, hDc);
477 DefWndPaintNC(HWND hWnd, HRGN clip)
479 if (IsWindowVisible(hWnd))
483 DefWndRedrawIconTitle(hWnd);
487 DefWndDoPaintNC(hWnd, clip);
494 DefWndHitTestNC(HWND hWnd, POINT Point)
497 ULONG Style = GetWindowLong(hWnd, GWL_STYLE);
498 ULONG ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
500 GetWindowRect(hWnd, &WindowRect);
502 if (!PtInRect(&WindowRect, Point))
506 if (Style & WS_MINIMIZE)
510 if (UserHasThickFrameStyle(Style, ExStyle))
512 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXFRAME),
513 -GetSystemMetrics(SM_CYFRAME));
514 if (!PtInRect(&WindowRect, Point))
516 if (Point.y < WindowRect.top)
518 if (Point.x < (WindowRect.left + GetSystemMetrics(SM_CXSIZE)))
522 if (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXSIZE)))
528 if (Point.y >= WindowRect.bottom)
530 if (Point.x < (WindowRect.left + GetSystemMetrics(SM_CXSIZE)))
532 return(HTBOTTOMLEFT);
534 if (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXSIZE)))
536 return(HTBOTTOMRIGHT);
540 if (Point.x < WindowRect.left)
542 if (Point.y < (WindowRect.top + GetSystemMetrics(SM_CYSIZE)))
546 if (Point.y >= (WindowRect.bottom - GetSystemMetrics(SM_CYSIZE)))
548 return(HTBOTTOMLEFT);
552 if (Point.x >= WindowRect.right)
554 if (Point.y < (WindowRect.top + GetSystemMetrics(SM_CYSIZE)))
558 if (Point.y >= (WindowRect.bottom - GetSystemMetrics(SM_CYSIZE)))
560 return(HTBOTTOMRIGHT);
568 if (UserHasDlgFrameStyle(Style, ExStyle))
570 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXDLGFRAME),
571 -GetSystemMetrics(SM_CYDLGFRAME));
573 else if (UserHasThinFrameStyle(Style, ExStyle))
575 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXBORDER),
576 -GetSystemMetrics(SM_CYBORDER));
578 if (!PtInRect(&WindowRect, Point))
584 if ((Style & WS_CAPTION) == WS_CAPTION)
586 WindowRect.top += GetSystemMetrics(SM_CYCAPTION) -
587 GetSystemMetrics(SM_CYBORDER);
588 if (!PtInRect(&WindowRect, Point))
590 if ((Style & WS_SYSMENU) && !(ExStyle & WS_EX_TOOLWINDOW))
592 WindowRect.left += GetSystemMetrics(SM_CXSIZE);
594 if (Point.x <= WindowRect.left)
599 if (Style & WS_MAXIMIZEBOX)
601 WindowRect.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
603 if (Point.x >= WindowRect.right)
608 if (Style & WS_MINIMIZEBOX)
610 WindowRect.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
612 if (Point.x >= WindowRect.right)
620 ScreenToClient(hWnd, &Point);
621 GetClientRect(hWnd, &WindowRect);
623 if (PtInRect(&WindowRect, Point))
628 if (Style & WS_VSCROLL)
630 WindowRect.right += GetSystemMetrics(SM_CXVSCROLL);
631 if (PtInRect(&WindowRect, Point))
637 if (Style & WS_HSCROLL)
639 WindowRect.bottom += GetSystemMetrics(SM_CYHSCROLL);
640 if (PtInRect(&WindowRect, Point))
642 if ((Style & WS_VSCROLL) &&
643 (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXVSCROLL))))
651 if (UserHasMenu(hWnd, Style))
653 if (Point.y < 0 && Point.x >= 0 && Point.x <= WindowRect.right)
663 DefWndTrackMinMaxBox(HWND hWnd, WPARAM wParam)
665 HDC hDC = GetWindowDC(hWnd);
671 if (wParam == HTMINBUTTON)
673 UserDrawMinButton(hWnd, hDC, TRUE);
677 UserDrawMaxButton(hWnd, hDC, TRUE);
682 BOOL OldState = Pressed;
684 GetMessageA(hWnd, &Msg, 0, 0);
685 if (Msg.message == WM_LBUTTONUP)
689 if (Msg.message != WM_MOUSEMOVE)
694 Pressed = DefWndHitTestNC(hWnd, Msg.pt) == wParam;
695 if (Pressed != OldState)
697 if (wParam == HTMINBUTTON)
699 UserDrawMinButton(hWnd, hDC, Pressed);
703 UserDrawMaxButton(hWnd, hDC, Pressed);
710 if (wParam == HTMINBUTTON)
712 UserDrawMinButton(hWnd, hDC, FALSE);
716 UserDrawMaxButton(hWnd, hDC, FALSE);
721 ReleaseDC(hWnd, hDC);
728 if (wParam == HTMINBUTTON)
730 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MINIMIZE,
731 MAKELONG(Msg.pt.x, Msg.pt.y));
735 SendMessageA(hWnd, WM_SYSCOMMAND,
736 IsZoomed(hWnd) ? SC_RESTORE : SC_MAXIMIZE,
737 MAKELONG(Msg.pt.x, Msg.pt.y));
742 DefWndDrawSysButton(HWND hWnd, HDC hDC, BOOL Down)
746 HBITMAP hSavedBitmap;
748 UserGetInsideRectNC(hWnd, &Rect);
749 hDcMem = CreateCompatibleDC(hDC);
750 hSavedBitmap = SelectObject(hDcMem, hbitmapClose);
751 BitBlt(hDC, Rect.left, Rect.top, GetSystemMetrics(SM_CXSIZE),
752 GetSystemMetrics(SM_CYSIZE), hDcMem,
753 (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) ?
754 GetSystemMetrics(SM_CXSIZE): 0, 0, Down ? NOTSRCCOPY : SRCCOPY);
755 SelectObject(hDcMem, hSavedBitmap);
760 DefWndHandleLButtonDownNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
766 HWND hTopWnd = GetAncestor(hWnd, GA_ROOT);
767 if (SetActiveWindow(hTopWnd) || GetActiveWindow() == hTopWnd)
769 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam);
775 if (GetWindowLong(hWnd, GWL_STYLE) & WS_SYSMENU)
777 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE))
779 HDC hDC = GetWindowDC(hWnd);
780 DefWndDrawSysButton(hWnd, hDC, TRUE);
781 ReleaseDC(hWnd, hDC);
783 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU,
790 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam);
794 SendMessageA(hWnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam);
798 SendMessageA(hWnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam);
803 DefWndTrackMinMaxBox(hWnd, wParam);
814 SendMessageA(hWnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
821 DefWndHandleLButtonDblClkNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
823 /* FIXME: Implement this. */
828 DefWndHandleActiveNC(HWND hWnd, WPARAM wParam)
830 /* FIXME: Implement this. */
835 DefWndSetRedraw(HWND hWnd, WPARAM wParam)
840 DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam)
842 /* Not for child windows. */
843 if (hWnd != (HWND)wParam)
848 switch(LOWORD(lParam))
852 WORD Msg = HIWORD(lParam);
853 if (Msg == WM_LBUTTONDOWN || Msg == WM_MBUTTONDOWN ||
854 Msg == WM_RBUTTONDOWN)
863 HICON hCursor = (HICON)GetClassLong(hWnd, GCL_HCURSOR);
875 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZEWE)));
881 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENS)));
887 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENWSE)));
893 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENESW)));
896 return((LRESULT)SetCursor(LoadCursorW(0, IDC_ARROW)));
900 DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, POINT Pt)
902 /* FIXME: Implement system commands. */
907 DefWndAdjustRect(RECT* Rect, ULONG Style, BOOL Menu, ULONG ExStyle)
909 if (Style & WS_ICONIC)
914 if (UserHasThickFrameStyle(Style, ExStyle))
916 InflateRect(Rect, GetSystemMetrics(SM_CXFRAME),
917 GetSystemMetrics(SM_CYFRAME));
919 else if (UserHasDlgFrameStyle(Style, ExStyle))
921 InflateRect(Rect, GetSystemMetrics(SM_CXDLGFRAME),
922 GetSystemMetrics(SM_CYDLGFRAME));
924 else if (UserHasThinFrameStyle(Style, ExStyle))
926 InflateRect(Rect, GetSystemMetrics(SM_CXBORDER),
927 GetSystemMetrics(SM_CYBORDER));
929 if (Style & WS_CAPTION)
931 Rect->top -= GetSystemMetrics(SM_CYCAPTION) -
932 GetSystemMetrics(SM_CYBORDER);
936 Rect->top -= GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYBORDER);
938 if (Style & WS_VSCROLL)
940 Rect->right += GetSystemMetrics(SM_CXVSCROLL) - 1;
941 if (UserHasAnyFrameStyle(Style, ExStyle))
946 if (Style & WS_HSCROLL)
948 Rect->bottom += GetSystemMetrics(SM_CYHSCROLL) - 1;
949 if (UserHasAnyFrameStyle(Style, ExStyle))
957 DefWndNCCalcSize(HWND hWnd, RECT* Rect)
960 LONG Style = GetClassLongW(hWnd, GCL_STYLE);
961 RECT TmpRect = {0, 0, 0, 0};
963 if (Style & CS_VREDRAW)
965 Result |= WVR_VREDRAW;
967 if (Style & CS_HREDRAW)
969 Result |= WVR_HREDRAW;
972 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE))
974 DefWndAdjustRect(&TmpRect, GetWindowLong(hWnd, GWL_STYLE),
975 FALSE, GetWindowLong(hWnd, GWL_EXSTYLE));
976 Rect->left -= TmpRect.left;
977 Rect->top -= TmpRect.top;
978 Rect->right -= TmpRect.right;
979 Rect->bottom -= TmpRect.bottom;
980 /* FIXME: Adjust if the window has a menu. */
981 Rect->bottom = max(Rect->top, Rect->bottom);
982 Rect->right = max(Rect->left, Rect->right);
988 DefWndHandleWindowPosChanging(HWND hWnd, WINDOWPOS* Pos)
990 /* FIXME: Implement this. */
995 User32DefWindowProc(HWND hWnd,
1005 return(DefWndPaintNC(hWnd, (HRGN)wParam));
1011 Point.x = SLOWORD(lParam);
1012 Point.y = SHIWORD(lParam);
1013 return(DefWndHitTestNC(hWnd, Point));
1016 case WM_NCLBUTTONDOWN:
1018 return(DefWndHandleLButtonDownNC(hWnd, wParam, lParam));
1021 case WM_LBUTTONDBLCLK:
1022 case WM_NCLBUTTONDBLCLK:
1024 return(DefWndHandleLButtonDblClkNC(hWnd, wParam, lParam));
1027 case WM_NCRBUTTONDOWN:
1029 if (wParam == HTCAPTION)
1039 if (hWnd == GetCapture())
1043 Pt.x = SLOWORD(lParam);
1044 Pt.y = SHIWORD(lParam);
1045 ClientToScreen(hWnd, &Pt);
1046 lParam = MAKELPARAM(Pt.x, Pt.y);
1049 SendMessageW(hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam);
1053 SendMessageA (hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam);
1058 case WM_NCRBUTTONUP:
1060 /* Wine does nothing here. */
1064 case WM_CONTEXTMENU:
1066 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1070 SendMessageW(GetParent(hWnd), Msg, wParam, lParam);
1074 SendMessageA(hWnd, WM_CONTEXTMENU, wParam, lParam);
1082 Pt.x = SLOWORD(lParam);
1083 Pt.y = SHIWORD(lParam);
1085 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1087 ScreenToClient(GetParent(hWnd), &Pt);
1090 HitCode = DefWndHitTestNC(hWnd, Pt);
1092 if (HitCode == HTCAPTION || HitCode == HTSYSMENU)
1094 TrackPopupMenu(GetSystemMenu(hWnd, FALSE),
1095 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
1096 Pt.x, Pt.y, 0, hWnd, NULL);
1104 return(DefWndHandleActiveNC(hWnd, wParam));
1121 HDC hDc = BeginPaint(hWnd, &Ps);
1125 if (GetWindowLongW(hWnd, GWL_STYLE) & WS_MINIMIZE &&
1126 (hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON)) != NULL)
1130 GetWindowRect(hWnd, &WindowRect);
1131 x = (WindowRect.right - WindowRect.left -
1132 GetSystemMetrics(SM_CXICON)) / 2;
1133 y = (WindowRect.bottom - WindowRect.top -
1134 GetSystemMetrics(SM_CYICON)) / 2;
1135 DrawIcon(hDc, x, y, hIcon);
1137 EndPaint(hWnd, &Ps);
1145 hRgn = CreateRectRgn(0, 0, 0, 0);
1146 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1148 RedrawWindow(hWnd, NULL, hRgn,
1149 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1158 DefWndSetRedraw(hWnd, wParam);
1164 DestroyWindow(hWnd);
1168 case WM_MOUSEACTIVATE:
1170 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1175 Ret = SendMessageW(GetParent(hWnd), WM_MOUSEACTIVATE,
1180 Ret = SendMessageA(GetParent(hWnd), WM_MOUSEACTIVATE,
1188 return((LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE);
1193 if (LOWORD(lParam) != WA_INACTIVE &&
1194 GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE)
1196 /* Check if the window is minimized. */
1204 if (GetWindowLong(hWnd, GWL_STYLE & WS_CHILD))
1208 return(SendMessageW(GetParent(hWnd), WM_MOUSEWHEEL,
1213 return(SendMessageA(GetParent(hWnd), WM_MOUSEWHEEL,
1221 case WM_ICONERASEBKGND:
1224 HBRUSH hBrush = (HBRUSH)GetClassLongW(hWnd, GCL_HBRBACKGROUND);
1225 GetClipBox((HDC)wParam, &Rect);
1226 FillRect((HDC)wParam, &Rect, hBrush);
1235 /* FIXME: Implement colour controls. */
1239 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1241 if (LOWORD(lParam) < HTLEFT || LOWORD(lParam) > HTBOTTOMRIGHT)
1246 bResult = SendMessageW(GetParent(hWnd), WM_SETCURSOR,
1251 bResult = SendMessageA(GetParent(hWnd), WM_SETCURSOR,
1260 return(DefWndHandleSetCursor(hWnd, wParam, lParam));
1266 Pt.x = SLOWORD(lParam);
1267 Pt.y = SHIWORD(lParam);
1268 return(DefWndHandleSysCommand(hWnd, wParam, Pt));
1271 /* FIXME: Handle key messages. */
1279 /* FIXME: Check for a popup window. */
1280 if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE && !wParam) ||
1281 (!(GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE) && wParam))
1285 ShowWindow(hWnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE);
1291 /* FIXME: Check for a desktop. */
1292 if (GetCapture() == hWnd)
1304 /* FIXME: Implement this. */
1307 case WM_QUERYDROPOBJECT:
1309 if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_ACCEPTFILES)
1316 case WM_QUERYDRAGICON:
1321 hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON);
1324 return((LRESULT)hIcon);
1326 for (Len = 1; Len < 64; Len++)
1328 if ((hIcon = LoadIconW(NULL, MAKEINTRESOURCE(Len))) != NULL)
1330 return((LRESULT)hIcon);
1333 return((LRESULT)LoadIconW(0, IDI_APPLICATION));
1336 /* FIXME: WM_ISACTIVEICON */
1338 case WM_NOTIFYFORMAT:
1340 if (IsWindowUnicode(hWnd))
1342 return(NFR_UNICODE);
1352 INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
1353 HICON hOldIcon = (HICON)GetClassLongW(hWnd, Index);
1354 SetClassLongW(hWnd, Index, lParam);
1355 SetWindowPos(hWnd, 0, 0, 0, 0, 0,
1356 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1357 SWP_NOACTIVATE | SWP_NOZORDER);
1358 return((LRESULT)hOldIcon);
1363 INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
1364 return(GetClassLongW(hWnd, Index));
1371 SendMessageW(GetParent(hWnd), Msg, wParam, lParam);
1375 SendMessageA(GetParent(hWnd), Msg, wParam, lParam);
1384 DefWindowProcA(HWND hWnd,
1390 static LPSTR WindowTextAtom = 0;
1397 CREATESTRUCTA* Cs = (CREATESTRUCTA*)lParam;
1398 if (HIWORD(Cs->lpszName))
1401 (LPSTR)(ULONG)GlobalAddAtomA("USER32!WindowTextAtomA");
1402 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1403 strlen(Cs->lpszName) * sizeof(CHAR));
1404 strcpy(WindowText, Cs->lpszName);
1405 SetPropA(hWnd, WindowTextAtom, WindowText);
1412 return(DefWndNCCalcSize(hWnd, (RECT*)lParam));
1415 case WM_WINDOWPOSCHANGING:
1417 return(DefWndHandleWindowPosChanging(hWnd, (WINDOWPOS*)lParam));
1420 case WM_GETTEXTLENGTH:
1422 if (WindowTextAtom == 0 ||
1423 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1427 return(strlen(WindowText));
1432 if (WindowTextAtom == 0 ||
1433 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1437 ((PSTR)lParam) = '\0';
1441 strncpy((LPSTR)lParam, WindowText, wParam);
1442 return(min(wParam, strlen(WindowText)));
1447 if (WindowTextAtom != 0)
1450 (LPSTR)(DWORD)GlobalAddAtomA("USER32!WindowTextAtomW");
1452 if (WindowTextAtom != 0 &&
1453 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1455 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1457 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1458 strlen((PSTR)lParam) * sizeof(CHAR));
1459 strcpy(WindowText, (PSTR)lParam);
1460 SetPropA(hWnd, WindowTextAtom, WindowText);
1465 if (WindowTextAtom != 0 &&
1466 (WindowText = RemovePropA(hWnd, WindowTextAtom)) == NULL)
1468 RtlFreeHeap(GetProcessHeap(), 0, WindowText);
1470 if (WindowTextAtom != 0)
1472 GlobalDeleteAtom((ATOM)(ULONG)WindowTextAtom);
1474 /* FIXME: Destroy scroll bars here as well. */
1479 Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE);
1487 DefWindowProcW(HWND hWnd,
1493 static LPWSTR WindowTextAtom = 0;
1500 CREATESTRUCTW* Cs = (CREATESTRUCTW*)lParam;
1501 if (HIWORD(Cs->lpszName))
1504 (LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW");
1505 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1506 wcslen(Cs->lpszName) * sizeof(WCHAR));
1507 wcscpy(WindowText, Cs->lpszName);
1508 SetPropW(hWnd, WindowTextAtom, WindowText);
1515 return(DefWndNCCalcSize(hWnd, (RECT*)lParam));
1518 case WM_WINDOWPOSCHANGING:
1520 return(DefWndHandleWindowPosChanging(hWnd, (WINDOWPOS*)lParam));
1523 case WM_GETTEXTLENGTH:
1525 if (WindowTextAtom == 0 ||
1526 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1530 return(wcslen(WindowText));
1535 if (WindowTextAtom == 0 ||
1536 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1540 ((PWSTR)lParam) = '\0';
1544 wcsncpy((PWSTR)lParam, WindowText, wParam);
1545 return(min(wParam, wcslen(WindowText)));
1550 if (WindowTextAtom != 0)
1553 (LPWSTR)(DWORD)GlobalAddAtom(L"USER32!WindowTextAtomW");
1555 if (WindowTextAtom != 0 &&
1556 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1558 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1560 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1561 wcslen((PWSTR)lParam) * sizeof(WCHAR));
1562 wcscpy(WindowText, (PWSTR)lParam);
1563 SetPropW(hWnd, WindowTextAtom, WindowText);
1568 if (WindowTextAtom != 0 &&
1569 (WindowText = RemovePropW(hWnd, WindowTextAtom)) == NULL)
1571 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1573 if (WindowTextAtom != 0)
1575 GlobalDeleteAtom((ATOM)(DWORD)WindowTextAtom);
1577 /* FIXME: Destroy scroll bars here as well. */
1582 Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, TRUE);