1 /* $Id: defwnd.c,v 1.113 2003/12/22 20:22:40 navaraf 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 LRESULT
DefWndNCPaint(HWND hWnd
, HRGN hRgn
);
27 LRESULT
DefWndNCCalcSize(HWND hWnd
, BOOL CalcSizeStruct
, RECT
*Rect
);
28 LRESULT
DefWndNCActivate(HWND hWnd
, WPARAM wParam
);
29 LRESULT
DefWndNCHitTest(HWND hWnd
, POINT Point
);
30 LRESULT
DefWndNCLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
31 LRESULT
DefWndNCLButtonDblClk(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
32 VOID
DefWndTrackScrollBar(HWND hWnd
, WPARAM wParam
, POINT Point
);
34 /* GLOBALS *******************************************************************/
36 /* TODO: widgets will be cached here.
37 static HBITMAP hbClose;
38 static HBITMAP hbCloseD;
39 static HBITMAP hbMinimize;
40 static HBITMAP hbMinimizeD;
41 static HBITMAP hbRestore;
42 static HBITMAP hbRestoreD;
43 static HBITMAP hbMaximize;
44 static HBITMAP hbScrUp;
45 static HBITMAP hbScrDwn;
46 static HBITMAP hbScrLeft;
47 static HBITMAP hbScrRight;
51 static COLORREF SysColours
[] =
53 RGB(192, 192, 192) /* COLOR_SCROLLBAR */,
54 RGB(58, 110, 165) /* COLOR_BACKGROUND */,
55 RGB(0, 0, 128) /* COLOR_ACTIVECAPTION */,
56 RGB(128, 128, 128) /* COLOR_INACTIVECAPTION */,
57 RGB(192, 192, 192) /* COLOR_MENU */,
58 RGB(255, 255, 255) /* COLOR_WINDOW */,
59 RGB(0, 0, 0) /* COLOR_WINDOWFRAME */,
60 RGB(0, 0, 0) /* COLOR_MENUTEXT */,
61 RGB(0, 0, 0) /* COLOR_WINDOWTEXT */,
62 RGB(255, 255, 255) /* COLOR_CAPTIONTEXT */,
63 RGB(192, 192, 192) /* COLOR_ACTIVEBORDER */,
64 RGB(192, 192, 192) /* COLOR_INACTIVEBORDER */,
65 RGB(128, 128, 128) /* COLOR_APPWORKSPACE */,
66 RGB(0, 0, 128) /* COLOR_HILIGHT */,
67 RGB(255, 255, 255) /* COLOR_HILIGHTTEXT */,
68 RGB(192, 192, 192) /* COLOR_BTNFACE */,
69 RGB(128, 128, 128) /* COLOR_BTNSHADOW */,
70 RGB(128, 128, 128) /* COLOR_GRAYTEXT */,
71 RGB(0, 0, 0) /* COLOR_BTNTEXT */,
72 RGB(192, 192, 192) /* COLOR_INACTIVECAPTIONTEXT */,
73 RGB(255, 255, 255) /* COLOR_BTNHILIGHT */,
74 RGB(32, 32, 32) /* COLOR_3DDKSHADOW */,
75 RGB(192, 192, 192) /* COLOR_3DLIGHT */,
76 RGB(0, 0, 0) /* COLOR_INFOTEXT */,
77 RGB(255, 255, 192) /* COLOR_INFOBK */,
78 RGB(180, 180, 180) /* COLOR_ALTERNATEBTNFACE */,
79 RGB(0, 0, 255) /* COLOR_HOTLIGHT */,
80 RGB(16, 132, 208) /* COLOR_GRADIENTACTIVECAPTION */,
81 RGB(181, 181, 181) /* COLOR_GRADIENTINACTIVECAPTION */,
84 #define NUM_SYSCOLORS (sizeof(SysColours) / sizeof(SysColours[0]))
88 /* Bits in the dwKeyData */
89 #define KEYDATA_ALT 0x2000
91 /* FUNCTIONS *****************************************************************/
94 UserSetupInternalPos(VOID
)
97 AtomInternalPos
= GlobalAddAtomA(Str
);
104 GetSysColor(int nIndex
)
106 return SysColours
[nIndex
];
113 GetSysColorPen(int nIndex
)
115 static HPEN SysPens
[NUM_SYSCOLORS
];
117 if (nIndex
< 0 || NUM_SYSCOLORS
< nIndex
)
119 SetLastError(ERROR_INVALID_PARAMETER
);
123 /* FIXME should register this object with DeleteObject() so it
125 if (NULL
== SysPens
[nIndex
])
127 SysPens
[nIndex
] = CreatePen(PS_SOLID
, 1, SysColours
[nIndex
]);
130 return SysPens
[nIndex
];
137 GetSysColorBrush(int nIndex
)
139 static HBRUSH SysBrushes
[NUM_SYSCOLORS
];
141 if (nIndex
< 0 || NUM_SYSCOLORS
< nIndex
)
143 SetLastError(ERROR_INVALID_PARAMETER
);
147 /* FIXME should register this object with DeleteObject() so it
149 if (NULL
== SysBrushes
[nIndex
])
151 SysBrushes
[nIndex
] = (HBRUSH
) ((DWORD
) CreateSolidBrush(SysColours
[nIndex
]) | 0x00800000);
154 return SysBrushes
[nIndex
];
162 DefFrameProcA( HWND hWnd,
178 DefFrameProcW(HWND hWnd,
190 UserGetInternalPos(HWND hWnd
)
193 lpPos
= (PINTERNALPOS
)GetPropA(hWnd
, (LPSTR
)(DWORD
)AtomInternalPos
);
198 UserHasAnyFrameStyle(ULONG Style
, ULONG ExStyle
)
200 return ((Style
& (WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
)) ||
201 (ExStyle
& WS_EX_DLGMODALFRAME
) ||
202 (!(Style
& (WS_CHILD
| WS_POPUP
))));
206 UserHasDlgFrameStyle(ULONG Style
, ULONG ExStyle
)
208 return ((ExStyle
& WS_EX_DLGMODALFRAME
) ||
209 ((Style
& WS_DLGFRAME
) && (!(Style
& WS_THICKFRAME
))));
213 UserHasThickFrameStyle(ULONG Style
, ULONG ExStyle
)
215 return ((Style
& WS_THICKFRAME
) &&
216 (!((Style
& (WS_DLGFRAME
| WS_BORDER
)) == WS_DLGFRAME
)));
220 UserHasThinFrameStyle(ULONG Style
, ULONG ExStyle
)
222 return ((Style
& WS_BORDER
) || (!(Style
& (WS_CHILD
| WS_POPUP
))));
226 UserHasBigFrameStyle(ULONG Style
, ULONG ExStyle
)
228 return ((Style
& (WS_THICKFRAME
| WS_DLGFRAME
)) ||
229 (ExStyle
& WS_EX_DLGMODALFRAME
));
233 UserGetInsideRectNC(HWND hWnd
, RECT
*rect
)
239 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
240 ExStyle
= GetWindowLongW(hWnd
, GWL_EXSTYLE
);
241 GetWindowRect(hWnd
, &WindowRect
);
242 rect
->top
= rect
->left
= 0;
243 rect
->right
= WindowRect
.right
- WindowRect
.left
;
244 rect
->bottom
= WindowRect
.bottom
- WindowRect
.top
;
246 if (Style
& WS_ICONIC
)
251 /* Remove frame from rectangle */
252 if (UserHasThickFrameStyle(Style
, ExStyle
))
254 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
),
255 -GetSystemMetrics(SM_CYFRAME
));
259 if (UserHasDlgFrameStyle(Style
, ExStyle
))
261 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
262 -GetSystemMetrics(SM_CYDLGFRAME
));
263 /* FIXME: this isn't in NC_AdjustRect? why not? */
264 if (ExStyle
& WS_EX_DLGMODALFRAME
)
265 InflateRect( rect
, -1, 0 );
269 if (UserHasThinFrameStyle(Style
, ExStyle
))
271 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
272 -GetSystemMetrics(SM_CYBORDER
));
280 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
287 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
289 /* Not for child windows. */
290 if (hWnd
!= (HWND
)wParam
)
295 switch(LOWORD(lParam
))
299 WORD Msg
= HIWORD(lParam
);
300 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
301 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
310 HICON hCursor
= (HICON
)GetClassLongW(hWnd
, GCL_HCURSOR
);
322 if (Style
& WS_MAXIMIZE
)
326 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
332 if (Style
& WS_MAXIMIZE
)
336 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
342 if (Style
& WS_MAXIMIZE
)
346 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
352 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
356 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
359 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
363 DefWndStartSizeMove(HWND hWnd
, WPARAM wParam
, POINT
*capturePoint
)
369 ULONG Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
371 GetWindowRect(hWnd
, &rectWindow
);
373 if ((wParam
& 0xfff0) == SC_MOVE
)
375 /* Move pointer at the center of the caption */
377 UserGetInsideRectNC(hWnd
, &rect
);
378 if (Style
& WS_SYSMENU
)
379 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
380 if (Style
& WS_MINIMIZEBOX
)
381 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
382 if (Style
& WS_MAXIMIZEBOX
)
383 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
384 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
385 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
393 GetMessageW(&msg
, NULL
, 0, 0);
397 hittest
= DefWndNCHitTest(hWnd
, msg
.pt
);
398 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
410 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
411 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
415 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
416 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
420 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
421 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
425 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
426 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
429 case VK_ESCAPE
: return 0;
435 SetCursorPos( pt
.x
, pt
.y
);
436 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
), Style
);
440 #define ON_LEFT_BORDER(hit) \
441 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
442 #define ON_RIGHT_BORDER(hit) \
443 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
444 #define ON_TOP_BORDER(hit) \
445 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
446 #define ON_BOTTOM_BORDER(hit) \
447 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
450 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
451 ULONG width
, ULONG height
, DWORD rop
)
453 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
454 PatBlt( hdc
, rect
->left
, rect
->top
,
455 rect
->right
- rect
->left
- width
, height
, rop
);
456 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
457 rect
->bottom
- rect
->top
- height
, rop
);
458 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
459 rect
->right
- rect
->left
- width
, -height
, rop
);
460 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
461 rect
->bottom
- rect
->top
- height
, rop
);
462 SelectObject( hdc
, hbrush
);
466 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
470 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
),
471 GetSystemMetrics(SM_CYFRAME
), PATINVERT
);
473 else DrawFocusRect( hdc
, rect
);
477 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
480 RECT sizingRect
, mouseRect
, origRect
, clipRect
;
482 LONG hittest
= (LONG
)(wParam
& 0x0f);
483 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
484 POINT minTrack
, maxTrack
;
485 POINT capturePoint
, pt
;
486 ULONG Style
= GetWindowLongW(hwnd
, GWL_STYLE
);
487 ULONG ExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
488 BOOL thickframe
= UserHasThickFrameStyle(Style
, ExStyle
);
489 BOOL iconic
= Style
& WS_MINIMIZE
;
491 DWORD dwPoint
= GetMessagePos();
492 BOOL DragFullWindows
= FALSE
;
495 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
497 pt
.x
= SLOWORD(dwPoint
);
498 pt
.y
= SHIWORD(dwPoint
);
501 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
))
506 if ((wParam
& 0xfff0) == SC_MOVE
)
510 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
523 if (hittest
&& hittest
!= HTSYSMENU
)
530 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
539 if (Style
& WS_CHILD
)
541 hWndParent
= GetParent(hwnd
);
544 /* Get min/max info */
546 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
547 GetWindowRect(hwnd
, &sizingRect
);
548 if (Style
& WS_CHILD
)
550 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
551 GetClientRect(hWndParent
, &mouseRect
);
552 clipRect
= mouseRect
;
553 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
557 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
),
558 GetSystemMetrics(SM_CYSCREEN
));
559 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &clipRect
, 0);
561 ClipCursor(&clipRect
);
563 origRect
= sizingRect
;
564 if (ON_LEFT_BORDER(hittest
))
566 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
567 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
569 else if (ON_RIGHT_BORDER(hittest
))
571 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
572 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
574 if (ON_TOP_BORDER(hittest
))
576 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
577 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
579 else if (ON_BOTTOM_BORDER(hittest
))
581 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
582 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
584 if (Style
& WS_CHILD
)
586 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
588 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
590 if (GetCapture() != hwnd
) SetCapture( hwnd
);
592 if (Style
& WS_CHILD
)
594 /* Retrieve a default cache DC (without using the window style) */
595 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
602 if( iconic
) /* create a cursor for dragging */
604 HICON hIcon
= (HICON
)GetClassLongW(hwnd
, GCL_HICON
);
605 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
606 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
607 if( !hDragCursor
) iconic
= FALSE
;
610 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
611 if( !iconic
&& !DragFullWindows
)
613 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
620 GetMessageW(&msg
, 0, 0, 0);
622 /* Exit on button-up, Return, or Esc */
623 if ((msg
.message
== WM_LBUTTONUP
) ||
624 ((msg
.message
== WM_KEYDOWN
) &&
625 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
627 if (msg
.message
== WM_PAINT
)
629 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
630 UpdateWindow( msg
.hwnd
);
631 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
635 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
636 continue; /* We are not interested in other messages */
640 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
642 case VK_UP
: pt
.y
-= 8; break;
643 case VK_DOWN
: pt
.y
+= 8; break;
644 case VK_LEFT
: pt
.x
-= 8; break;
645 case VK_RIGHT
: pt
.x
+= 8; break;
648 pt
.x
= max( pt
.x
, mouseRect
.left
);
649 pt
.x
= min( pt
.x
, mouseRect
.right
);
650 pt
.y
= max( pt
.y
, mouseRect
.top
);
651 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
653 dx
= pt
.x
- capturePoint
.x
;
654 dy
= pt
.y
- capturePoint
.y
;
662 if( iconic
) /* ok, no system popup tracking */
664 hOldCursor
= SetCursor(hDragCursor
);
666 WinPosShowIconTitle( hwnd
, FALSE
);
670 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
673 RECT newRect
= sizingRect
;
674 WPARAM wpSizingHit
= 0;
676 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
677 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
678 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
679 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
680 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
681 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
684 /* determine the hit location */
685 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
686 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
687 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
692 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
694 /* To avoid any deadlocks, all the locks on the windows
695 structures must be suspended before the SetWindowPos */
696 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
697 newRect
.right
- newRect
.left
,
698 newRect
.bottom
- newRect
.top
,
699 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
702 sizingRect
= newRect
;
711 if( moved
) /* restore cursors, show icon title later on */
714 SetCursor( hOldCursor
);
716 DestroyCursor( hDragCursor
);
718 else if(!DragFullWindows
)
719 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
721 if (Style
& WS_CHILD
)
722 ReleaseDC( hWndParent
, hdc
);
726 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
727 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
729 /* window moved or resized */
732 /* if the moving/resizing isn't canceled call SetWindowPos
733 * with the new position or the new size of the window
735 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
737 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
739 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
740 sizingRect
.right
- sizingRect
.left
,
741 sizingRect
.bottom
- sizingRect
.top
,
742 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
744 else { /* restore previous size/position */
746 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
747 origRect
.right
- origRect
.left
,
748 origRect
.bottom
- origRect
.top
,
749 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
754 if( Style
& WS_MINIMIZE
)
756 /* Single click brings up the system menu when iconized */
760 if( Style
& WS_SYSMENU
)
761 SendMessageA( hwnd
, WM_SYSCOMMAND
,
762 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
764 else WinPosShowIconTitle( hwnd
, TRUE
);
770 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
774 switch (wParam
& 0xfff0)
778 DefWndDoSizeMove(hWnd
, wParam
);
781 wp
.length
= sizeof(WINDOWPLACEMENT
);
782 if(GetWindowPlacement(hWnd
, &wp
))
784 wp
.showCmd
= SW_MINIMIZE
;
785 SetWindowPlacement(hWnd
, &wp
);
789 wp
.length
= sizeof(WINDOWPLACEMENT
);
790 if(GetWindowPlacement(hWnd
, &wp
))
792 wp
.showCmd
= SW_MAXIMIZE
;
793 SetWindowPlacement(hWnd
, &wp
);
797 wp
.length
= sizeof(WINDOWPLACEMENT
);
798 if(GetWindowPlacement(hWnd
, &wp
))
800 wp
.showCmd
= SW_RESTORE
;
801 SetWindowPlacement(hWnd
, &wp
);
805 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
808 MenuTrackMouseMenuBar(hWnd
, wParam
, Pt
);
811 MenuTrackKbdMenuBar(hWnd
, wParam
, Pt
.x
);
815 /* FIXME: Implement */
824 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
826 POINT maxSize
, minTrack
;
827 LONG style
= GetWindowLongA(hWnd
, GWL_STYLE
);
829 if (Pos
->flags
& SWP_NOSIZE
) return 0;
830 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
832 WinPosGetMinMaxInfo(hWnd
, &maxSize
, NULL
, &minTrack
, NULL
);
833 Pos
->cx
= min(Pos
->cx
, maxSize
.x
);
834 Pos
->cy
= min(Pos
->cy
, maxSize
.y
);
835 if (!(style
& WS_MINIMIZE
))
837 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
838 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
844 /* Undocumented flags. */
845 #define SWP_NOCLIENTMOVE 0x0800
846 #define SWP_NOCLIENTSIZE 0x1000
849 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
853 GetClientRect(hWnd
, &Rect
);
854 MapWindowPoints(hWnd
, (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
?
855 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
857 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
859 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
862 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
864 WPARAM wp
= SIZE_RESTORED
;
869 else if (IsIconic(hWnd
))
873 SendMessageW(hWnd
, WM_SIZE
, wp
,
874 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
880 /***********************************************************************
883 * Default colors for control painting.
886 DefWndControlColor(HDC hDC
, UINT ctlType
)
888 if (CTLCOLOR_SCROLLBAR
== ctlType
)
890 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
891 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
892 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
895 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
896 * we better use 0x55aa bitmap brush to make scrollbar's background
897 * look different from the window background.
899 if (bk
== GetSysColor(COLOR_WINDOW
))
902 return CACHE_GetPattern55AABrush();
911 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
913 if ((CTLCOLOR_EDIT
== ctlType
) || (CTLCOLOR_LISTBOX
== ctlType
))
915 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
919 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
920 return GetSysColorBrush(COLOR_3DFACE
);
923 return GetSysColorBrush(COLOR_WINDOW
);
927 DefWndScreenshot(HWND hWnd
)
933 User32DefWindowProc(HWND hWnd
,
943 return DefWndNCPaint(hWnd
, (HRGN
)wParam
);
948 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
953 return DefWndNCActivate(hWnd
, wParam
);
959 Point
.x
= SLOWORD(lParam
);
960 Point
.y
= SHIWORD(lParam
);
961 return (DefWndNCHitTest(hWnd
, Point
));
964 case WM_NCLBUTTONDOWN
:
966 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
969 case WM_LBUTTONDBLCLK
:
970 case WM_NCLBUTTONDBLCLK
:
972 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
975 case WM_NCRBUTTONDOWN
:
977 if (wParam
== HTCAPTION
)
984 case WM_WINDOWPOSCHANGING
:
986 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
989 case WM_WINDOWPOSCHANGED
:
991 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
997 if (hWnd
== GetCapture())
1001 Pt
.x
= SLOWORD(lParam
);
1002 Pt
.y
= SHIWORD(lParam
);
1003 ClientToScreen(hWnd
, &Pt
);
1004 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1007 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1011 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1016 case WM_CONTEXTMENU
:
1018 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1022 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1026 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1034 Pt
.x
= SLOWORD(lParam
);
1035 Pt
.y
= SHIWORD(lParam
);
1036 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1038 ScreenToClient(GetParent(hWnd
), &Pt
);
1041 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1043 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1045 TrackPopupMenu(GetSystemMenu(hWnd
, FALSE
),
1046 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
1047 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1055 /* FIXME: Implement. */
1063 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1067 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1068 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1072 GetClientRect(hWnd
, &ClientRect
);
1073 x
= (ClientRect
.right
- ClientRect
.left
-
1074 GetSystemMetrics(SM_CXICON
)) / 2;
1075 y
= (ClientRect
.bottom
- ClientRect
.top
-
1076 GetSystemMetrics(SM_CYICON
)) / 2;
1077 DrawIcon(hDC
, x
, y
, hIcon
);
1079 EndPaint(hWnd
, &Ps
);
1087 hRgn
= CreateRectRgn(0, 0, 0, 0);
1088 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1090 RedrawWindow(hWnd
, NULL
, hRgn
,
1091 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1100 DefWndSetRedraw(hWnd
, wParam
);
1106 DestroyWindow(hWnd
);
1110 case WM_MOUSEACTIVATE
:
1112 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1117 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1122 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1130 return ((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1135 /* Check if the window is minimized. */
1136 if (LOWORD(lParam
) != WA_INACTIVE
&&
1137 !(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1146 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1150 return (SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1155 return (SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1163 case WM_ICONERASEBKGND
:
1166 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1172 if (GetClassLongW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1174 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1175 GetClientRect(hWnd
, &Rect
);
1176 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1180 GetClipBox((HDC
)wParam
, &Rect
);
1182 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1186 case WM_CTLCOLORMSGBOX
:
1187 case WM_CTLCOLOREDIT
:
1188 case WM_CTLCOLORLISTBOX
:
1189 case WM_CTLCOLORBTN
:
1190 case WM_CTLCOLORDLG
:
1191 case WM_CTLCOLORSTATIC
:
1192 case WM_CTLCOLORSCROLLBAR
:
1193 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1197 ULONG Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1199 if (Style
& WS_CHILD
)
1201 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1206 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1211 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1220 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1226 Pt
.x
= SLOWORD(lParam
);
1227 Pt
.y
= SHIWORD(lParam
);
1228 return (DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1231 /* FIXME: Handle key messages. */
1239 /* FIXME: This is also incomplete. */
1242 if (HIWORD(lParam
) & KEYDATA_ALT
)
1244 if (wParam
== VK_F4
) /* Try to close the window */
1246 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1247 if (!(GetClassLongW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1250 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1252 PostMessageA(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1255 else if (wParam
== VK_SNAPSHOT
)
1257 DefWndScreenshot(hWnd
);
1269 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1270 if (!(Style
& WS_POPUP
))
1272 if ((Style
& WS_VISIBLE
) && wParam
)
1274 if (!(Style
& WS_VISIBLE
) && !wParam
)
1276 if (!GetWindow(hWnd
, GW_OWNER
))
1278 ShowWindow(hWnd
, wParam
? SW_SHOWNA
: SW_HIDE
);
1284 /* FIXME: Check for a desktop. */
1285 if (GetCapture() == hWnd
)
1300 case WM_QUERYDROPOBJECT
:
1302 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1309 case WM_QUERYDRAGICON
:
1314 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1317 return ((LRESULT
)hIcon
);
1319 for (Len
= 1; Len
< 64; Len
++)
1321 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1323 return((LRESULT
)hIcon
);
1326 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1329 /* FIXME: WM_ISACTIVEICON */
1331 case WM_NOTIFYFORMAT
:
1333 if (IsWindowUnicode(hWnd
))
1335 return(NFR_UNICODE
);
1345 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1346 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1347 SetClassLongW(hWnd
, Index
, lParam
);
1348 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1349 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1350 SWP_NOACTIVATE
| SWP_NOZORDER
);
1351 return ((LRESULT
)hOldIcon
);
1356 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1357 return (GetClassLongW(hWnd
, Index
));
1364 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1368 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1375 THRDCARETINFO CaretInfo
;
1378 case 0xffff: /* Caret timer */
1379 /* switch showing byte in win32k and get information about the caret */
1380 if(NtUserCallOneParam((DWORD
)&CaretInfo
, ONEPARAM_ROUTINE_SWITCHCARETSHOWING
) && (CaretInfo
.hWnd
== hWnd
))
1382 DrawCaret(hWnd
, &CaretInfo
);
1390 case WM_QUERYENDSESSION
:
1400 DefWindowProcA(HWND hWnd
,
1412 case WM_GETTEXTLENGTH
:
1414 return InternalGetWindowText(hWnd
, NULL
, 0);
1419 UNICODE_STRING UnicodeString
;
1420 LPSTR AnsiBuffer
= (LPSTR
)lParam
;
1425 *((PWSTR
)lParam
) = '\0';
1427 UnicodeString
.Length
= UnicodeString
.MaximumLength
=
1428 wParam
* sizeof(WCHAR
);
1429 UnicodeString
.Buffer
= HeapAlloc(GetProcessHeap(), 0,
1430 UnicodeString
.Length
);
1431 if (!UnicodeString
.Buffer
)
1433 Result
= InternalGetWindowText(hWnd
, UnicodeString
.Buffer
, wParam
);
1435 !WideCharToMultiByte(CP_ACP
, 0, UnicodeString
.Buffer
, -1,
1436 AnsiBuffer
, wParam
, NULL
, NULL
))
1438 AnsiBuffer
[wParam
- 1] = 0;
1440 HeapFree(GetProcessHeap(), 0, UnicodeString
.Buffer
);
1447 ANSI_STRING AnsiString
;
1448 RtlInitAnsiString(&AnsiString
, (LPSTR
)lParam
);
1449 NtUserDefSetText(hWnd
, &AnsiString
);
1450 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1452 DefWndNCPaint(hWnd
, (HRGN
)1);
1458 FIXME: Implement these.
1460 case WM_IME_KEYDOWN:
1462 case WM_IME_STARTCOMPOSITION:
1463 case WM_IME_COMPOSITION:
1464 case WM_IME_ENDCOMPOSITION:
1466 case WM_IME_SETCONTEXT:
1470 return User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1475 DefWindowProcW(HWND hWnd
,
1487 case WM_GETTEXTLENGTH
:
1489 return InternalGetWindowText(hWnd
, NULL
, 0);
1497 *((PWSTR
)lParam
) = '\0';
1499 Result
= InternalGetWindowText(hWnd
, (PWSTR
)lParam
, wParam
);
1505 UNICODE_STRING UnicodeString
;
1506 ANSI_STRING AnsiString
;
1508 RtlInitUnicodeString(&UnicodeString
, (LPWSTR
)lParam
);
1509 RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
1510 NtUserDefSetText(hWnd
, &AnsiString
);
1511 RtlFreeAnsiString(&AnsiString
);
1512 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1514 DefWndNCPaint(hWnd
, (HRGN
)1);
1521 SendMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
1525 case WM_IME_SETCONTEXT
:
1532 return User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);