1 /* $Id: defwnd.c,v 1.62 2003/08/06 18:43:57 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
) && GetMenu(hWnd
) != 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
)
454 Active
= GetWindowLongW(hWnd
, GWL_STYLE
) & WIN_NCACTIVATED
;
455 Style
= GetWindowLong(hWnd
, GWL_STYLE
);
456 ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
458 hDC
= GetDCEx(hWnd
, (clip
> (HRGN
)1) ? clip
: 0, DCX_USESTYLE
| DCX_WINDOW
|
459 ((clip
> (HRGN
)1) ? (DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
) : 0));
465 /* FIXME: Test whether we need to draw anything at all. */
467 GetWindowRect(hWnd
, &rect
);
468 rect
.right
= rect
.right
- rect
.left
;
469 rect
.bottom
= rect
.bottom
- rect
.top
;
470 rect
.top
= rect
.left
= 0;
471 SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
472 if (UserHasThickFrameStyle(Style
, ExStyle
))
474 UserDrawFrameNC(hWnd
, &rect
, FALSE
, Active
);
475 wFrame
= GetSystemMetrics(SM_CXSIZEFRAME
);
477 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
479 UserDrawFrameNC(hWnd
, &rect
, TRUE
, Active
);
480 wFrame
= GetSystemMetrics(SM_CXDLGFRAME
);
482 if (Style
& WS_CAPTION
)
485 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
);
486 rect
.top
+= GetSystemMetrics(SM_CYSIZE
) +
487 GetSystemMetrics(SM_CYBORDER
);
488 UserDrawCaptionNC(hDC
, &r
, hWnd
, Style
, Active
);
492 if (UserHasMenu(hWnd
, Style
))
495 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYMENU
);
498 rect
.top
+= MenuDrawMenuBar(hDC
, &r
, hWnd
, FALSE
);
501 /* Draw scrollbars */
502 if (Style
& WS_VSCROLL
)
503 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_VERT
, TRUE
, TRUE
);
504 if (Style
& WS_HSCROLL
)
505 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_HORZ
, TRUE
, TRUE
);
507 /* FIXME: Draw size box.*/
509 ReleaseDC(hWnd
, hDC
);
514 DefWndPaintNC(HWND hWnd
, HRGN clip
)
516 if (IsWindowVisible(hWnd
))
520 DefWndRedrawIconTitle(hWnd
);
524 DefWndDoPaintNC(hWnd
, clip
);
532 DefWndHitTestNC(HWND hWnd
, POINT Point
)
535 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
536 ULONG ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
538 GetWindowRect(hWnd
, &WindowRect
);
539 if (!PtInRect(&WindowRect
, Point
))
543 if (Style
& WS_MINIMIZE
)
547 if (UserHasThickFrameStyle(Style
, ExStyle
))
549 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXFRAME
),
550 -GetSystemMetrics(SM_CYFRAME
));
551 if (!PtInRect(&WindowRect
, Point
))
553 if (Point
.y
< WindowRect
.top
)
555 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
559 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
565 if (Point
.y
>= WindowRect
.bottom
)
567 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
569 return(HTBOTTOMLEFT
);
571 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
573 return(HTBOTTOMRIGHT
);
577 if (Point
.x
< WindowRect
.left
)
579 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
583 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
585 return(HTBOTTOMLEFT
);
589 if (Point
.x
>= WindowRect
.right
)
591 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
595 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
597 return(HTBOTTOMRIGHT
);
605 if (UserHasDlgFrameStyle(Style
, ExStyle
))
607 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXDLGFRAME
),
608 -GetSystemMetrics(SM_CYDLGFRAME
));
610 else if (UserHasThinFrameStyle(Style
, ExStyle
))
612 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
613 -GetSystemMetrics(SM_CYBORDER
));
615 if (!PtInRect(&WindowRect
, Point
))
621 if ((Style
& WS_CAPTION
) == WS_CAPTION
)
623 WindowRect
.top
+= (GetSystemMetrics(SM_CYCAPTION
) -
624 GetSystemMetrics(SM_CYBORDER
));
625 if (!PtInRect(&WindowRect
, Point
))
627 if ((Style
& WS_SYSMENU
) && !(ExStyle
& WS_EX_TOOLWINDOW
))
629 WindowRect
.left
+= GetSystemMetrics(SM_CXSIZE
);
630 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
632 if (Point
.x
<= WindowRect
.left
)
636 if (WindowRect
.right
<= Point
.x
)
641 if (Style
& WS_MAXIMIZEBOX
|| Style
& WS_MINIMIZEBOX
)
643 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) - 2;
645 if (Point
.x
>= WindowRect
.right
)
650 if (Style
& WS_MINIMIZEBOX
)
652 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) - 2;
654 if (Point
.x
>= WindowRect
.right
)
662 ScreenToClient(hWnd
, &Point
);
663 GetClientRect(hWnd
, &WindowRect
);
665 if (PtInRect(&WindowRect
, Point
))
670 if (Style
& WS_VSCROLL
)
672 WindowRect
.right
+= GetSystemMetrics(SM_CXVSCROLL
);
673 if (PtInRect(&WindowRect
, Point
))
679 if (Style
& WS_HSCROLL
)
681 WindowRect
.bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
682 if (PtInRect(&WindowRect
, Point
))
684 if ((Style
& WS_VSCROLL
) &&
685 (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXVSCROLL
))))
693 if (UserHasMenu(hWnd
, Style
))
695 if (Point
.y
< 0 && Point
.x
>= 0 && Point
.x
<= WindowRect
.right
)
705 DefWndHandleLButtonDownNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
711 HWND hTopWnd
= GetAncestor(hWnd
, GA_ROOT
);
712 if (SetActiveWindow(hTopWnd
) || GetActiveWindow() == hTopWnd
)
714 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOVE
+ HTCAPTION
, lParam
);
720 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_SYSMENU
)
722 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
724 HDC hDC
= GetWindowDC(hWnd
);
725 UserDrawSysMenuButton(hWnd
, hDC
, TRUE
);
726 ReleaseDC(hWnd
, hDC
);
728 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
+ HTSYSMENU
,
735 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
, lParam
);
740 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_HSCROLL
+ HTHSCROLL
, lParam
);
745 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_VSCROLL
+ HTVSCROLL
, lParam
);
750 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), IsMinBoxActive(hWnd
), DFCS_CAPTIONMIN
);
755 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), IsMaxBoxActive(hWnd
), DFCS_CAPTIONMAX
);
760 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), TRUE
, DFCS_CAPTIONCLOSE
);
772 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_SIZE
+ wParam
- 2, lParam
);
781 DefWndHandleLButtonDblClkNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
789 DefWndHandleLButtonUpNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
791 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), FALSE
, DFCS_CAPTIONMIN
);
792 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), FALSE
, DFCS_CAPTIONMAX
);
793 UserDrawCaptionButton( hWnd
, GetWindowDC(hWnd
), FALSE
, DFCS_CAPTIONCLOSE
);
798 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
803 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
808 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
817 DefWndHandleActiveNC(HWND hWnd
, WPARAM wParam
)
825 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
832 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
834 /* Not for child windows. */
835 if (hWnd
!= (HWND
)wParam
)
840 switch(LOWORD(lParam
))
844 WORD Msg
= HIWORD(lParam
);
845 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
846 Msg
== WM_RBUTTONDOWN
)
855 HICON hCursor
= (HICON
)GetClassLong(hWnd
, GCL_HCURSOR
);
867 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
873 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
879 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
885 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
888 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
892 DefWndStartSizeMove(HWND hWnd
, WPARAM wParam
, POINT
*capturePoint
)
898 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
900 GetWindowRect(hWnd
, &rectWindow
);
902 if ((wParam
& 0xfff0) == SC_MOVE
)
904 /* Move pointer at the center of the caption */
906 UserGetInsideRectNC(hWnd
, &rect
);
907 if (Style
& WS_SYSMENU
)
908 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
909 if (Style
& WS_MINIMIZEBOX
)
910 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
911 if (Style
& WS_MAXIMIZEBOX
)
912 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
913 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
914 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
922 GetMessage(&msg
, NULL
, 0, 0);
926 hittest
= DefWndHitTestNC(hWnd
, msg
.pt
);
927 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
939 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
940 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
944 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
945 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
949 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
950 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
954 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
955 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
958 case VK_ESCAPE
: return 0;
964 SetCursorPos( pt
.x
, pt
.y
);
965 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
));
969 #define ON_LEFT_BORDER(hit) \
970 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
971 #define ON_RIGHT_BORDER(hit) \
972 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
973 #define ON_TOP_BORDER(hit) \
974 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
975 #define ON_BOTTOM_BORDER(hit) \
976 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
979 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
980 ULONG width
, ULONG height
, DWORD rop
)
982 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
983 PatBlt( hdc
, rect
->left
, rect
->top
,
984 rect
->right
- rect
->left
- width
, height
, rop
);
985 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
986 rect
->bottom
- rect
->top
- height
, rop
);
987 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
988 rect
->right
- rect
->left
- width
, -height
, rop
);
989 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
990 rect
->bottom
- rect
->top
- height
, rop
);
991 SelectObject( hdc
, hbrush
);
995 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
999 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
),
1000 GetSystemMetrics(SM_CYFRAME
), PATINVERT
);
1002 else DrawFocusRect( hdc
, rect
);
1006 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
1009 RECT sizingRect
, mouseRect
, origRect
;
1011 LONG hittest
= (LONG
)(wParam
& 0x0f);
1012 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1013 POINT minTrack
, maxTrack
;
1014 POINT capturePoint
, pt
;
1015 ULONG Style
= GetWindowLong(hwnd
, GWL_STYLE
);
1016 ULONG ExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
1017 BOOL thickframe
= UserHasThickFrameStyle(Style
, ExStyle
);
1018 BOOL iconic
= Style
& WS_MINIMIZE
;
1020 DWORD dwPoint
= GetMessagePos();
1021 BOOL DragFullWindows
= FALSE
;
1024 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1026 pt
.x
= SLOWORD(dwPoint
);
1027 pt
.y
= SHIWORD(dwPoint
);
1030 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
))
1035 if ((wParam
& 0xfff0) == SC_MOVE
)
1039 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
1052 if (hittest
&& hittest
!= HTSYSMENU
)
1059 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
1068 if (Style
& WS_CHILD
)
1070 hWndParent
= GetParent(hwnd
);
1073 /* Get min/max info */
1075 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1076 GetWindowRect(hwnd
, &sizingRect
);
1077 origRect
= sizingRect
;
1078 if (Style
& WS_CHILD
)
1080 GetClientRect(hWndParent
, &mouseRect
);
1084 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
),
1085 GetSystemMetrics(SM_CYSCREEN
));
1087 if (ON_LEFT_BORDER(hittest
))
1089 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1090 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1092 else if (ON_RIGHT_BORDER(hittest
))
1094 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1095 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1097 if (ON_TOP_BORDER(hittest
))
1099 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1100 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1102 else if (ON_BOTTOM_BORDER(hittest
))
1104 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1105 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1107 if (Style
& WS_CHILD
)
1109 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
1111 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1113 if (GetCapture() != hwnd
) SetCapture( hwnd
);
1115 if (Style
& WS_CHILD
)
1117 /* Retrieve a default cache DC (without using the window style) */
1118 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
1125 if( iconic
) /* create a cursor for dragging */
1127 HICON hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICON
);
1128 if(!hIcon
) hIcon
= (HICON
)SendMessage( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1129 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
1130 if( !hDragCursor
) iconic
= FALSE
;
1133 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
1134 if( !iconic
&& !DragFullWindows
)
1136 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1143 GetMessage(&msg
, 0, 0, 0);
1145 /* Exit on button-up, Return, or Esc */
1146 if ((msg
.message
== WM_LBUTTONUP
) ||
1147 ((msg
.message
== WM_KEYDOWN
) &&
1148 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1150 if (msg
.message
== WM_PAINT
)
1152 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1153 UpdateWindow( msg
.hwnd
);
1154 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1158 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1159 continue; /* We are not interested in other messages */
1163 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1165 case VK_UP
: pt
.y
-= 8; break;
1166 case VK_DOWN
: pt
.y
+= 8; break;
1167 case VK_LEFT
: pt
.x
-= 8; break;
1168 case VK_RIGHT
: pt
.x
+= 8; break;
1171 pt
.x
= max( pt
.x
, mouseRect
.left
);
1172 pt
.x
= min( pt
.x
, mouseRect
.right
);
1173 pt
.y
= max( pt
.y
, mouseRect
.top
);
1174 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1176 dx
= pt
.x
- capturePoint
.x
;
1177 dy
= pt
.y
- capturePoint
.y
;
1185 if( iconic
) /* ok, no system popup tracking */
1187 hOldCursor
= SetCursor(hDragCursor
);
1189 WinPosShowIconTitle( hwnd
, FALSE
);
1193 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1196 RECT newRect
= sizingRect
;
1197 WPARAM wpSizingHit
= 0;
1199 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1200 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1201 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1202 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1203 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1204 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1207 /* determine the hit location */
1208 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1209 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1210 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1214 if(!DragFullWindows
)
1215 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
1217 /* To avoid any deadlocks, all the locks on the windows
1218 structures must be suspended before the SetWindowPos */
1219 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1220 newRect
.right
- newRect
.left
,
1221 newRect
.bottom
- newRect
.top
,
1222 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1225 sizingRect
= newRect
;
1233 if( moved
) /* restore cursors, show icon title later on */
1235 ShowCursor( FALSE
);
1236 SetCursor( hOldCursor
);
1238 DestroyCursor( hDragCursor
);
1240 else if(!DragFullWindows
)
1241 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
1243 if (Style
& WS_CHILD
)
1244 ReleaseDC( hWndParent
, hdc
);
1246 ReleaseDC( 0, hdc
);
1248 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1249 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1251 /* window moved or resized */
1254 /* if the moving/resizing isn't canceled call SetWindowPos
1255 * with the new position or the new size of the window
1257 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1259 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1260 if(!DragFullWindows
)
1261 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1262 sizingRect
.right
- sizingRect
.left
,
1263 sizingRect
.bottom
- sizingRect
.top
,
1264 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1266 else { /* restore previous size/position */
1268 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1269 origRect
.right
- origRect
.left
,
1270 origRect
.bottom
- origRect
.top
,
1271 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1275 if( IsWindow(hwnd
) )
1276 if( Style
& WS_MINIMIZE
)
1278 /* Single click brings up the system menu when iconized */
1282 if( Style
& WS_SYSMENU
)
1283 SendMessageA( hwnd
, WM_SYSCOMMAND
,
1284 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1286 else WinPosShowIconTitle( hwnd
, TRUE
);
1292 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
1294 switch (wParam
& 0xfff0)
1298 DefWndDoSizeMove(hWnd
, wParam
);
1301 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
1304 MenuTrackMouseMenuBar(hWnd
, wParam
, Pt
);
1307 MenuTrackKbdMenuBar(hWnd
, wParam
, Pt
.x
);
1310 /* FIXME: Implement */
1320 DefWndAdjustRect(RECT
* Rect
, ULONG Style
, BOOL Menu
, ULONG ExStyle
)
1322 if (Style
& WS_ICONIC
)
1327 if (UserHasThickFrameStyle(Style
, ExStyle
))
1329 InflateRect(Rect
, GetSystemMetrics(SM_CXFRAME
),
1330 GetSystemMetrics(SM_CYFRAME
));
1332 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
1334 InflateRect(Rect
, GetSystemMetrics(SM_CXDLGFRAME
),
1335 GetSystemMetrics(SM_CYDLGFRAME
));
1337 else if (UserHasThinFrameStyle(Style
, ExStyle
))
1339 InflateRect(Rect
, GetSystemMetrics(SM_CXBORDER
),
1340 GetSystemMetrics(SM_CYBORDER
));
1342 if (Style
& WS_CAPTION
)
1344 Rect
->top
-= (GetSystemMetrics(SM_CYCAPTION
) -
1345 GetSystemMetrics(SM_CYBORDER
)) + 1;
1349 Rect
->top
-= GetSystemMetrics(SM_CYMENU
) + GetSystemMetrics(SM_CYBORDER
);
1351 if (Style
& WS_VSCROLL
)
1353 Rect
->right
+= GetSystemMetrics(SM_CXVSCROLL
) - 1;
1354 if (UserHasAnyFrameStyle(Style
, ExStyle
))
1359 if (Style
& WS_HSCROLL
)
1361 Rect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
) - 1;
1362 if (UserHasAnyFrameStyle(Style
, ExStyle
))
1371 DefWndNCCalcSize(HWND hWnd
, RECT
* Rect
)
1374 LONG Style
= GetClassLongW(hWnd
, GCL_STYLE
);
1375 RECT TmpRect
= {0, 0, 0, 0};
1377 if (Style
& CS_VREDRAW
)
1379 Result
|= WVR_VREDRAW
;
1381 if (Style
& CS_HREDRAW
)
1383 Result
|= WVR_HREDRAW
;
1386 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1388 DefWndAdjustRect(&TmpRect
, GetWindowLong(hWnd
, GWL_STYLE
),
1389 FALSE
, GetWindowLong(hWnd
, GWL_EXSTYLE
));
1390 Rect
->left
-= TmpRect
.left
;
1391 Rect
->top
-= TmpRect
.top
;
1392 Rect
->right
-= TmpRect
.right
;
1393 Rect
->bottom
-= TmpRect
.bottom
;
1394 if (UserHasMenu(hWnd
, GetWindowLong(hWnd
, GWL_EXSTYLE
)))
1396 Rect
->top
+= MenuGetMenuBarHeight(hWnd
,
1397 Rect
->right
- Rect
->left
,
1401 Rect
->bottom
= max(Rect
->top
, Rect
->bottom
);
1402 Rect
->right
= max(Rect
->left
, Rect
->right
);
1409 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
1417 User32DefWindowProc(HWND hWnd
,
1427 return(DefWndPaintNC(hWnd
, (HRGN
)wParam
));
1429 case WM_WINDOWPOSCHANGING
:
1431 DbgPrint("WM_WINDOWPOSCHANGING\n\n");
1437 Point
.x
= SLOWORD(lParam
);
1438 Point
.y
= SHIWORD(lParam
);
1439 return(DefWndHitTestNC(hWnd
, Point
));
1442 case WM_NCLBUTTONDOWN
:
1444 return(DefWndHandleLButtonDownNC(hWnd
, wParam
, lParam
));
1447 case WM_NCLBUTTONUP
:
1449 return(DefWndHandleLButtonUpNC(hWnd
, wParam
, lParam
));
1452 case WM_LBUTTONDBLCLK
:
1453 case WM_NCLBUTTONDBLCLK
:
1455 return(DefWndHandleLButtonDblClkNC(hWnd
, wParam
, lParam
));
1458 case WM_NCRBUTTONDOWN
:
1460 if (wParam
== HTCAPTION
)
1473 if (hWnd
== GetCapture())
1477 Pt
.x
= SLOWORD(lParam
);
1478 Pt
.y
= SHIWORD(lParam
);
1479 ClientToScreen(hWnd
, &Pt
);
1480 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1483 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1487 SendMessageA (hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1492 case WM_NCRBUTTONUP
:
1494 /* Wine does nothing here. */
1498 case WM_CONTEXTMENU
:
1500 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1504 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1508 SendMessageA(hWnd
, WM_CONTEXTMENU
, wParam
, lParam
);
1516 Pt
.x
= SLOWORD(lParam
);
1517 Pt
.y
= SHIWORD(lParam
);
1519 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1521 ScreenToClient(GetParent(hWnd
), &Pt
);
1524 HitCode
= DefWndHitTestNC(hWnd
, Pt
);
1526 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1528 TrackPopupMenu(GetSystemMenu(hWnd
, FALSE
),
1529 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
1530 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1538 return(DefWndHandleActiveNC(hWnd
, wParam
));
1555 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1559 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1560 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1564 GetWindowRect(hWnd
, &WindowRect
);
1565 x
= (WindowRect
.right
- WindowRect
.left
-
1566 GetSystemMetrics(SM_CXICON
)) / 2;
1567 y
= (WindowRect
.bottom
- WindowRect
.top
-
1568 GetSystemMetrics(SM_CYICON
)) / 2;
1569 DrawIcon(hDC
, x
, y
, hIcon
);
1571 if (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_CLIENTEDGE
)
1574 GetClientRect(hWnd
, &WindowRect
);
1575 DrawEdge(hDC
, &WindowRect
, EDGE_SUNKEN
, BF_RECT
);
1577 EndPaint(hWnd
, &Ps
);
1585 hRgn
= CreateRectRgn(0, 0, 0, 0);
1586 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1588 RedrawWindow(hWnd
, NULL
, hRgn
,
1589 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1598 DefWndSetRedraw(hWnd
, wParam
);
1604 DestroyWindow(hWnd
);
1608 case WM_MOUSEACTIVATE
:
1610 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1615 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1620 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1628 return((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1633 /* Check if the window is minimized. */
1634 if (LOWORD(lParam
) != WA_INACTIVE
&&
1635 !(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1644 if (GetWindowLong(hWnd
, GWL_STYLE
& WS_CHILD
))
1648 return(SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1653 return(SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1661 case WM_ICONERASEBKGND
:
1665 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1666 GetClipBox((HDC
)wParam
, &Rect
);
1667 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1676 /* FIXME: Implement colour controls. */
1680 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1682 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1687 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1692 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1701 return(DefWndHandleSetCursor(hWnd
, wParam
, lParam
));
1707 Pt
.x
= SLOWORD(lParam
);
1708 Pt
.y
= SHIWORD(lParam
);
1709 return(DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1712 /* FIXME: Handle key messages. */
1720 /* FIXME: Not done correctly */
1721 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
&& !wParam
) ||
1722 (!(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
) && wParam
))
1726 ShowWindow(hWnd
, wParam
? SW_SHOWNA
: SW_HIDE
);
1732 /* FIXME: Check for a desktop. */
1733 if (GetCapture() == hWnd
)
1745 /* FIXME: Implement this. */
1748 case WM_QUERYDROPOBJECT
:
1750 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1757 case WM_QUERYDRAGICON
:
1762 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1765 return((LRESULT
)hIcon
);
1767 for (Len
= 1; Len
< 64; Len
++)
1769 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCE(Len
))) != NULL
)
1771 return((LRESULT
)hIcon
);
1774 return((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1777 /* FIXME: WM_ISACTIVEICON */
1779 case WM_NOTIFYFORMAT
:
1781 if (IsWindowUnicode(hWnd
))
1783 return(NFR_UNICODE
);
1793 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1794 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1795 SetClassLongW(hWnd
, Index
, lParam
);
1796 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1797 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1798 SWP_NOACTIVATE
| SWP_NOZORDER
);
1799 return((LRESULT
)hOldIcon
);
1804 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1805 return(GetClassLongW(hWnd
, Index
));
1812 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1816 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1822 if (HIWORD(lParam
) & KEYDATA_ALT
)
1824 if (wParam
== VK_F4
) /* Try to close the window */
1826 //HWND hTopWnd = GetAncestor(hWnd, GA_ROOT);
1827 HWND hTopWnd
= hWnd
;
1828 if (!(GetClassLongW(hTopWnd
, GCL_STYLE
) & CS_NOCLOSE
))
1832 PostMessageW(hTopWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1836 PostMessageA(hTopWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1848 DefWindowProcA(HWND hWnd
,
1854 static LPSTR WindowTextAtom
= 0;
1861 CREATESTRUCTA
* Cs
= (CREATESTRUCTA
*)lParam
;
1862 if (HIWORD(Cs
->lpszName
))
1864 if (0 == WindowTextAtom
)
1867 (LPSTR
)(ULONG
)GlobalAddAtomA("USER32!WindowTextAtomA");
1869 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1870 strlen(Cs
->lpszName
) * sizeof(CHAR
));
1871 strcpy(WindowText
, Cs
->lpszName
);
1872 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1879 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1882 case WM_WINDOWPOSCHANGING
:
1884 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1887 case WM_GETTEXTLENGTH
:
1889 if (WindowTextAtom
== 0 ||
1890 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1894 return(strlen(WindowText
));
1899 if (WindowTextAtom
== 0 ||
1900 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1904 *((PSTR
)lParam
) = '\0';
1908 strncpy((LPSTR
)lParam
, WindowText
, wParam
);
1909 return(min(wParam
, strlen(WindowText
)));
1914 if (0 == WindowTextAtom
)
1917 (LPSTR
)(DWORD
)GlobalAddAtomA("USER32!WindowTextAtomW");
1919 if (WindowTextAtom
!= 0 &&
1920 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1922 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
1924 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1925 strlen((PSTR
)lParam
) * sizeof(CHAR
));
1926 strcpy(WindowText
, (PSTR
)lParam
);
1927 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1928 if (0 != (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
))
1930 DefWndPaintNC(hWnd
, (HRGN
) 1);
1932 Result
= (LPARAM
) TRUE
;
1938 if (WindowTextAtom
!= 0 &&
1939 (WindowText
= RemovePropA(hWnd
, WindowTextAtom
)) == NULL
)
1941 RtlFreeHeap(GetProcessHeap(), 0, WindowText
);
1947 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1956 DefWindowProcW(HWND hWnd
,
1962 static LPWSTR WindowTextAtom
= 0;
1969 CREATESTRUCTW
* Cs
= (CREATESTRUCTW
*)lParam
;
1970 if (HIWORD(Cs
->lpszName
))
1972 if (0 == WindowTextAtom
)
1975 (LPWSTR
)(DWORD
)GlobalAddAtomW(L
"USER32!WindowTextAtomW");
1977 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1978 wcslen(Cs
->lpszName
) * sizeof(WCHAR
));
1979 wcscpy(WindowText
, Cs
->lpszName
);
1980 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
1987 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1990 case WM_WINDOWPOSCHANGING
:
1992 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1995 case WM_GETTEXTLENGTH
:
1997 if (WindowTextAtom
== 0 ||
1998 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2002 return(wcslen(WindowText
));
2007 if (WindowTextAtom
== 0 ||
2008 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2012 ((PWSTR
)lParam
) = '\0';
2016 wcsncpy((PWSTR
)lParam
, WindowText
, wParam
);
2017 return(min(wParam
, wcslen(WindowText
)));
2022 if (WindowTextAtom
!= 0)
2025 (LPWSTR
)(DWORD
)GlobalAddAtom(L
"USER32!WindowTextAtomW");
2027 if (WindowTextAtom
!= 0 &&
2028 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
2030 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
2032 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
2033 wcslen((PWSTR
)lParam
) * sizeof(WCHAR
));
2034 wcscpy(WindowText
, (PWSTR
)lParam
);
2035 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
2036 if (0 != (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
))
2038 DefWndPaintNC(hWnd
, (HRGN
) 1);
2040 Result
= (LPARAM
) TRUE
;
2046 if (WindowTextAtom
!= 0 &&
2047 (WindowText
= RemovePropW(hWnd
, WindowTextAtom
)) == NULL
)
2049 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
2055 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);