1 /* $Id: defwnd.c,v 1.59 2003/08/05 15:41:03 weiden Exp $
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 ******************************************************************/
17 #include <user32/wininternal.h>
26 /* GLOBALS *******************************************************************/
28 static HBITMAP hbSysMenu
;
29 /* TODO: widgets will be cached here.
30 static HBITMAP hbClose;
31 static HBITMAP hbCloseD;
32 static HBITMAP hbMinimize;
33 static HBITMAP hbMinimizeD;
34 static HBITMAP hbRestore;
35 static HBITMAP hbRestoreD;
36 static HBITMAP hbMaximize;
37 static HBITMAP hbScrUp;
38 static HBITMAP hbScrDwn;
39 static HBITMAP hbScrLeft;
40 static HBITMAP hbScrRight;
42 static COLORREF SysColours
[] =
44 RGB(224, 224, 224) /* COLOR_SCROLLBAR */,
45 RGB(58, 110, 165) /* COLOR_BACKGROUND */,
46 RGB(0, 0, 128) /* COLOR_ACTIVECAPTION */,
47 RGB(128, 128, 128) /* COLOR_INACTIVECAPTION */,
48 RGB(192, 192, 192) /* COLOR_MENU */,
49 RGB(192, 192, 192) /* COLOR_WINDOW */,
50 RGB(192, 192, 192) /* COLOR_WINDOWFRAME */,
51 RGB(0, 0, 0) /* COLOR_MENUTEXT */,
52 RGB(0, 0, 0) /* COLOR_WINDOWTEXT */,
53 RGB(255, 255, 255) /* COLOR_CAPTIONTEXT */,
54 RGB(128, 128, 128) /* COLOR_ACTIVEBORDER */,
55 RGB(255, 255, 255) /* COLOR_INACTIVEBORDER */,
56 RGB(255, 255, 232) /* COLOR_APPWORKSPACE */,
57 RGB(224, 224, 224) /* COLOR_HILIGHT */,
58 RGB(0, 0, 128) /* COLOR_HILIGHTTEXT */,
59 RGB(192, 192, 192) /* COLOR_BTNFACE */,
60 RGB(128, 128, 128) /* COLOR_BTNSHADOW */,
61 RGB(192, 192, 192) /* COLOR_GRAYTEXT */,
62 RGB(0, 0, 0) /* COLOR_BTNTEXT */,
63 RGB(192, 192, 192) /* COLOR_INACTIVECAPTIONTEXT */,
64 RGB(255, 255, 255) /* COLOR_BTNHILIGHT */,
65 RGB(32, 32, 32) /* COLOR_3DDKSHADOW */,
66 RGB(192, 192, 192) /* COLOR_3DLIGHT */,
67 RGB(0, 0, 0) /* COLOR_INFOTEXT */,
68 RGB(255, 255, 192) /* COLOR_INFOBK */,
69 RGB(184, 180, 184) /* COLOR_ALTERNATEBTNFACE */,
70 RGB(0, 0, 255) /* COLOR_HOTLIGHT */,
71 RGB(16, 132, 208) /* COLOR_GRADIENTACTIVECAPTION */,
72 RGB(181, 181, 181) /* COLOR_GRADIENTINACTIVECAPTION */,
75 static ATOM AtomInternalPos
;
77 /* Bits in the dwKeyData */
78 #define KEYDATA_ALT 0x2000
80 /* FUNCTIONS *****************************************************************/
82 BOOL
IsMaxBoxActive(HWND hWnd
)
84 ULONG uStyle
= GetWindowLong( hWnd
, GWL_STYLE
);
85 return (uStyle
& WS_MAXIMIZEBOX
);
88 BOOL
IsCloseBoxActive( HWND hWnd
)
90 ULONG uStyle
= GetWindowLong(hWnd
, GWL_STYLE
);
91 return ( uStyle
& WS_SYSMENU
);
94 BOOL
IsMinBoxActive( HWND hWnd
)
96 ULONG uStyle
= GetWindowLong( hWnd
, GWL_STYLE
);
97 return (uStyle
& WS_MINIMIZEBOX
);
100 INT
UIGetFrameSizeX( HWND hWnd
)
102 ULONG uStyle
= GetWindowLong( hWnd
, GWL_STYLE
);
104 if ( uStyle
& WS_THICKFRAME
)
105 return GetSystemMetrics( SM_CXSIZEFRAME
);
107 return GetSystemMetrics( SM_CXFRAME
);
110 INT
UIGetFrameSizeY( HWND hWnd
)
112 ULONG uStyle
= GetWindowLong( hWnd
, GWL_STYLE
);
114 if ( uStyle
& WS_THICKFRAME
)
115 return GetSystemMetrics( SM_CYSIZEFRAME
);
117 return GetSystemMetrics( SM_CYFRAME
);
121 UserSetupInternalPos( VOID
)
124 AtomInternalPos
= GlobalAddAtomA(Str
);
132 GetSysColor(int nIndex
)
134 return SysColours
[nIndex
];
139 GetSysColorPen( int nIndex
)
141 return(CreatePen(PS_SOLID
, 1, SysColours
[nIndex
]));
149 GetSysColorBrush( int nIndex
)
151 return(CreateSolidBrush(SysColours
[nIndex
]));
159 DefFrameProcA( HWND hWnd
,
173 DefFrameProcW(HWND hWnd
,
184 UserGetInternalPos(HWND hWnd
)
187 lpPos
= (PINTERNALPOS
)GetPropA(hWnd
, (LPSTR
)(DWORD
)AtomInternalPos
);
192 DefWndRedrawIconTitle(HWND hWnd
)
194 PINTERNALPOS lpPos
= (PINTERNALPOS
)GetPropA(hWnd
,
195 (LPSTR
)(DWORD
)AtomInternalPos
);
198 if (lpPos
->IconTitle
!= NULL
)
200 SendMessageA(lpPos
->IconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
201 InvalidateRect(lpPos
->IconTitle
, NULL
, TRUE
);
210 UserHasMenu(HWND hWnd
, ULONG Style
)
212 return(!(Style
& WS_CHILD
) && GetWindowLong(hWnd
, GWL_ID
) != 0);
217 UserHasAnyFrameStyle(ULONG Style
, ULONG ExStyle
)
219 return((Style
& (WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
)) ||
220 (ExStyle
& WS_EX_DLGMODALFRAME
) ||
221 (!(Style
& (WS_CHILD
| WS_POPUP
))));
226 UserHasDlgFrameStyle(ULONG Style
, ULONG ExStyle
)
228 return((ExStyle
& WS_EX_DLGMODALFRAME
) ||
229 ((Style
& WS_DLGFRAME
) && (!(Style
& WS_THICKFRAME
))));
234 UserHasThickFrameStyle(ULONG Style
, ULONG ExStyle
)
236 return((Style
& WS_THICKFRAME
) &&
237 (!((Style
& (WS_DLGFRAME
| WS_BORDER
)) == WS_DLGFRAME
)));
242 UserHasThinFrameStyle(ULONG Style
, ULONG ExStyle
)
244 return((Style
& WS_BORDER
) ||
245 (!(Style
& (WS_CHILD
| WS_POPUP
))));
250 UserHasBigFrameStyle(ULONG Style
, ULONG ExStyle
)
252 return((Style
& (WS_THICKFRAME
| WS_DLGFRAME
)) ||
253 (ExStyle
& WS_EX_DLGMODALFRAME
));
256 void UserGetInsideRectNC( HWND hWnd
, RECT
*rect
)
262 Style
= GetWindowLong(hWnd
, GWL_STYLE
);
263 ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
264 GetWindowRect(hWnd
, &WindowRect
);
265 rect
->top
= rect
->left
= 0;
266 rect
->right
= WindowRect
.right
- WindowRect
.left
;
267 rect
->bottom
= WindowRect
.bottom
- WindowRect
.top
;
269 if (Style
& WS_ICONIC
)
274 /* Remove frame from rectangle */
275 if (UserHasThickFrameStyle(Style
, ExStyle
))
277 InflateRect( rect
, -GetSystemMetrics(SM_CXFRAME
),
278 -GetSystemMetrics(SM_CYFRAME
) );
282 if (UserHasDlgFrameStyle(Style
, ExStyle
))
284 InflateRect( rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
285 -GetSystemMetrics(SM_CYDLGFRAME
));
286 /* FIXME: this isn't in NC_AdjustRect? why not? */
287 if (ExStyle
& WS_EX_DLGMODALFRAME
)
288 InflateRect( rect
, -1, 0 );
292 if (UserHasThinFrameStyle(Style
, ExStyle
))
294 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
295 -GetSystemMetrics(SM_CYBORDER
));
301 VOID
UserDrawSysMenuButton( HWND hWnd
, HDC hDC
, BOOL down
)
305 HBITMAP hSavedBitmap
;
307 hbSysMenu
= LoadBitmap(0, MAKEINTRESOURCE(OBM_CLOSE
));
308 UserGetInsideRectNC(hWnd
, &Rect
);
309 hDcMem
= CreateCompatibleDC(hDC
);
310 hSavedBitmap
= SelectObject(hDcMem
, hbSysMenu
);
311 BitBlt(hDC
, Rect
.left
+ 2, Rect
.top
+
313 (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
) ?
314 GetSystemMetrics(SM_CXSIZE
): 0, 0, SRCCOPY
);
315 SelectObject(hDcMem
, hSavedBitmap
);
319 /* FIXME: Cache bitmaps, then just bitblt instead of calling DFC() (and
320 wasting precious CPU cycles) every time */
322 static void UserDrawCaptionButton( HWND hWnd
, HDC hDC
, BOOL bDown
, ULONG Type
)
326 INT iBmpWidth
= GetSystemMetrics(SM_CXSIZE
) - 2;
327 INT iBmpHeight
= GetSystemMetrics(SM_CYSIZE
) - 4;
329 INT OffsetX
= UIGetFrameSizeX( hWnd
);
330 INT OffsetY
= UIGetFrameSizeY( hWnd
);
332 if(!(GetWindowLong( hWnd
, GWL_STYLE
) & WS_SYSMENU
))
337 GetWindowRect( hWnd
, &rect
);
339 rect
.right
= rect
.right
- rect
.left
;
340 rect
.bottom
= rect
.bottom
- rect
.top
;
341 rect
.left
= rect
.top
= 0;
345 case DFCS_CAPTIONMIN
:
347 if ((GetWindowLong( hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
) == TRUE
)
348 return; /* ToolWindows don't have min/max buttons */
351 rect
.right
- OffsetX
- (iBmpWidth
*3) - 5,
353 rect
.right
- (iBmpWidth
* 2) - OffsetX
- 5,
354 rect
.top
+ iBmpHeight
+ OffsetY
+ 2 );
355 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
356 DFCS_CAPTIONMIN
| (bDown
? DFCS_PUSHED
: 0) |
357 (IsMinBoxActive(hWnd
) ? 0 : DFCS_INACTIVE
) );
360 case DFCS_CAPTIONMAX
:
362 if ((GetWindowLong( hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
) == TRUE
)
363 return; /* ToolWindows don't have min/max buttons */
365 rect
.right
- OffsetX
- (iBmpWidth
*2) - 5,
367 rect
.right
- iBmpWidth
- OffsetX
- 5,
368 rect
.top
+ iBmpHeight
+ OffsetY
+ 2 );
370 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
371 (IsZoomed(hWnd
) ? DFCS_CAPTIONRESTORE
: DFCS_CAPTIONMAX
) |
372 (bDown
? DFCS_PUSHED
: 0) |
373 (IsMaxBoxActive(hWnd
) ? 0 : DFCS_INACTIVE
) );
376 case DFCS_CAPTIONCLOSE
:
379 rect
.right
- OffsetX
- iBmpWidth
- 3,
381 rect
.right
- OffsetX
- 3,
382 rect
.top
+ iBmpHeight
+ OffsetY
+ 2 );
384 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
386 (bDown
? DFCS_PUSHED
: 0) |
387 (IsCloseBoxActive(hWnd
) ? 0 : DFCS_INACTIVE
)) );
392 static void UserDrawCaptionNC( HDC hDC
, RECT
*rect
, HWND hWnd
,
393 DWORD style
, BOOL active
)
397 /* FIXME: Implement and Use DrawCaption() */
398 SelectObject( hDC
, GetSysColorBrush(active
? COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
) );
400 PatBlt(hDC
,rect
->left
+ GetSystemMetrics(SM_CXFRAME
), rect
->top
+
401 GetSystemMetrics(SM_CYFRAME
), rect
->right
- (GetSystemMetrics(SM_CXFRAME
) * 2), (rect
->top
+
402 GetSystemMetrics(SM_CYCAPTION
)) - 1, PATCOPY
);
404 if (style
& WS_SYSMENU
)
406 UserDrawSysMenuButton( hWnd
, hDC
, FALSE
);
407 r
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
408 UserDrawCaptionButton( hWnd
, hDC
, FALSE
, DFCS_CAPTIONCLOSE
);
409 r
.right
-= GetSystemMetrics(SM_CXSMSIZE
) + 1;
410 UserDrawCaptionButton( hWnd
, hDC
, FALSE
, DFCS_CAPTIONMIN
);
411 UserDrawCaptionButton( hWnd
, hDC
, FALSE
, DFCS_CAPTIONMAX
);
413 if (GetWindowTextW( hWnd
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]) ))
415 NONCLIENTMETRICSW nclm
;
416 HFONT hFont
, hOldFont
;
418 nclm
.cbSize
= sizeof(nclm
);
419 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
420 SetTextColor(hDC
, SysColours
[ active
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
]);
421 SetBkMode( hDC
, TRANSPARENT
);
422 if (style
& WS_EX_TOOLWINDOW
)
423 hFont
= CreateFontIndirectW(&nclm
.lfSmCaptionFont
);
425 hFont
= CreateFontIndirectW(&nclm
.lfCaptionFont
);
426 hOldFont
= SelectObject(hDC
, hFont
);
427 TextOutW(hDC
, r
.left
+ (GetSystemMetrics(SM_CXDLGFRAME
) * 2), rect
->top
+ (nclm
.lfCaptionFont
.lfHeight
/ 2), buffer
, wcslen(buffer
));
428 DeleteObject (SelectObject (hDC
, hOldFont
));
434 UserDrawFrameNC(HWND hWnd
, RECT
* rect
, BOOL dlgFrame
, BOOL active
)
436 HDC hDC
= GetWindowDC(hWnd
);
437 SelectObject( hDC
, GetSysColorBrush(COLOR_WINDOW
) );
438 DrawEdge(hDC
, rect
,EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
442 void SCROLL_DrawScrollBar (HWND hWnd
, HDC hDC
, INT nBar
, BOOL arrows
, BOOL interior
);
445 DefWndDoPaintNC(HWND hWnd
, HRGN clip
)
453 Active
= GetWindowLongW(hWnd
, GWL_STYLE
) & WIN_NCACTIVATED
;
454 Style
= GetWindowLong(hWnd
, GWL_STYLE
);
455 ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
457 hDC
= GetDCEx(hWnd
, (clip
> (HRGN
)1) ? clip
: 0, DCX_USESTYLE
| DCX_WINDOW
|
458 ((clip
> (HRGN
)1) ? (DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
) : 0));
464 /* FIXME: Test whether we need to draw anything at all. */
466 GetWindowRect(hWnd
, &rect
);
467 rect
.right
= rect
.right
- rect
.left
;
468 rect
.bottom
= rect
.bottom
- rect
.top
;
469 rect
.top
= rect
.left
= 0;
470 SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
471 if (UserHasThickFrameStyle(Style
, ExStyle
))
473 UserDrawFrameNC(hWnd
, &rect
, FALSE
, Active
);
475 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
477 UserDrawFrameNC(hWnd
, &rect
, TRUE
, Active
);
479 if (Style
& WS_CAPTION
)
482 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
);
483 rect
.top
+= GetSystemMetrics(SM_CYSIZE
) +
484 GetSystemMetrics(SM_CYBORDER
);
485 UserDrawCaptionNC(hDC
, &r
, hWnd
, Style
, Active
);
489 if (UserHasMenu(hWnd
, Style
))
492 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYMENU
);
494 rect
.top
+= MenuDrawMenuBar(hDC
, &r
, hWnd
, FALSE
);
497 /* Draw scrollbars */
498 if (Style
& WS_VSCROLL
)
499 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_VERT
, TRUE
, TRUE
);
500 if (Style
& WS_HSCROLL
)
501 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_HORZ
, TRUE
, TRUE
);
503 /* FIXME: Draw size box.*/
505 ReleaseDC(hWnd
, hDC
);
510 DefWndPaintNC(HWND hWnd
, HRGN clip
)
512 if (IsWindowVisible(hWnd
))
516 DefWndRedrawIconTitle(hWnd
);
520 DefWndDoPaintNC(hWnd
, clip
);
528 DefWndHitTestNC(HWND hWnd
, POINT Point
)
531 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
532 ULONG ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
534 GetWindowRect(hWnd
, &WindowRect
);
535 if (!PtInRect(&WindowRect
, Point
))
539 if (Style
& WS_MINIMIZE
)
543 if (UserHasThickFrameStyle(Style
, ExStyle
))
545 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXFRAME
),
546 -GetSystemMetrics(SM_CYFRAME
));
547 if (!PtInRect(&WindowRect
, Point
))
549 if (Point
.y
< WindowRect
.top
)
551 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
555 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
561 if (Point
.y
>= WindowRect
.bottom
)
563 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
565 return(HTBOTTOMLEFT
);
567 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
569 return(HTBOTTOMRIGHT
);
573 if (Point
.x
< WindowRect
.left
)
575 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
579 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
581 return(HTBOTTOMLEFT
);
585 if (Point
.x
>= WindowRect
.right
)
587 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
591 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
593 return(HTBOTTOMRIGHT
);
601 if (UserHasDlgFrameStyle(Style
, ExStyle
))
603 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXDLGFRAME
),
604 -GetSystemMetrics(SM_CYDLGFRAME
));
606 else if (UserHasThinFrameStyle(Style
, ExStyle
))
608 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
609 -GetSystemMetrics(SM_CYBORDER
));
611 if (!PtInRect(&WindowRect
, Point
))
617 if ((Style
& WS_CAPTION
) == WS_CAPTION
)
619 WindowRect
.top
+= (GetSystemMetrics(SM_CYCAPTION
) -
620 GetSystemMetrics(SM_CYBORDER
));
621 if (!PtInRect(&WindowRect
, Point
))
623 if ((Style
& WS_SYSMENU
) && !(ExStyle
& WS_EX_TOOLWINDOW
))
625 WindowRect
.left
+= GetSystemMetrics(SM_CXSIZE
);
626 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
628 if (Point
.x
<= WindowRect
.left
)
632 if (WindowRect
.right
<= Point
.x
)
637 if (Style
& WS_MAXIMIZEBOX
|| Style
& WS_MINIMIZEBOX
)
639 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) - 2;
641 if (Point
.x
>= WindowRect
.right
)
646 if (Style
& WS_MINIMIZEBOX
)
648 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) - 2;
650 if (Point
.x
>= WindowRect
.right
)
658 ScreenToClient(hWnd
, &Point
);
659 GetClientRect(hWnd
, &WindowRect
);
661 if (PtInRect(&WindowRect
, Point
))
666 if (Style
& WS_VSCROLL
)
668 WindowRect
.right
+= GetSystemMetrics(SM_CXVSCROLL
);
669 if (PtInRect(&WindowRect
, Point
))
675 if (Style
& WS_HSCROLL
)
677 WindowRect
.bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
678 if (PtInRect(&WindowRect
, Point
))
680 if ((Style
& WS_VSCROLL
) &&
681 (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXVSCROLL
))))
689 if (UserHasMenu(hWnd
, Style
))
691 if (Point
.y
< 0 && Point
.x
>= 0 && Point
.x
<= WindowRect
.right
)
701 DefWndHandleLButtonDownNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
707 HWND hTopWnd
= GetAncestor(hWnd
, GA_ROOT
);
708 if (SetActiveWindow(hTopWnd
) || GetActiveWindow() == hTopWnd
)
710 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOVE
+ HTCAPTION
, lParam
);
716 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_SYSMENU
)
718 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
720 HDC hDC
= GetWindowDC(hWnd
);
721 UserDrawSysMenuButton(hWnd
, hDC
, TRUE
);
722 ReleaseDC(hWnd
, hDC
);
724 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
+ HTSYSMENU
,
731 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
, lParam
);
736 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_HSCROLL
+ HTHSCROLL
, lParam
);
741 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_VSCROLL
+ HTVSCROLL
, lParam
);
746 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), IsMinBoxActive(hWnd
), DFCS_CAPTIONMIN
);
751 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), IsMaxBoxActive(hWnd
), DFCS_CAPTIONMAX
);
756 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), TRUE
, DFCS_CAPTIONCLOSE
);
768 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_SIZE
+ wParam
- 2, lParam
);
777 DefWndHandleLButtonDblClkNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
785 DefWndHandleLButtonUpNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
787 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), FALSE
, DFCS_CAPTIONMIN
);
788 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), FALSE
, DFCS_CAPTIONMAX
);
789 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), FALSE
, DFCS_CAPTIONCLOSE
);
794 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
799 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
804 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
813 DefWndHandleActiveNC(HWND hWnd
, WPARAM wParam
)
821 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
828 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
830 /* Not for child windows. */
831 if (hWnd
!= (HWND
)wParam
)
836 switch(LOWORD(lParam
))
840 WORD Msg
= HIWORD(lParam
);
841 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
842 Msg
== WM_RBUTTONDOWN
)
851 HICON hCursor
= (HICON
)GetClassLong(hWnd
, GCL_HCURSOR
);
863 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
869 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
875 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
881 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
884 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
888 DefWndStartSizeMove(HWND hWnd
, WPARAM wParam
, POINT
*capturePoint
)
894 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
896 GetWindowRect(hWnd
, &rectWindow
);
898 if ((wParam
& 0xfff0) == SC_MOVE
)
900 /* Move pointer at the center of the caption */
902 UserGetInsideRectNC(hWnd
, &rect
);
903 if (Style
& WS_SYSMENU
)
904 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
905 if (Style
& WS_MINIMIZEBOX
)
906 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
907 if (Style
& WS_MAXIMIZEBOX
)
908 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
909 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
910 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
918 GetMessage(&msg
, NULL
, 0, 0);
922 hittest
= DefWndHitTestNC(hWnd
, msg
.pt
);
923 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
935 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
936 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
940 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
941 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
945 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
946 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
950 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
951 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
954 case VK_ESCAPE
: return 0;
960 SetCursorPos( pt
.x
, pt
.y
);
961 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
));
965 #define ON_LEFT_BORDER(hit) \
966 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
967 #define ON_RIGHT_BORDER(hit) \
968 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
969 #define ON_TOP_BORDER(hit) \
970 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
971 #define ON_BOTTOM_BORDER(hit) \
972 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
975 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
976 ULONG width
, ULONG height
, DWORD rop
)
978 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
979 PatBlt( hdc
, rect
->left
, rect
->top
,
980 rect
->right
- rect
->left
- width
, height
, rop
);
981 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
982 rect
->bottom
- rect
->top
- height
, rop
);
983 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
984 rect
->right
- rect
->left
- width
, -height
, rop
);
985 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
986 rect
->bottom
- rect
->top
- height
, rop
);
987 SelectObject( hdc
, hbrush
);
991 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
995 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
),
996 GetSystemMetrics(SM_CYFRAME
), PATINVERT
);
998 else DrawFocusRect( hdc
, rect
);
1002 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
1005 RECT sizingRect
, mouseRect
, origRect
;
1007 LONG hittest
= (LONG
)(wParam
& 0x0f);
1008 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1009 POINT minTrack
, maxTrack
;
1010 POINT capturePoint
, pt
;
1011 ULONG Style
= GetWindowLong(hwnd
, GWL_STYLE
);
1012 ULONG ExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
1013 BOOL thickframe
= UserHasThickFrameStyle(Style
, ExStyle
);
1014 BOOL iconic
= Style
& WS_MINIMIZE
;
1016 DWORD dwPoint
= GetMessagePos();
1017 BOOL DragFullWindows
= FALSE
;
1020 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1022 pt
.x
= SLOWORD(dwPoint
);
1023 pt
.y
= SHIWORD(dwPoint
);
1026 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
))
1031 if ((wParam
& 0xfff0) == SC_MOVE
)
1035 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
1048 if (hittest
&& hittest
!= HTSYSMENU
)
1055 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
1064 if (Style
& WS_CHILD
)
1066 hWndParent
= GetParent(hwnd
);
1069 /* Get min/max info */
1071 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1072 GetWindowRect(hwnd
, &sizingRect
);
1073 origRect
= sizingRect
;
1074 if (Style
& WS_CHILD
)
1076 GetClientRect(hWndParent
, &mouseRect
);
1080 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
),
1081 GetSystemMetrics(SM_CYSCREEN
));
1083 if (ON_LEFT_BORDER(hittest
))
1085 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1086 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1088 else if (ON_RIGHT_BORDER(hittest
))
1090 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1091 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1093 if (ON_TOP_BORDER(hittest
))
1095 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1096 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1098 else if (ON_BOTTOM_BORDER(hittest
))
1100 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1101 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1103 if (Style
& WS_CHILD
)
1105 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
1107 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1109 if (GetCapture() != hwnd
) SetCapture( hwnd
);
1111 if (Style
& WS_CHILD
)
1113 /* Retrieve a default cache DC (without using the window style) */
1114 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
1121 if( iconic
) /* create a cursor for dragging */
1123 HICON hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICON
);
1124 if(!hIcon
) hIcon
= (HICON
)SendMessage( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1125 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
1126 if( !hDragCursor
) iconic
= FALSE
;
1129 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
1130 if( !iconic
&& !DragFullWindows
)
1132 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1139 GetMessage(&msg
, 0, 0, 0);
1141 /* Exit on button-up, Return, or Esc */
1142 if ((msg
.message
== WM_LBUTTONUP
) ||
1143 ((msg
.message
== WM_KEYDOWN
) &&
1144 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1146 if (msg
.message
== WM_PAINT
)
1148 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1149 UpdateWindow( msg
.hwnd
);
1150 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1154 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1155 continue; /* We are not interested in other messages */
1159 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1161 case VK_UP
: pt
.y
-= 8; break;
1162 case VK_DOWN
: pt
.y
+= 8; break;
1163 case VK_LEFT
: pt
.x
-= 8; break;
1164 case VK_RIGHT
: pt
.x
+= 8; break;
1167 pt
.x
= max( pt
.x
, mouseRect
.left
);
1168 pt
.x
= min( pt
.x
, mouseRect
.right
);
1169 pt
.y
= max( pt
.y
, mouseRect
.top
);
1170 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1172 dx
= pt
.x
- capturePoint
.x
;
1173 dy
= pt
.y
- capturePoint
.y
;
1181 if( iconic
) /* ok, no system popup tracking */
1183 hOldCursor
= SetCursor(hDragCursor
);
1185 WinPosShowIconTitle( hwnd
, FALSE
);
1189 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1192 RECT newRect
= sizingRect
;
1193 WPARAM wpSizingHit
= 0;
1195 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1196 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1197 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1198 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1199 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1200 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1203 /* determine the hit location */
1204 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1205 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1206 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1210 if(!DragFullWindows
)
1211 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
1213 /* To avoid any deadlocks, all the locks on the windows
1214 structures must be suspended before the SetWindowPos */
1215 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1216 newRect
.right
- newRect
.left
,
1217 newRect
.bottom
- newRect
.top
,
1218 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1221 sizingRect
= newRect
;
1229 if( moved
) /* restore cursors, show icon title later on */
1231 ShowCursor( FALSE
);
1232 SetCursor( hOldCursor
);
1234 DestroyCursor( hDragCursor
);
1236 else if(!DragFullWindows
)
1237 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1239 if (Style
& WS_CHILD
)
1240 ReleaseDC( hWndParent
, hdc
);
1242 ReleaseDC( 0, hdc
);
1244 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1245 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1247 /* window moved or resized */
1250 /* if the moving/resizing isn't canceled call SetWindowPos
1251 * with the new position or the new size of the window
1253 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1255 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1256 if(!DragFullWindows
)
1257 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1258 sizingRect
.right
- sizingRect
.left
,
1259 sizingRect
.bottom
- sizingRect
.top
,
1260 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1262 else { /* restore previous size/position */
1264 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1265 origRect
.right
- origRect
.left
,
1266 origRect
.bottom
- origRect
.top
,
1267 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1271 if( IsWindow(hwnd
) )
1272 if( Style
& WS_MINIMIZE
)
1274 /* Single click brings up the system menu when iconized */
1278 if( Style
& WS_SYSMENU
)
1279 SendMessageA( hwnd
, WM_SYSCOMMAND
,
1280 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1282 else WinPosShowIconTitle( hwnd
, TRUE
);
1288 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
1290 switch (wParam
& 0xfff0)
1294 DefWndDoSizeMove(hWnd
, wParam
);
1297 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
1300 MenuTrackMouseMenuBar(hWnd
, wParam
, Pt
);
1303 MenuTrackKbdMenuBar(hWnd
, wParam
, Pt
.x
);
1306 /* FIXME: Implement */
1316 DefWndAdjustRect(RECT
* Rect
, ULONG Style
, BOOL Menu
, ULONG ExStyle
)
1318 if (Style
& WS_ICONIC
)
1323 if (UserHasThickFrameStyle(Style
, ExStyle
))
1325 InflateRect(Rect
, GetSystemMetrics(SM_CXFRAME
),
1326 GetSystemMetrics(SM_CYFRAME
));
1328 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
1330 InflateRect(Rect
, GetSystemMetrics(SM_CXDLGFRAME
),
1331 GetSystemMetrics(SM_CYDLGFRAME
));
1333 else if (UserHasThinFrameStyle(Style
, ExStyle
))
1335 InflateRect(Rect
, GetSystemMetrics(SM_CXBORDER
),
1336 GetSystemMetrics(SM_CYBORDER
));
1338 if (Style
& WS_CAPTION
)
1340 Rect
->top
-= (GetSystemMetrics(SM_CYCAPTION
) -
1341 GetSystemMetrics(SM_CYBORDER
)) + 1;
1345 Rect
->top
-= GetSystemMetrics(SM_CYMENU
) + GetSystemMetrics(SM_CYBORDER
);
1347 if (Style
& WS_VSCROLL
)
1349 Rect
->right
+= GetSystemMetrics(SM_CXVSCROLL
) - 1;
1350 if (UserHasAnyFrameStyle(Style
, ExStyle
))
1355 if (Style
& WS_HSCROLL
)
1357 Rect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
) - 1;
1358 if (UserHasAnyFrameStyle(Style
, ExStyle
))
1367 DefWndNCCalcSize(HWND hWnd
, RECT
* Rect
)
1370 LONG Style
= GetClassLongW(hWnd
, GCL_STYLE
);
1371 RECT TmpRect
= {0, 0, 0, 0};
1373 if (Style
& CS_VREDRAW
)
1375 Result
|= WVR_VREDRAW
;
1377 if (Style
& CS_HREDRAW
)
1379 Result
|= WVR_HREDRAW
;
1382 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1384 DefWndAdjustRect(&TmpRect
, GetWindowLong(hWnd
, GWL_STYLE
),
1385 FALSE
, GetWindowLong(hWnd
, GWL_EXSTYLE
));
1386 Rect
->left
-= TmpRect
.left
;
1387 Rect
->top
-= TmpRect
.top
;
1388 Rect
->right
-= TmpRect
.right
;
1389 Rect
->bottom
-= TmpRect
.bottom
;
1390 if (UserHasMenu(hWnd
, GetWindowLong(hWnd
, GWL_EXSTYLE
)))
1392 Rect
->top
+= MenuGetMenuBarHeight(hWnd
,
1393 Rect
->right
- Rect
->left
,
1397 Rect
->bottom
= max(Rect
->top
, Rect
->bottom
);
1398 Rect
->right
= max(Rect
->left
, Rect
->right
);
1405 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
1413 User32DefWindowProc(HWND hWnd
,
1423 return(DefWndPaintNC(hWnd
, (HRGN
)wParam
));
1425 case WM_WINDOWPOSCHANGING
:
1427 DbgPrint("WM_WINDOWPOSCHANGING\n\n");
1433 Point
.x
= SLOWORD(lParam
);
1434 Point
.y
= SHIWORD(lParam
);
1435 return(DefWndHitTestNC(hWnd
, Point
));
1438 case WM_NCLBUTTONDOWN
:
1440 return(DefWndHandleLButtonDownNC(hWnd
, wParam
, lParam
));
1443 case WM_NCLBUTTONUP
:
1445 return(DefWndHandleLButtonUpNC(hWnd
, wParam
, lParam
));
1448 case WM_LBUTTONDBLCLK
:
1449 case WM_NCLBUTTONDBLCLK
:
1451 return(DefWndHandleLButtonDblClkNC(hWnd
, wParam
, lParam
));
1454 case WM_NCRBUTTONDOWN
:
1456 if (wParam
== HTCAPTION
)
1469 if (hWnd
== GetCapture())
1473 Pt
.x
= SLOWORD(lParam
);
1474 Pt
.y
= SHIWORD(lParam
);
1475 ClientToScreen(hWnd
, &Pt
);
1476 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1479 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1483 SendMessageA (hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1488 case WM_NCRBUTTONUP
:
1490 /* Wine does nothing here. */
1494 case WM_CONTEXTMENU
:
1496 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1500 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1504 SendMessageA(hWnd
, WM_CONTEXTMENU
, wParam
, lParam
);
1512 Pt
.x
= SLOWORD(lParam
);
1513 Pt
.y
= SHIWORD(lParam
);
1515 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1517 ScreenToClient(GetParent(hWnd
), &Pt
);
1520 HitCode
= DefWndHitTestNC(hWnd
, Pt
);
1522 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1524 TrackPopupMenu(GetSystemMenu(hWnd
, FALSE
),
1525 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
1526 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1534 return(DefWndHandleActiveNC(hWnd
, wParam
));
1551 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1555 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1556 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1560 GetWindowRect(hWnd
, &WindowRect
);
1561 x
= (WindowRect
.right
- WindowRect
.left
-
1562 GetSystemMetrics(SM_CXICON
)) / 2;
1563 y
= (WindowRect
.bottom
- WindowRect
.top
-
1564 GetSystemMetrics(SM_CYICON
)) / 2;
1565 DrawIcon(hDC
, x
, y
, hIcon
);
1567 if (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_CLIENTEDGE
)
1570 GetClientRect(hWnd
, &WindowRect
);
1571 DrawEdge(hDC
, &WindowRect
, EDGE_SUNKEN
, BF_RECT
);
1573 EndPaint(hWnd
, &Ps
);
1581 hRgn
= CreateRectRgn(0, 0, 0, 0);
1582 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1584 RedrawWindow(hWnd
, NULL
, hRgn
,
1585 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1594 DefWndSetRedraw(hWnd
, wParam
);
1600 DestroyWindow(hWnd
);
1604 case WM_MOUSEACTIVATE
:
1606 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1611 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1616 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1624 return((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1629 /* Check if the window is minimized. */
1630 if (LOWORD(lParam
) != WA_INACTIVE
&&
1631 !(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1640 if (GetWindowLong(hWnd
, GWL_STYLE
& WS_CHILD
))
1644 return(SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1649 return(SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1657 case WM_ICONERASEBKGND
:
1661 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1662 GetClipBox((HDC
)wParam
, &Rect
);
1663 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1672 /* FIXME: Implement colour controls. */
1676 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1678 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1683 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1688 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1697 return(DefWndHandleSetCursor(hWnd
, wParam
, lParam
));
1703 Pt
.x
= SLOWORD(lParam
);
1704 Pt
.y
= SHIWORD(lParam
);
1705 return(DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1708 /* FIXME: Handle key messages. */
1716 /* FIXME: Not done correctly */
1717 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
&& !wParam
) ||
1718 (!(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
) && wParam
))
1722 ShowWindow(hWnd
, wParam
? SW_SHOWNA
: SW_HIDE
);
1728 /* FIXME: Check for a desktop. */
1729 if (GetCapture() == hWnd
)
1741 /* FIXME: Implement this. */
1744 case WM_QUERYDROPOBJECT
:
1746 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1753 case WM_QUERYDRAGICON
:
1758 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1761 return((LRESULT
)hIcon
);
1763 for (Len
= 1; Len
< 64; Len
++)
1765 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCE(Len
))) != NULL
)
1767 return((LRESULT
)hIcon
);
1770 return((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1773 /* FIXME: WM_ISACTIVEICON */
1775 case WM_NOTIFYFORMAT
:
1777 if (IsWindowUnicode(hWnd
))
1779 return(NFR_UNICODE
);
1789 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1790 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1791 SetClassLongW(hWnd
, Index
, lParam
);
1792 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1793 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1794 SWP_NOACTIVATE
| SWP_NOZORDER
);
1795 return((LRESULT
)hOldIcon
);
1800 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1801 return(GetClassLongW(hWnd
, Index
));
1808 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1812 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1818 if (HIWORD(lParam
) & KEYDATA_ALT
)
1820 if (wParam
== VK_F4
) /* Try to close the window */
1822 //HWND hTopWnd = GetAncestor(hWnd, GA_ROOT);
1823 HWND hTopWnd
= hWnd
;
1824 if (!(GetClassLongW(hTopWnd
, GCL_STYLE
) & CS_NOCLOSE
))
1828 PostMessageW(hTopWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1832 PostMessageA(hTopWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1844 DefWindowProcA(HWND hWnd
,
1850 static LPSTR WindowTextAtom
= 0;
1857 CREATESTRUCTA
* Cs
= (CREATESTRUCTA
*)lParam
;
1858 if (HIWORD(Cs
->lpszName
))
1860 if (0 == WindowTextAtom
)
1863 (LPSTR
)(ULONG
)GlobalAddAtomA("USER32!WindowTextAtomA");
1865 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1866 strlen(Cs
->lpszName
) * sizeof(CHAR
));
1867 strcpy(WindowText
, Cs
->lpszName
);
1868 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1875 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1878 case WM_WINDOWPOSCHANGING
:
1880 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1883 case WM_GETTEXTLENGTH
:
1885 if (WindowTextAtom
== 0 ||
1886 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1890 return(strlen(WindowText
));
1895 if (WindowTextAtom
== 0 ||
1896 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1900 *((PSTR
)lParam
) = '\0';
1904 strncpy((LPSTR
)lParam
, WindowText
, wParam
);
1905 return(min(wParam
, strlen(WindowText
)));
1910 if (0 == WindowTextAtom
)
1913 (LPSTR
)(DWORD
)GlobalAddAtomA("USER32!WindowTextAtomW");
1915 if (WindowTextAtom
!= 0 &&
1916 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1918 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
1920 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1921 strlen((PSTR
)lParam
) * sizeof(CHAR
));
1922 strcpy(WindowText
, (PSTR
)lParam
);
1923 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1924 if (0 != (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
))
1926 DefWndPaintNC(hWnd
, (HRGN
) 1);
1928 Result
= (LPARAM
) TRUE
;
1934 if (WindowTextAtom
!= 0 &&
1935 (WindowText
= RemovePropA(hWnd
, WindowTextAtom
)) == NULL
)
1937 RtlFreeHeap(GetProcessHeap(), 0, WindowText
);
1943 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1952 DefWindowProcW(HWND hWnd
,
1958 static LPWSTR WindowTextAtom
= 0;
1965 CREATESTRUCTW
* Cs
= (CREATESTRUCTW
*)lParam
;
1966 if (HIWORD(Cs
->lpszName
))
1968 if (0 == WindowTextAtom
)
1971 (LPWSTR
)(DWORD
)GlobalAddAtomW(L
"USER32!WindowTextAtomW");
1973 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1974 wcslen(Cs
->lpszName
) * sizeof(WCHAR
));
1975 wcscpy(WindowText
, Cs
->lpszName
);
1976 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
1983 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1986 case WM_WINDOWPOSCHANGING
:
1988 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1991 case WM_GETTEXTLENGTH
:
1993 if (WindowTextAtom
== 0 ||
1994 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
1998 return(wcslen(WindowText
));
2003 if (WindowTextAtom
== 0 ||
2004 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2008 ((PWSTR
)lParam
) = '\0';
2012 wcsncpy((PWSTR
)lParam
, WindowText
, wParam
);
2013 return(min(wParam
, wcslen(WindowText
)));
2018 if (WindowTextAtom
!= 0)
2021 (LPWSTR
)(DWORD
)GlobalAddAtom(L
"USER32!WindowTextAtomW");
2023 if (WindowTextAtom
!= 0 &&
2024 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2026 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
2028 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2029 wcslen((PWSTR
)lParam
) * sizeof(WCHAR
));
2030 wcscpy(WindowText
, (PWSTR
)lParam
);
2031 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
2032 if (0 != (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
))
2034 DefWndPaintNC(hWnd
, (HRGN
) 1);
2036 Result
= (LPARAM
) TRUE
;
2042 if (WindowTextAtom
!= 0 &&
2043 (WindowText
= RemovePropW(hWnd
, WindowTextAtom
)) == NULL
)
2045 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
2051 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);