1 /* $Id: defwnd.c,v 1.57 2003/07/27 11:54:41 dwelch 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 UserDrawCloseButton ( HWND hWnd
, HDC hDC
, BOOL bDown
)
326 BOOL bToolWindow
= GetWindowLongA( hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
;
327 INT iBmpWidth
= (bToolWindow
? GetSystemMetrics(SM_CXSMSIZE
) :
328 GetSystemMetrics(SM_CXSIZE
)) - 2;
329 INT iBmpHeight
= (bToolWindow
? GetSystemMetrics(SM_CYSMSIZE
) :
330 GetSystemMetrics(SM_CYSIZE
) - 4);
331 INT OffsetX
= UIGetFrameSizeY( hWnd
);
332 INT OffsetY
= UIGetFrameSizeY( hWnd
);
335 if(!(GetWindowLong( hWnd
, GWL_STYLE
) & WS_SYSMENU
))
339 GetWindowRect( hWnd
, &rect
);
341 rect
.right
= rect
.right
- rect
.left
;
342 rect
.bottom
= rect
.bottom
- rect
.top
;
343 rect
.left
= rect
.top
= 0;
345 rect
.right
- OffsetX
- iBmpWidth
- 3,
347 rect
.right
- OffsetX
- 3,
348 rect
.top
+ iBmpHeight
+ OffsetY
+ 2 );
350 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
352 (bDown
? DFCS_PUSHED
: 0) |
353 (IsCloseBoxActive(hWnd
) ? 0 : DFCS_INACTIVE
)) );
356 static void UserDrawMaxButton( HWND hWnd
, HDC hDC
, BOOL bDown
)
360 INT iBmpWidth
= GetSystemMetrics(SM_CXSIZE
) - 2;
361 INT iBmpHeight
= GetSystemMetrics(SM_CYSIZE
) - 4;
363 INT OffsetX
= UIGetFrameSizeY( hWnd
);
364 INT OffsetY
= UIGetFrameSizeY( hWnd
);
366 GetWindowRect( hWnd
, &rect
);
368 if (!IsMinBoxActive(hWnd
) && !IsMaxBoxActive(hWnd
))
370 if ((GetWindowLongA( hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
) == TRUE
)
371 return; /* ToolWindows don't have min/max buttons */
373 rect
.right
= rect
.right
- rect
.left
;
374 rect
.bottom
= rect
.bottom
- rect
.top
;
375 rect
.left
= rect
.top
= 0;
377 rect
.right
- OffsetX
- (iBmpWidth
*2) - 5,
379 rect
.right
- iBmpWidth
- OffsetX
- 5,
380 rect
.top
+ iBmpHeight
+ OffsetY
+ 2 );
382 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
383 (IsZoomed(hWnd
) ? DFCS_CAPTIONRESTORE
: DFCS_CAPTIONMAX
) |
384 (bDown
? DFCS_PUSHED
: 0) |
385 (IsMaxBoxActive(hWnd
) ? 0 : DFCS_INACTIVE
) );
390 static void UserDrawMinButton( HWND hWnd
, HDC hDC
, BOOL bDown
)
394 INT iBmpWidth
= GetSystemMetrics(SM_CXSIZE
) - 2;
395 INT iBmpHeight
= GetSystemMetrics(SM_CYSIZE
) - 4;
397 INT OffsetX
= UIGetFrameSizeX( hWnd
);
398 INT OffsetY
= UIGetFrameSizeY( hWnd
);
400 GetWindowRect( hWnd
, &rect
);
402 if (!IsMinBoxActive(hWnd
) && !IsMaxBoxActive(hWnd
))
404 if ((GetWindowLongA( hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
) == TRUE
)
405 return; /* ToolWindows don't have min/max buttons */
407 rect
.right
= rect
.right
- rect
.left
;
408 rect
.bottom
= rect
.bottom
- rect
.top
;
409 rect
.left
= rect
.top
= 0;
411 rect
.right
- OffsetX
- (iBmpWidth
*3) - 5,
413 rect
.right
- (iBmpWidth
* 2) - OffsetX
- 5,
414 rect
.top
+ iBmpHeight
+ OffsetY
+ 2 );
415 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
416 DFCS_CAPTIONMIN
| (bDown
? DFCS_PUSHED
: 0) |
417 (IsMinBoxActive(hWnd
) ? 0 : DFCS_INACTIVE
) );
420 static void UserDrawCaptionNC( HDC hDC
, RECT
*rect
, HWND hWnd
,
421 DWORD style
, BOOL active
)
425 /* FIXME: Implement and Use DrawCaption() */
426 SelectObject( hDC
, GetSysColorBrush(active
? COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
) );
428 PatBlt(hDC
,rect
->left
+ GetSystemMetrics(SM_CXFRAME
), rect
->top
+
429 GetSystemMetrics(SM_CYFRAME
), rect
->right
- (GetSystemMetrics(SM_CXFRAME
) * 2), (rect
->top
+
430 GetSystemMetrics(SM_CYCAPTION
)) - 1, PATCOPY
);
432 if (style
& WS_SYSMENU
)
434 UserDrawSysMenuButton( hWnd
, hDC
, FALSE
);
435 r
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
436 UserDrawCloseButton( hWnd
, hDC
, FALSE
);
437 r
.right
-= GetSystemMetrics(SM_CXSMSIZE
) + 1;
438 UserDrawMinButton(hWnd
, hDC
, FALSE
);
439 UserDrawMaxButton(hWnd
, hDC
, FALSE
);
441 if (GetWindowTextA( hWnd
, buffer
, sizeof(buffer
) ))
443 NONCLIENTMETRICS nclm
;
444 HFONT hFont
, hOldFont
;
446 nclm
.cbSize
= sizeof(NONCLIENTMETRICS
);
447 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
448 SetTextColor(hDC
, SysColours
[ active
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
]);
449 SetBkMode( hDC
, TRANSPARENT
);
450 if (style
& WS_EX_TOOLWINDOW
)
451 hFont
= CreateFontIndirectW(&nclm
.lfSmCaptionFont
);
453 hFont
= CreateFontIndirectW(&nclm
.lfCaptionFont
);
454 hOldFont
= SelectObject(hDC
, hFont
);
455 TextOutA(hDC
, r
.left
+ (GetSystemMetrics(SM_CXDLGFRAME
) * 2), rect
->top
+ (nclm
.lfCaptionFont
.lfHeight
/ 2), buffer
, strlen(buffer
));
456 DeleteObject (SelectObject (hDC
, hOldFont
));
462 UserDrawFrameNC(HWND hWnd
, RECT
* rect
, BOOL dlgFrame
, BOOL active
)
464 HDC hDC
= GetWindowDC(hWnd
);
465 SelectObject( hDC
, GetSysColorBrush(COLOR_WINDOW
) );
466 DrawEdge(hDC
, rect
,EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
470 void SCROLL_DrawScrollBar (HWND hWnd
, HDC hDC
, INT nBar
, BOOL arrows
, BOOL interior
);
473 DefWndDoPaintNC(HWND hWnd
, HRGN clip
)
481 Active
= GetWindowLongW(hWnd
, GWL_STYLE
) & WIN_NCACTIVATED
;
482 Style
= GetWindowLong(hWnd
, GWL_STYLE
);
483 ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
485 hDC
= GetDCEx(hWnd
, (clip
> (HRGN
)1) ? clip
: 0, DCX_USESTYLE
| DCX_WINDOW
|
486 ((clip
> (HRGN
)1) ? (DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
) : 0));
492 /* FIXME: Test whether we need to draw anything at all. */
494 GetWindowRect(hWnd
, &rect
);
495 rect
.right
= rect
.right
- rect
.left
;
496 rect
.bottom
= rect
.bottom
- rect
.top
;
497 rect
.top
= rect
.left
= 0;
498 SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
499 if (UserHasThickFrameStyle(Style
, ExStyle
))
501 UserDrawFrameNC(hWnd
, &rect
, FALSE
, Active
);
503 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
505 UserDrawFrameNC(hWnd
, &rect
, TRUE
, Active
);
507 if (Style
& WS_CAPTION
)
510 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
);
511 rect
.top
+= GetSystemMetrics(SM_CYSIZE
) +
512 GetSystemMetrics(SM_CYBORDER
);
513 UserDrawCaptionNC(hDC
, &r
, hWnd
, Style
, Active
);
517 if (UserHasMenu(hWnd
, Style
))
520 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYMENU
);
522 rect
.top
+= MenuDrawMenuBar(hDC
, &r
, hWnd
, FALSE
);
525 /* Draw scrollbars */
526 if (Style
& WS_VSCROLL
)
527 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_VERT
, TRUE
, TRUE
);
528 if (Style
& WS_HSCROLL
)
529 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_HORZ
, TRUE
, TRUE
);
531 /* FIXME: Draw size box.*/
533 ReleaseDC(hWnd
, hDC
);
538 DefWndPaintNC(HWND hWnd
, HRGN clip
)
540 if (IsWindowVisible(hWnd
))
544 DefWndRedrawIconTitle(hWnd
);
548 DefWndDoPaintNC(hWnd
, clip
);
556 DefWndHitTestNC(HWND hWnd
, POINT Point
)
559 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
560 ULONG ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
562 GetWindowRect(hWnd
, &WindowRect
);
563 if (!PtInRect(&WindowRect
, Point
))
567 if (Style
& WS_MINIMIZE
)
571 if (UserHasThickFrameStyle(Style
, ExStyle
))
573 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXFRAME
),
574 -GetSystemMetrics(SM_CYFRAME
));
575 if (!PtInRect(&WindowRect
, Point
))
577 if (Point
.y
< WindowRect
.top
)
579 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
583 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
589 if (Point
.y
>= WindowRect
.bottom
)
591 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
593 return(HTBOTTOMLEFT
);
595 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
597 return(HTBOTTOMRIGHT
);
601 if (Point
.x
< WindowRect
.left
)
603 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
607 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
609 return(HTBOTTOMLEFT
);
613 if (Point
.x
>= WindowRect
.right
)
615 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
619 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
621 return(HTBOTTOMRIGHT
);
629 if (UserHasDlgFrameStyle(Style
, ExStyle
))
631 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXDLGFRAME
),
632 -GetSystemMetrics(SM_CYDLGFRAME
));
634 else if (UserHasThinFrameStyle(Style
, ExStyle
))
636 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
637 -GetSystemMetrics(SM_CYBORDER
));
639 if (!PtInRect(&WindowRect
, Point
))
645 if ((Style
& WS_CAPTION
) == WS_CAPTION
)
647 WindowRect
.top
+= (GetSystemMetrics(SM_CYCAPTION
) -
648 GetSystemMetrics(SM_CYBORDER
));
649 if (!PtInRect(&WindowRect
, Point
))
651 if ((Style
& WS_SYSMENU
) && !(ExStyle
& WS_EX_TOOLWINDOW
))
653 WindowRect
.left
+= GetSystemMetrics(SM_CXSIZE
);
654 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
656 if (Point
.x
<= WindowRect
.left
)
660 if (WindowRect
.right
<= Point
.x
)
665 if (Style
& WS_MAXIMIZEBOX
|| Style
& WS_MINIMIZEBOX
)
667 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) - 2;
669 if (Point
.x
>= WindowRect
.right
)
674 if (Style
& WS_MINIMIZEBOX
)
676 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) - 2;
678 if (Point
.x
>= WindowRect
.right
)
686 ScreenToClient(hWnd
, &Point
);
687 GetClientRect(hWnd
, &WindowRect
);
689 if (PtInRect(&WindowRect
, Point
))
694 if (Style
& WS_VSCROLL
)
696 WindowRect
.right
+= GetSystemMetrics(SM_CXVSCROLL
);
697 if (PtInRect(&WindowRect
, Point
))
703 if (Style
& WS_HSCROLL
)
705 WindowRect
.bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
706 if (PtInRect(&WindowRect
, Point
))
708 if ((Style
& WS_VSCROLL
) &&
709 (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXVSCROLL
))))
717 if (UserHasMenu(hWnd
, Style
))
719 if (Point
.y
< 0 && Point
.x
>= 0 && Point
.x
<= WindowRect
.right
)
729 DefWndHandleLButtonDownNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
735 HWND hTopWnd
= GetAncestor(hWnd
, GA_ROOT
);
736 if (SetActiveWindow(hTopWnd
) || GetActiveWindow() == hTopWnd
)
738 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOVE
+ HTCAPTION
, lParam
);
744 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_SYSMENU
)
746 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
748 HDC hDC
= GetWindowDC(hWnd
);
749 UserDrawSysMenuButton(hWnd
, hDC
, TRUE
);
750 ReleaseDC(hWnd
, hDC
);
752 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
+ HTSYSMENU
,
759 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
, lParam
);
764 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_HSCROLL
+ HTHSCROLL
, lParam
);
769 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_VSCROLL
+ HTVSCROLL
, lParam
);
774 UserDrawMinButton(hWnd
, GetWindowDC(hWnd
), IsMinBoxActive(hWnd
) );
779 UserDrawMaxButton(hWnd
,GetWindowDC(hWnd
), IsMaxBoxActive(hWnd
) );
784 UserDrawCloseButton(hWnd
,GetWindowDC(hWnd
),TRUE
);
796 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_SIZE
+ wParam
- 2, lParam
);
805 DefWndHandleLButtonDblClkNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
813 DefWndHandleLButtonUpNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
815 UserDrawMinButton(hWnd
,GetWindowDC(hWnd
),FALSE
);
816 UserDrawMaxButton(hWnd
,GetWindowDC(hWnd
),FALSE
);
817 UserDrawCloseButton(hWnd
,GetWindowDC(hWnd
),FALSE
);
822 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
827 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
832 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
841 DefWndHandleActiveNC(HWND hWnd
, WPARAM wParam
)
849 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
856 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
858 /* Not for child windows. */
859 if (hWnd
!= (HWND
)wParam
)
864 switch(LOWORD(lParam
))
868 WORD Msg
= HIWORD(lParam
);
869 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
870 Msg
== WM_RBUTTONDOWN
)
879 HICON hCursor
= (HICON
)GetClassLong(hWnd
, GCL_HCURSOR
);
891 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
897 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
903 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
909 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
912 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
916 DefWndStartSizeMove(HWND hWnd
, WPARAM wParam
, POINT
*capturePoint
)
922 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
924 GetWindowRect(hWnd
, &rectWindow
);
926 if ((wParam
& 0xfff0) == SC_MOVE
)
928 /* Move pointer at the center of the caption */
930 UserGetInsideRectNC(hWnd
, &rect
);
931 if (Style
& WS_SYSMENU
)
932 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
933 if (Style
& WS_MINIMIZEBOX
)
934 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
935 if (Style
& WS_MAXIMIZEBOX
)
936 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
937 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
938 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
946 GetMessage(&msg
, NULL
, 0, 0);
950 hittest
= DefWndHitTestNC(hWnd
, msg
.pt
);
951 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
963 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
964 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
968 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
969 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
973 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
974 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
978 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
979 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
982 case VK_ESCAPE
: return 0;
988 SetCursorPos( pt
.x
, pt
.y
);
989 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
));
993 #define ON_LEFT_BORDER(hit) \
994 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
995 #define ON_RIGHT_BORDER(hit) \
996 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
997 #define ON_TOP_BORDER(hit) \
998 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
999 #define ON_BOTTOM_BORDER(hit) \
1000 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
1003 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
1004 ULONG width
, ULONG height
, DWORD rop
)
1006 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1007 PatBlt( hdc
, rect
->left
, rect
->top
,
1008 rect
->right
- rect
->left
- width
, height
, rop
);
1009 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1010 rect
->bottom
- rect
->top
- height
, rop
);
1011 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1012 rect
->right
- rect
->left
- width
, -height
, rop
);
1013 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1014 rect
->bottom
- rect
->top
- height
, rop
);
1015 SelectObject( hdc
, hbrush
);
1019 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
1023 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
),
1024 GetSystemMetrics(SM_CYFRAME
), PATINVERT
);
1026 else DrawFocusRect( hdc
, rect
);
1030 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
1033 RECT sizingRect
, mouseRect
, origRect
;
1035 LONG hittest
= (LONG
)(wParam
& 0x0f);
1036 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1037 POINT minTrack
, maxTrack
;
1038 POINT capturePoint
, pt
;
1039 ULONG Style
= GetWindowLong(hwnd
, GWL_STYLE
);
1040 ULONG ExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
1041 BOOL thickframe
= UserHasThickFrameStyle(Style
, ExStyle
);
1042 BOOL iconic
= Style
& WS_MINIMIZE
;
1044 DWORD dwPoint
= GetMessagePos();
1045 BOOL DragFullWindows
= FALSE
;
1048 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1050 pt
.x
= SLOWORD(dwPoint
);
1051 pt
.y
= SHIWORD(dwPoint
);
1054 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
))
1059 if ((wParam
& 0xfff0) == SC_MOVE
)
1063 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
1076 if (hittest
&& hittest
!= HTSYSMENU
)
1083 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
1092 if (Style
& WS_CHILD
)
1094 hWndParent
= GetParent(hwnd
);
1097 /* Get min/max info */
1099 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1100 GetWindowRect(hwnd
, &sizingRect
);
1101 origRect
= sizingRect
;
1102 if (Style
& WS_CHILD
)
1104 GetClientRect(hWndParent
, &mouseRect
);
1108 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
),
1109 GetSystemMetrics(SM_CYSCREEN
));
1111 if (ON_LEFT_BORDER(hittest
))
1113 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1114 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1116 else if (ON_RIGHT_BORDER(hittest
))
1118 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1119 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1121 if (ON_TOP_BORDER(hittest
))
1123 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1124 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1126 else if (ON_BOTTOM_BORDER(hittest
))
1128 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1129 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1131 if (Style
& WS_CHILD
)
1133 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
1135 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1137 if (GetCapture() != hwnd
) SetCapture( hwnd
);
1139 if (Style
& WS_CHILD
)
1141 /* Retrieve a default cache DC (without using the window style) */
1142 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
1149 if( iconic
) /* create a cursor for dragging */
1151 HICON hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICON
);
1152 if(!hIcon
) hIcon
= (HICON
)SendMessage( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1153 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
1154 if( !hDragCursor
) iconic
= FALSE
;
1157 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
1158 if( !iconic
&& !DragFullWindows
)
1160 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1167 GetMessage(&msg
, 0, 0, 0);
1169 /* Exit on button-up, Return, or Esc */
1170 if ((msg
.message
== WM_LBUTTONUP
) ||
1171 ((msg
.message
== WM_KEYDOWN
) &&
1172 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1174 if (msg
.message
== WM_PAINT
)
1176 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1177 UpdateWindow( msg
.hwnd
);
1178 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1182 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1183 continue; /* We are not interested in other messages */
1187 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1189 case VK_UP
: pt
.y
-= 8; break;
1190 case VK_DOWN
: pt
.y
+= 8; break;
1191 case VK_LEFT
: pt
.x
-= 8; break;
1192 case VK_RIGHT
: pt
.x
+= 8; break;
1195 pt
.x
= max( pt
.x
, mouseRect
.left
);
1196 pt
.x
= min( pt
.x
, mouseRect
.right
);
1197 pt
.y
= max( pt
.y
, mouseRect
.top
);
1198 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1200 dx
= pt
.x
- capturePoint
.x
;
1201 dy
= pt
.y
- capturePoint
.y
;
1209 if( iconic
) /* ok, no system popup tracking */
1211 hOldCursor
= SetCursor(hDragCursor
);
1213 WinPosShowIconTitle( hwnd
, FALSE
);
1217 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1220 RECT newRect
= sizingRect
;
1221 WPARAM wpSizingHit
= 0;
1223 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1224 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1225 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1226 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1227 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1228 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1231 /* determine the hit location */
1232 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1233 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1234 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1238 if(!DragFullWindows
)
1239 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
1241 /* To avoid any deadlocks, all the locks on the windows
1242 structures must be suspended before the SetWindowPos */
1243 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1244 newRect
.right
- newRect
.left
,
1245 newRect
.bottom
- newRect
.top
,
1246 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1249 sizingRect
= newRect
;
1257 if( moved
) /* restore cursors, show icon title later on */
1259 ShowCursor( FALSE
);
1260 SetCursor( hOldCursor
);
1262 DestroyCursor( hDragCursor
);
1264 else if(!DragFullWindows
)
1265 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1267 if (Style
& WS_CHILD
)
1268 ReleaseDC( hWndParent
, hdc
);
1270 ReleaseDC( 0, hdc
);
1272 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1273 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1275 /* window moved or resized */
1278 /* if the moving/resizing isn't canceled call SetWindowPos
1279 * with the new position or the new size of the window
1281 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1283 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1284 if(!DragFullWindows
)
1285 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1286 sizingRect
.right
- sizingRect
.left
,
1287 sizingRect
.bottom
- sizingRect
.top
,
1288 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1290 else { /* restore previous size/position */
1292 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1293 origRect
.right
- origRect
.left
,
1294 origRect
.bottom
- origRect
.top
,
1295 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1299 if( IsWindow(hwnd
) )
1300 if( Style
& WS_MINIMIZE
)
1302 /* Single click brings up the system menu when iconized */
1306 if( Style
& WS_SYSMENU
)
1307 SendMessageA( hwnd
, WM_SYSCOMMAND
,
1308 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1310 else WinPosShowIconTitle( hwnd
, TRUE
);
1316 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
1318 switch (wParam
& 0xfff0)
1322 DefWndDoSizeMove(hWnd
, wParam
);
1325 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
1328 MenuTrackMouseMenuBar(hWnd
, wParam
, Pt
);
1331 MenuTrackKbdMenuBar(hWnd
, wParam
, Pt
.x
);
1334 /* FIXME: Implement */
1344 DefWndAdjustRect(RECT
* Rect
, ULONG Style
, BOOL Menu
, ULONG ExStyle
)
1346 if (Style
& WS_ICONIC
)
1351 if (UserHasThickFrameStyle(Style
, ExStyle
))
1353 InflateRect(Rect
, GetSystemMetrics(SM_CXFRAME
),
1354 GetSystemMetrics(SM_CYFRAME
));
1356 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
1358 InflateRect(Rect
, GetSystemMetrics(SM_CXDLGFRAME
),
1359 GetSystemMetrics(SM_CYDLGFRAME
));
1361 else if (UserHasThinFrameStyle(Style
, ExStyle
))
1363 InflateRect(Rect
, GetSystemMetrics(SM_CXBORDER
),
1364 GetSystemMetrics(SM_CYBORDER
));
1366 if (Style
& WS_CAPTION
)
1368 Rect
->top
-= (GetSystemMetrics(SM_CYCAPTION
) -
1369 GetSystemMetrics(SM_CYBORDER
)) + 1;
1373 Rect
->top
-= GetSystemMetrics(SM_CYMENU
) + GetSystemMetrics(SM_CYBORDER
);
1375 if (Style
& WS_VSCROLL
)
1377 Rect
->right
+= GetSystemMetrics(SM_CXVSCROLL
) - 1;
1378 if (UserHasAnyFrameStyle(Style
, ExStyle
))
1383 if (Style
& WS_HSCROLL
)
1385 Rect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
) - 1;
1386 if (UserHasAnyFrameStyle(Style
, ExStyle
))
1395 DefWndNCCalcSize(HWND hWnd
, RECT
* Rect
)
1398 LONG Style
= GetClassLongW(hWnd
, GCL_STYLE
);
1399 RECT TmpRect
= {0, 0, 0, 0};
1401 if (Style
& CS_VREDRAW
)
1403 Result
|= WVR_VREDRAW
;
1405 if (Style
& CS_HREDRAW
)
1407 Result
|= WVR_HREDRAW
;
1410 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1412 DefWndAdjustRect(&TmpRect
, GetWindowLong(hWnd
, GWL_STYLE
),
1413 FALSE
, GetWindowLong(hWnd
, GWL_EXSTYLE
));
1414 Rect
->left
-= TmpRect
.left
;
1415 Rect
->top
-= TmpRect
.top
;
1416 Rect
->right
-= TmpRect
.right
;
1417 Rect
->bottom
-= TmpRect
.bottom
;
1418 if (UserHasMenu(hWnd
, GetWindowLong(hWnd
, GWL_EXSTYLE
)))
1420 Rect
->top
+= MenuGetMenuBarHeight(hWnd
,
1421 Rect
->right
- Rect
->left
,
1425 Rect
->bottom
= max(Rect
->top
, Rect
->bottom
);
1426 Rect
->right
= max(Rect
->left
, Rect
->right
);
1433 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
1441 User32DefWindowProc(HWND hWnd
,
1451 return(DefWndPaintNC(hWnd
, (HRGN
)wParam
));
1453 case WM_WINDOWPOSCHANGING
:
1455 DbgPrint("WM_WINDOWPOSCHANGING\n\n");
1461 Point
.x
= SLOWORD(lParam
);
1462 Point
.y
= SHIWORD(lParam
);
1463 return(DefWndHitTestNC(hWnd
, Point
));
1466 case WM_NCLBUTTONDOWN
:
1468 return(DefWndHandleLButtonDownNC(hWnd
, wParam
, lParam
));
1471 case WM_NCLBUTTONUP
:
1473 return(DefWndHandleLButtonUpNC(hWnd
, wParam
, lParam
));
1476 case WM_LBUTTONDBLCLK
:
1477 case WM_NCLBUTTONDBLCLK
:
1479 return(DefWndHandleLButtonDblClkNC(hWnd
, wParam
, lParam
));
1482 case WM_NCRBUTTONDOWN
:
1484 if (wParam
== HTCAPTION
)
1497 if (hWnd
== GetCapture())
1501 Pt
.x
= SLOWORD(lParam
);
1502 Pt
.y
= SHIWORD(lParam
);
1503 ClientToScreen(hWnd
, &Pt
);
1504 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1507 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1511 SendMessageA (hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1516 case WM_NCRBUTTONUP
:
1518 /* Wine does nothing here. */
1522 case WM_CONTEXTMENU
:
1524 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1528 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1532 SendMessageA(hWnd
, WM_CONTEXTMENU
, wParam
, lParam
);
1540 Pt
.x
= SLOWORD(lParam
);
1541 Pt
.y
= SHIWORD(lParam
);
1543 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1545 ScreenToClient(GetParent(hWnd
), &Pt
);
1548 HitCode
= DefWndHitTestNC(hWnd
, Pt
);
1550 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1552 TrackPopupMenu(GetSystemMenu(hWnd
, FALSE
),
1553 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
1554 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1562 return(DefWndHandleActiveNC(hWnd
, wParam
));
1579 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1583 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1584 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1588 GetWindowRect(hWnd
, &WindowRect
);
1589 x
= (WindowRect
.right
- WindowRect
.left
-
1590 GetSystemMetrics(SM_CXICON
)) / 2;
1591 y
= (WindowRect
.bottom
- WindowRect
.top
-
1592 GetSystemMetrics(SM_CYICON
)) / 2;
1593 DrawIcon(hDC
, x
, y
, hIcon
);
1595 if (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_CLIENTEDGE
)
1598 GetClientRect(hWnd
, &WindowRect
);
1599 DrawEdge(hDC
, &WindowRect
, EDGE_SUNKEN
, BF_RECT
);
1601 EndPaint(hWnd
, &Ps
);
1609 hRgn
= CreateRectRgn(0, 0, 0, 0);
1610 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1612 RedrawWindow(hWnd
, NULL
, hRgn
,
1613 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1622 DefWndSetRedraw(hWnd
, wParam
);
1628 DestroyWindow(hWnd
);
1632 case WM_MOUSEACTIVATE
:
1634 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1639 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1644 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1652 return((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1657 /* Check if the window is minimized. */
1658 if (LOWORD(lParam
) != WA_INACTIVE
&&
1659 !(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1668 if (GetWindowLong(hWnd
, GWL_STYLE
& WS_CHILD
))
1672 return(SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1677 return(SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1685 case WM_ICONERASEBKGND
:
1689 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1690 GetClipBox((HDC
)wParam
, &Rect
);
1691 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1700 /* FIXME: Implement colour controls. */
1704 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1706 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1711 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1716 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1725 return(DefWndHandleSetCursor(hWnd
, wParam
, lParam
));
1731 Pt
.x
= SLOWORD(lParam
);
1732 Pt
.y
= SHIWORD(lParam
);
1733 return(DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1736 /* FIXME: Handle key messages. */
1744 /* FIXME: Not done correctly */
1745 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
&& !wParam
) ||
1746 (!(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
) && wParam
))
1750 ShowWindow(hWnd
, wParam
? SW_SHOWNA
: SW_HIDE
);
1756 /* FIXME: Check for a desktop. */
1757 if (GetCapture() == hWnd
)
1769 /* FIXME: Implement this. */
1772 case WM_QUERYDROPOBJECT
:
1774 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1781 case WM_QUERYDRAGICON
:
1786 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1789 return((LRESULT
)hIcon
);
1791 for (Len
= 1; Len
< 64; Len
++)
1793 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCE(Len
))) != NULL
)
1795 return((LRESULT
)hIcon
);
1798 return((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1801 /* FIXME: WM_ISACTIVEICON */
1803 case WM_NOTIFYFORMAT
:
1805 if (IsWindowUnicode(hWnd
))
1807 return(NFR_UNICODE
);
1817 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1818 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1819 SetClassLongW(hWnd
, Index
, lParam
);
1820 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1821 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1822 SWP_NOACTIVATE
| SWP_NOZORDER
);
1823 return((LRESULT
)hOldIcon
);
1828 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1829 return(GetClassLongW(hWnd
, Index
));
1836 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1840 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1846 if (HIWORD(lParam
) & KEYDATA_ALT
)
1848 if (wParam
== VK_F4
) /* Try to close the window */
1850 //HWND hTopWnd = GetAncestor(hWnd, GA_ROOT);
1851 HWND hTopWnd
= hWnd
;
1852 if (!(GetClassLongW(hTopWnd
, GCL_STYLE
) & CS_NOCLOSE
))
1856 PostMessageW(hTopWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1860 PostMessageA(hTopWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1872 DefWindowProcA(HWND hWnd
,
1878 static LPSTR WindowTextAtom
= 0;
1885 CREATESTRUCTA
* Cs
= (CREATESTRUCTA
*)lParam
;
1886 if (HIWORD(Cs
->lpszName
))
1888 if (0 == WindowTextAtom
)
1891 (LPSTR
)(ULONG
)GlobalAddAtomA("USER32!WindowTextAtomA");
1893 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1894 strlen(Cs
->lpszName
) * sizeof(CHAR
));
1895 strcpy(WindowText
, Cs
->lpszName
);
1896 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1903 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1906 case WM_WINDOWPOSCHANGING
:
1908 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1911 case WM_GETTEXTLENGTH
:
1913 if (WindowTextAtom
== 0 ||
1914 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1918 return(strlen(WindowText
));
1923 if (WindowTextAtom
== 0 ||
1924 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1928 *((PSTR
)lParam
) = '\0';
1932 strncpy((LPSTR
)lParam
, WindowText
, wParam
);
1933 return(min(wParam
, strlen(WindowText
)));
1938 if (0 == WindowTextAtom
)
1941 (LPSTR
)(DWORD
)GlobalAddAtomA("USER32!WindowTextAtomW");
1943 if (WindowTextAtom
!= 0 &&
1944 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1946 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
1948 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1949 strlen((PSTR
)lParam
) * sizeof(CHAR
));
1950 strcpy(WindowText
, (PSTR
)lParam
);
1951 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1952 if (0 != (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
))
1954 DefWndPaintNC(hWnd
, (HRGN
) 1);
1956 Result
= (LPARAM
) TRUE
;
1962 if (WindowTextAtom
!= 0 &&
1963 (WindowText
= RemovePropA(hWnd
, WindowTextAtom
)) == NULL
)
1965 RtlFreeHeap(GetProcessHeap(), 0, WindowText
);
1971 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1980 DefWindowProcW(HWND hWnd
,
1986 static LPWSTR WindowTextAtom
= 0;
1993 CREATESTRUCTW
* Cs
= (CREATESTRUCTW
*)lParam
;
1994 if (HIWORD(Cs
->lpszName
))
1996 if (0 == WindowTextAtom
)
1999 (LPWSTR
)(DWORD
)GlobalAddAtomW(L
"USER32!WindowTextAtomW");
2001 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2002 wcslen(Cs
->lpszName
) * sizeof(WCHAR
));
2003 wcscpy(WindowText
, Cs
->lpszName
);
2004 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
2011 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
2014 case WM_WINDOWPOSCHANGING
:
2016 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
2019 case WM_GETTEXTLENGTH
:
2021 if (WindowTextAtom
== 0 ||
2022 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2026 return(wcslen(WindowText
));
2031 if (WindowTextAtom
== 0 ||
2032 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2036 ((PWSTR
)lParam
) = '\0';
2040 wcsncpy((PWSTR
)lParam
, WindowText
, wParam
);
2041 return(min(wParam
, wcslen(WindowText
)));
2046 if (WindowTextAtom
!= 0)
2049 (LPWSTR
)(DWORD
)GlobalAddAtom(L
"USER32!WindowTextAtomW");
2051 if (WindowTextAtom
!= 0 &&
2052 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2054 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
2056 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2057 wcslen((PWSTR
)lParam
) * sizeof(WCHAR
));
2058 wcscpy(WindowText
, (PWSTR
)lParam
);
2059 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
2060 if (0 != (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
))
2062 DefWndPaintNC(hWnd
, (HRGN
) 1);
2064 Result
= (LPARAM
) TRUE
;
2070 if (WindowTextAtom
!= 0 &&
2071 (WindowText
= RemovePropW(hWnd
, WindowTextAtom
)) == NULL
)
2073 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
2079 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);