Release 940815
[wine/gsoc-2012-control.git] / windows / nonclient.c
blob2bb188e3667def6cb9c1b625433b6dcfb7eda7da
1 /*
2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
5 */
7 static char Copyright[] = "Copyright Alexandre Julliard, 1994";
9 #include "win.h"
10 #include "class.h"
11 #include "message.h"
12 #include "sysmetrics.h"
13 #include "user.h"
14 #include "scroll.h"
15 #include "syscolor.h"
17 static HBITMAP hbitmapClose = 0;
18 static HBITMAP hbitmapMDIClose = 0;
19 static HBITMAP hbitmapMinimize = 0;
20 static HBITMAP hbitmapMinimizeD = 0;
21 static HBITMAP hbitmapMaximize = 0;
22 static HBITMAP hbitmapMaximizeD = 0;
23 static HBITMAP hbitmapRestore = 0;
24 static HBITMAP hbitmapRestoreD = 0;
26 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
27 extern HINSTANCE hSysRes;
28 extern BOOL AboutWine_Proc( HWND hDlg, WORD msg, WORD wParam, LONG lParam );
30 extern void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
31 POINT *minTrack, POINT *maxTrack ); /* winpos.c */
32 extern void CURSOR_SetWinCursor( HWND hwnd, HCURSOR hcursor ); /* cursor.c */
33 extern WORD MENU_GetMenuBarHeight( HWND hwnd, WORD menubarWidth,
34 int orgX, int orgY ); /* menu.c */
35 extern void MENU_TrackMouseMenuBar( HWND hwnd, POINT pt ); /* menu.c */
36 extern void MENU_TrackKbdMenuBar( HWND hwnd, WORD wParam ); /* menu.c */
37 extern WORD MENU_DrawMenuBar( HDC hDC, LPRECT lprect,
38 HMENU hmenu, BOOL suppress_draw ); /* menu.c */
41 /* Some useful macros */
42 #define HAS_DLGFRAME(style,exStyle) \
43 (((style) & WS_DLGFRAME) && \
44 (((exStyle) & WS_EX_DLGMODALFRAME) || !((style) & WS_BORDER)))
46 #define HAS_THICKFRAME(style) \
47 (((style) & WS_THICKFRAME) && \
48 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
50 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
52 #define ON_LEFT_BORDER(hit) \
53 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
54 #define ON_RIGHT_BORDER(hit) \
55 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
56 #define ON_TOP_BORDER(hit) \
57 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
58 #define ON_BOTTOM_BORDER(hit) \
59 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
61 /***********************************************************************
62 * NC_AdjustRect
64 * Compute the size of the window rectangle from the size of the
65 * client rectangle.
67 static void NC_AdjustRect( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
69 if (HAS_DLGFRAME( style, exStyle ))
70 InflateRect( rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
71 else
73 if (HAS_THICKFRAME(style))
74 InflateRect( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
75 if (style & WS_BORDER)
76 InflateRect( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER );
79 if ((style & WS_CAPTION) == WS_CAPTION)
80 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
81 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
83 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
84 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
88 /***********************************************************************
89 * AdjustWindowRect (USER.102)
91 void AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
93 AdjustWindowRectEx( rect, style, menu, 0 );
97 /***********************************************************************
98 * AdjustWindowRectEx (USER.454)
100 void AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
102 /* Correct the window style */
104 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
105 style |= WS_CAPTION;
106 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
108 #ifdef DEBUG_NONCLIENT
109 printf( "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08x %d %08x\n",
110 rect->left, rect->top, rect->right, rect->bottom, style, menu, exStyle );
111 #endif
113 NC_AdjustRect( rect, style, menu, exStyle );
117 /***********************************************************************
118 * NC_HandleNCCalcSize
120 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
122 LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params )
124 RECT tmpRect = { 0, 0, 0, 0 };
125 WND *wndPtr = WIN_FindWndPtr( hwnd );
127 if (!wndPtr) return 0;
129 NC_AdjustRect( &tmpRect, wndPtr->dwStyle, FALSE, wndPtr->dwExStyle );
130 params->rgrc[0].left -= tmpRect.left;
131 params->rgrc[0].top -= tmpRect.top;
132 params->rgrc[0].right -= tmpRect.right;
133 params->rgrc[0].bottom -= tmpRect.bottom;
135 if (HAS_MENU(wndPtr))
137 params->rgrc[0].top += MENU_GetMenuBarHeight( hwnd,
138 params->rgrc[0].right - params->rgrc[0].left,
139 -tmpRect.left, -tmpRect.top ) + 1;
141 return 0;
145 /***********************************************************************
146 * NC_GetInsideRect
148 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
149 * but without the borders (if any).
150 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
152 void NC_GetInsideRect( HWND hwnd, RECT *rect )
154 WND * wndPtr = WIN_FindWndPtr( hwnd );
156 rect->top = rect->left = 0;
157 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
158 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
160 /* Remove frame from rectangle */
161 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
163 InflateRect( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
164 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) InflateRect( rect, -1, 0);
166 else
168 if (HAS_THICKFRAME( wndPtr->dwStyle ))
169 InflateRect( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
170 if (wndPtr->dwStyle & WS_BORDER)
171 InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
176 /***********************************************************************
177 * NC_InternalNCHitTest
179 * Perform the hit test calculation, but whithout testing the capture
180 * window.
182 static LONG NC_InternalNCHitTest( HWND hwnd, POINT pt )
184 RECT rect;
185 WND *wndPtr = WIN_FindWndPtr( hwnd );
186 if (!wndPtr) return HTERROR;
188 GetWindowRect( hwnd, &rect );
189 if (!PtInRect( &rect, pt )) return HTNOWHERE;
191 /* Check borders */
193 if (HAS_THICKFRAME( wndPtr->dwStyle ))
195 InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
196 if (wndPtr->dwStyle & WS_BORDER)
197 InflateRect( &rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
198 if (!PtInRect( &rect, pt ))
200 /* Check top sizing border */
201 if (pt.y < rect.top)
203 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
204 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
205 return HTTOP;
207 /* Check bottom sizing border */
208 if (pt.y >= rect.bottom)
210 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
211 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
212 return HTBOTTOM;
214 /* Check left sizing border */
215 if (pt.x < rect.left)
217 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
218 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
219 return HTLEFT;
221 /* Check right sizing border */
222 if (pt.x >= rect.right)
224 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
225 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
226 return HTRIGHT;
230 else /* No thick frame */
232 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
233 InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
234 else if (wndPtr->dwStyle & WS_BORDER)
235 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
236 if (!PtInRect( &rect, pt )) return HTBORDER;
239 /* Check caption */
241 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
243 rect.top += SYSMETRICS_CYCAPTION - 1;
244 if (!PtInRect( &rect, pt ))
246 /* Check system menu */
247 if (wndPtr->dwStyle & WS_SYSMENU)
248 rect.left += SYSMETRICS_CXSIZE;
249 if (pt.x <= rect.left) return HTSYSMENU;
250 /* Check maximize box */
251 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
252 rect.right -= SYSMETRICS_CXSIZE + 1;
253 if (pt.x >= rect.right) return HTMAXBUTTON;
254 /* Check minimize box */
255 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
256 rect.right -= SYSMETRICS_CXSIZE + 1;
257 if (pt.x >= rect.right) return HTMINBUTTON;
258 return HTCAPTION;
262 /* Check client area */
264 ScreenToClient( hwnd, &pt );
265 GetClientRect( hwnd, &rect );
266 if (PtInRect( &rect, pt )) return HTCLIENT;
268 /* Check vertical scroll bar */
270 if (wndPtr->dwStyle & WS_VSCROLL)
272 rect.right += SYSMETRICS_CXVSCROLL;
273 if (PtInRect( &rect, pt )) return HTVSCROLL;
276 /* Check horizontal scroll bar */
278 if (wndPtr->dwStyle & WS_HSCROLL)
280 rect.bottom += SYSMETRICS_CYHSCROLL;
281 if (PtInRect( &rect, pt ))
283 /* Check size box */
284 if ((wndPtr->dwStyle & WS_VSCROLL) &&
285 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
286 return HTSIZE;
287 return HTHSCROLL;
291 /* Check menu bar */
293 if (HAS_MENU(wndPtr))
295 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
296 return HTMENU;
299 /* Should never get here */
300 return HTERROR;
304 /***********************************************************************
305 * NC_HandleNCHitTest
307 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
309 LONG NC_HandleNCHitTest( HWND hwnd, POINT pt )
311 #ifdef DEBUG_NONCLIENT
312 printf( "NC_HandleNCHitTest: hwnd=%x pt=%d,%d\n", hwnd, pt.x, pt.y );
313 #endif
314 if (hwnd == GetCapture()) return HTCLIENT;
315 return NC_InternalNCHitTest( hwnd, pt );
319 /***********************************************************************
320 * NC_DrawSysButton
322 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
324 RECT rect;
325 WND *wndPtr = WIN_FindWndPtr( hwnd );
326 HDC hdcMem = CreateCompatibleDC( hdc );
327 if (hdcMem)
329 NC_GetInsideRect( hwnd, &rect );
330 if (wndPtr->dwStyle & WS_CHILD)
331 SelectObject( hdcMem, hbitmapMDIClose );
332 else
333 SelectObject( hdcMem, hbitmapClose );
334 BitBlt( hdc, rect.left, rect.top, SYSMETRICS_CXSIZE,
335 SYSMETRICS_CYSIZE, hdcMem, 1, 1, down ? NOTSRCCOPY : SRCCOPY );
336 DeleteDC( hdcMem );
341 /***********************************************************************
342 * NC_DrawMaxButton
344 static void NC_DrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
346 RECT rect;
347 HDC hdcMem = CreateCompatibleDC( hdc );
348 if (hdcMem)
350 NC_GetInsideRect( hwnd, &rect );
351 if (IsZoomed(hwnd))
352 SelectObject( hdcMem, down ? hbitmapRestoreD : hbitmapRestore );
353 else SelectObject( hdcMem, down ? hbitmapMaximizeD : hbitmapMaximize );
354 BitBlt( hdc, rect.right - SYSMETRICS_CXSIZE - 1, rect.top - 1,
355 SYSMETRICS_CXSIZE+2, SYSMETRICS_CYSIZE+2, hdcMem, 0, 0, SRCCOPY);
356 DeleteDC( hdcMem );
361 /***********************************************************************
362 * NC_DrawMinButton
364 static void NC_DrawMinButton( HWND hwnd, HDC hdc, BOOL down )
366 RECT rect;
367 WND *wndPtr = WIN_FindWndPtr( hwnd );
368 HDC hdcMem = CreateCompatibleDC( hdc );
369 if (hdcMem)
371 NC_GetInsideRect( hwnd, &rect );
372 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
373 rect.right -= SYSMETRICS_CXSIZE + 1;
374 if (down) SelectObject( hdcMem, hbitmapMinimizeD );
375 else SelectObject( hdcMem, hbitmapMinimize );
376 BitBlt( hdc, rect.right - SYSMETRICS_CXSIZE - 1, rect.top - 1,
377 SYSMETRICS_CXSIZE+2, SYSMETRICS_CYSIZE+2, hdcMem, 0, 0, SRCCOPY);
378 DeleteDC( hdcMem );
383 /***********************************************************************
384 * NC_DrawFrame
386 * Draw a window frame inside the given rectangle, and update the rectangle.
387 * The correct pen and brush must be selected in the DC.
389 static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame )
391 short width, height, tmp;
393 if (dlgFrame)
395 width = SYSMETRICS_CXDLGFRAME - 1;
396 height = SYSMETRICS_CYDLGFRAME - 1;
398 else
400 width = SYSMETRICS_CXFRAME - 1;
401 height = SYSMETRICS_CYFRAME - 1;
404 /* Draw frame */
405 PatBlt( hdc, rect->left, rect->top,
406 rect->right - rect->left, height, PATCOPY );
407 PatBlt( hdc, rect->left, rect->top,
408 width, rect->bottom - rect->top, PATCOPY );
409 PatBlt( hdc, rect->left, rect->bottom,
410 rect->right - rect->left, -height, PATCOPY );
411 PatBlt( hdc, rect->right, rect->top,
412 -width, rect->bottom - rect->top, PATCOPY );
414 if (dlgFrame)
416 InflateRect( rect, -width, -height );
417 return;
420 /* Draw inner rectangle */
421 MoveTo( hdc, rect->left+width, rect->top+height );
422 LineTo( hdc, rect->right-width-1, rect->top+height );
423 LineTo( hdc, rect->right-width-1, rect->bottom-height-1 );
424 LineTo( hdc, rect->left+width, rect->bottom-height-1 );
425 LineTo( hdc, rect->left+width, rect->top+height );
427 /* Draw the decorations */
428 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
429 MoveTo( hdc, rect->left, tmp);
430 LineTo( hdc, rect->left+width, tmp );
431 MoveTo( hdc, rect->right-width-1, tmp );
432 LineTo( hdc, rect->right-1, tmp );
434 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
435 MoveTo( hdc, rect->left, tmp );
436 LineTo( hdc, rect->left+width, tmp );
437 MoveTo( hdc, rect->right-width-1, tmp );
438 LineTo( hdc, rect->right-1, tmp );
440 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
441 MoveTo( hdc, tmp, rect->top );
442 LineTo( hdc, tmp, rect->top+height );
443 MoveTo( hdc, tmp, rect->bottom-height-1 );
444 LineTo( hdc, tmp, rect->bottom-1 );
446 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
447 MoveTo( hdc, tmp, rect->top );
448 LineTo( hdc, tmp, rect->top+height );
449 MoveTo( hdc, tmp, rect->bottom-height-1 );
450 LineTo( hdc, tmp, rect->bottom-1 );
452 InflateRect( rect, -width-1, -height-1 );
456 /***********************************************************************
457 * NC_DrawMovingFrame
459 * Draw the frame used when moving or resizing window.
461 static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
463 if (thickframe)
465 SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
466 PatBlt( hdc, rect->left, rect->top,
467 rect->right - rect->left - SYSMETRICS_CXFRAME,
468 SYSMETRICS_CYFRAME, PATINVERT );
469 PatBlt( hdc, rect->left, rect->top + SYSMETRICS_CYFRAME,
470 SYSMETRICS_CXFRAME,
471 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
472 PatBlt( hdc, rect->left + SYSMETRICS_CXFRAME, rect->bottom,
473 rect->right - rect->left - SYSMETRICS_CXFRAME,
474 -SYSMETRICS_CYFRAME, PATINVERT );
475 PatBlt( hdc, rect->right, rect->top, -SYSMETRICS_CXFRAME,
476 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
478 else DrawFocusRect( hdc, rect );
482 /***********************************************************************
483 * NC_DrawCaption
485 * Draw the window caption.
486 * The correct pen for the window frame must be selected in the DC.
488 static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
489 DWORD style, BOOL active )
491 RECT r = *rect;
492 WND * wndPtr = WIN_FindWndPtr( hwnd );
493 char buffer[256];
495 if (!hbitmapClose)
497 if (!(hbitmapClose = LoadBitmap( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
498 return;
499 if (!(hbitmapMDIClose = LoadBitmap( 0, MAKEINTRESOURCE(OBM_OLD_CLOSE) )))
500 return;
501 hbitmapMinimize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCE) );
502 hbitmapMinimizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCED) );
503 hbitmapMaximize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOM) );
504 hbitmapMaximizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
505 hbitmapRestore = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORE) );
506 hbitmapRestoreD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORED) );
509 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
511 HBRUSH hbrushOld = SelectObject( hdc, sysColorObjects.hbrushWindow );
512 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
513 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
514 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
515 r.left++;
516 r.right--;
517 SelectObject( hdc, hbrushOld );
520 MoveTo( hdc, r.left, r.bottom );
521 LineTo( hdc, r.right-1, r.bottom );
523 if (style & WS_SYSMENU)
525 NC_DrawSysButton( hwnd, hdc, FALSE );
526 r.left += SYSMETRICS_CXSIZE + 1;
527 MoveTo( hdc, r.left - 1, r.top );
528 LineTo( hdc, r.left - 1, r.bottom );
530 if (style & WS_MAXIMIZEBOX)
532 NC_DrawMaxButton( hwnd, hdc, FALSE );
533 r.right -= SYSMETRICS_CXSIZE + 1;
535 if (style & WS_MINIMIZEBOX)
537 NC_DrawMinButton( hwnd, hdc, FALSE );
538 r.right -= SYSMETRICS_CXSIZE + 1;
541 FillRect( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
542 sysColorObjects.hbrushInactiveCaption );
544 if (GetWindowText( hwnd, buffer, 256 ))
546 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
547 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
548 SetBkMode( hdc, TRANSPARENT );
549 DrawText( hdc, buffer, -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
554 /***********************************************************************
555 * NC_DoNCPaint
557 * Paint the non-client area.
558 * 'hrgn' is the update rgn to use (in client coords) or 1 if no update rgn.
560 void NC_DoNCPaint( HWND hwnd, HRGN hrgn, BOOL active, BOOL suppress_menupaint )
562 HDC hdc;
563 RECT rect, rect2;
565 WND *wndPtr = WIN_FindWndPtr( hwnd );
567 #ifdef DEBUG_NONCLIENT
568 printf( "NC_DoNCPaint: %d %d\n", hwnd, hrgn );
569 #endif
570 if (!wndPtr || !hrgn) return;
571 if ((!(wndPtr->dwStyle & (WS_BORDER | WS_DLGFRAME | WS_THICKFRAME))) ||
572 (!(wndPtr->dwStyle & WS_VISIBLE)))
573 return; /* Nothing to do! */
575 if (hrgn == 1) hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
576 else
578 /* Make region relative to window area */
579 int xoffset = wndPtr->rectWindow.left - wndPtr->rectClient.left;
580 int yoffset = wndPtr->rectWindow.top - wndPtr->rectClient.top;
581 OffsetRgn( hrgn, -xoffset, -yoffset );
582 hdc = GetDCEx( hwnd, hrgn, DCX_CACHE | DCX_WINDOW | DCX_INTERSECTRGN);
583 OffsetRgn( hrgn, xoffset, yoffset ); /* Restore region */
585 if (!hdc) return;
586 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
587 wndPtr->rectClient.top-wndPtr->rectWindow.top,
588 wndPtr->rectClient.right-wndPtr->rectWindow.left,
589 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
590 == NULLREGION)
592 ReleaseDC( hwnd, hdc );
593 return;
596 rect.top = rect.left = 0;
597 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
598 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
600 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
601 SelectObject( hdc, active ? sysColorObjects.hbrushActiveBorder :
602 sysColorObjects.hbrushInactiveBorder );
604 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME))
606 MoveTo( hdc, 0, 0 );
607 LineTo( hdc, rect.right-1, 0 );
608 LineTo( hdc, rect.right-1, rect.bottom-1 );
609 LineTo( hdc, 0, rect.bottom-1 );
610 LineTo( hdc, 0, 0 );
611 InflateRect( &rect, -1, -1 );
614 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
615 NC_DrawFrame( hdc, &rect, TRUE );
616 else if (wndPtr->dwStyle & WS_THICKFRAME)
617 NC_DrawFrame(hdc, &rect, FALSE);
619 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
621 RECT r = rect;
622 r.bottom = rect.top + SYSMETRICS_CYSIZE;
623 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
624 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
627 if (HAS_MENU(wndPtr))
629 RECT r = rect;
630 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
631 rect.top += MENU_DrawMenuBar( hdc, &r, (HMENU)wndPtr->wIDmenu,
632 suppress_menupaint );
635 if (wndPtr->dwStyle & (WS_VSCROLL | WS_HSCROLL)) {
636 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->VScroll != NULL) &&
637 (wndPtr->scroll_flags & 0x0001)) {
638 int bottom = rect.bottom;
639 if ((wndPtr->dwStyle & WS_HSCROLL) && (wndPtr->scroll_flags & 0x0001))
640 bottom -= SYSMETRICS_CYHSCROLL;
641 SetRect(&rect2, rect.right - SYSMETRICS_CXVSCROLL,
642 rect.top, rect.right, bottom);
643 StdDrawScrollBar(hwnd, hdc, SB_VERT, &rect2, (LPHEADSCROLL)wndPtr->VScroll);
645 if ((wndPtr->dwStyle & WS_HSCROLL) && wndPtr->HScroll != NULL &&
646 (wndPtr->scroll_flags & 0x0002)) {
647 int right = rect.right;
648 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->scroll_flags & 0x0001))
649 right -= SYSMETRICS_CYVSCROLL;
650 SetRect(&rect2, rect.left, rect.bottom - SYSMETRICS_CYHSCROLL,
651 right, rect.bottom);
652 StdDrawScrollBar(hwnd, hdc, SB_HORZ, &rect2, (LPHEADSCROLL)wndPtr->HScroll);
655 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL) &&
656 (wndPtr->scroll_flags & 0x0003) == 0x0003) {
657 RECT r = rect;
658 r.left = r.right - SYSMETRICS_CXVSCROLL;
659 r.top = r.bottom - SYSMETRICS_CYHSCROLL;
660 FillRect( hdc, &r, sysColorObjects.hbrushScrollbar );
664 ReleaseDC( hwnd, hdc );
668 NC_DoNCPaintIcon(HWND hwnd)
670 WND *wndPtr = WIN_FindWndPtr(hwnd);
671 PAINTSTRUCT ps;
672 HDC hdc;
673 int ret;
674 DC *dc;
675 GC testgc;
676 int s;
677 char buffer[256];
679 printf("painting icon\n");
680 if (wndPtr == NULL) {
681 printf("argh, can't find an icon to draw\n");
682 return;
684 hdc = BeginPaint(hwnd, &ps);
686 ret = DrawIcon(hdc, 100/2 - 16, 0, wndPtr->hIcon);
687 printf("ret is %d\n", ret);
689 if (s=GetWindowText(hwnd, buffer, 256))
691 /*SetBkColor(hdc, TRANSPARENT); */
692 TextOut(hdc, 0, 32, buffer, s);
694 EndPaint(hwnd, &ps);
696 printf("done painting icon\n");
701 LONG NC_HandleNCPaintIcon( HWND hwnd )
703 NC_DoNCPaintIcon(hwnd);
704 return 0;
709 /***********************************************************************
710 * NC_HandleNCPaint
712 * Handle a WM_NCPAINT message. Called from DefWindowProc().
714 LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn )
716 NC_DoNCPaint( hwnd, hrgn, hwnd == GetActiveWindow(), FALSE );
717 return 0;
721 /***********************************************************************
722 * NC_HandleNCActivate
724 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
726 LONG NC_HandleNCActivate( HWND hwnd, WORD wParam )
728 NC_DoNCPaint( hwnd, (HRGN)1, wParam, FALSE );
729 return TRUE;
733 /***********************************************************************
734 * NC_HandleSetCursor
736 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
738 LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam )
740 if (hwnd != wParam) return 0; /* Don't set the cursor for child windows */
742 switch(LOWORD(lParam))
744 case HTERROR:
746 WORD msg = HIWORD( lParam );
747 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
748 (msg == WM_RBUTTONDOWN))
749 MessageBeep(0);
751 break;
753 case HTCLIENT:
755 WND *wndPtr;
756 CLASS *classPtr;
757 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
758 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) break;
759 if (classPtr->wc.hCursor)
761 CURSOR_SetWinCursor( hwnd, classPtr->wc.hCursor );
762 return TRUE;
765 break;
767 case HTLEFT:
768 case HTRIGHT:
769 CURSOR_SetWinCursor( hwnd, LoadCursor( 0, IDC_SIZEWE ) );
770 return TRUE;
772 case HTTOP:
773 case HTBOTTOM:
774 CURSOR_SetWinCursor( hwnd, LoadCursor( 0, IDC_SIZENS ) );
775 return TRUE;
777 case HTTOPLEFT:
778 case HTBOTTOMRIGHT:
779 CURSOR_SetWinCursor( hwnd, LoadCursor( 0, IDC_SIZENWSE ) );
780 return TRUE;
782 case HTTOPRIGHT:
783 case HTBOTTOMLEFT:
784 CURSOR_SetWinCursor( hwnd, LoadCursor( 0, IDC_SIZENESW ) );
785 return TRUE;
788 /* Default cursor: arrow */
789 CURSOR_SetWinCursor( hwnd, LoadCursor( 0, IDC_ARROW ) );
790 return TRUE;
794 /***********************************************************************
795 * NC_StartSizeMove
797 * Initialisation of a move or resize, when initiatied from a menu choice.
798 * Return hit test code for caption or sizing border.
800 static LONG NC_StartSizeMove( HWND hwnd, WORD wParam, POINT *capturePoint )
802 LONG hittest = 0;
803 POINT pt;
804 MSG msg;
805 WND * wndPtr = WIN_FindWndPtr( hwnd );
807 if ((wParam & 0xfff0) == SC_MOVE)
809 /* Move pointer at the center of the caption */
810 RECT rect;
811 NC_GetInsideRect( hwnd, &rect );
812 if (wndPtr->dwStyle & WS_SYSMENU)
813 rect.left += SYSMETRICS_CXSIZE + 1;
814 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
815 rect.right -= SYSMETRICS_CXSIZE + 1;
816 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
817 rect.right -= SYSMETRICS_CXSIZE + 1;
818 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
819 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
820 if (wndPtr->dwStyle & WS_CHILD)
821 ClientToScreen( wndPtr->hwndParent, &pt );
822 hittest = HTCAPTION;
824 else /* SC_SIZE */
826 SetCapture(hwnd);
827 while(!hittest)
829 MSG_GetHardwareMessage( &msg );
830 switch(msg.message)
832 case WM_MOUSEMOVE:
833 hittest = NC_InternalNCHitTest( hwnd, msg.pt );
834 pt = msg.pt;
835 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
836 hittest = 0;
837 break;
839 case WM_LBUTTONUP:
840 return 0;
842 case WM_KEYDOWN:
843 switch(msg.wParam)
845 case VK_UP:
846 hittest = HTTOP;
847 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
848 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
849 break;
850 case VK_DOWN:
851 hittest = HTBOTTOM;
852 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
853 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
854 break;
855 case VK_LEFT:
856 hittest = HTLEFT;
857 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
858 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
859 break;
860 case VK_RIGHT:
861 hittest = HTRIGHT;
862 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
863 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
864 break;
865 case VK_RETURN:
866 case VK_ESCAPE: return 0;
871 *capturePoint = pt;
872 SetCursorPos( capturePoint->x, capturePoint->y );
873 NC_HandleSetCursor( hwnd, hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
874 return hittest;
878 /***********************************************************************
879 * NC_DoSizeMove
881 * Perform SC_MOVE and SC_SIZE commands.
883 static void NC_DoSizeMove( HWND hwnd, WORD wParam, POINT pt )
885 MSG msg;
886 LONG hittest;
887 RECT sizingRect, mouseRect;
888 HDC hdc;
889 BOOL thickframe;
890 POINT minTrack, maxTrack, capturePoint = pt;
891 WND * wndPtr = WIN_FindWndPtr( hwnd );
893 if (IsZoomed(hwnd) || IsIconic(hwnd) || !IsWindowVisible(hwnd)) return;
894 hittest = wParam & 0x0f;
895 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
897 if ((wParam & 0xfff0) == SC_MOVE)
899 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
900 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
901 if (!hittest) return;
903 else /* SC_SIZE */
905 if (!thickframe) return;
906 if (hittest) hittest += HTLEFT-1;
907 else
909 SetCapture(hwnd);
910 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
911 if (!hittest)
913 ReleaseCapture();
914 return;
919 /* Get min/max info */
921 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
922 sizingRect = wndPtr->rectWindow;
923 if (wndPtr->dwStyle & WS_CHILD)
924 GetClientRect( wndPtr->hwndParent, &mouseRect );
925 else SetRect( &mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN );
926 if (ON_LEFT_BORDER(hittest))
928 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
929 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
931 else if (ON_RIGHT_BORDER(hittest))
933 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
934 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
936 if (ON_TOP_BORDER(hittest))
938 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
939 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
941 else if (ON_BOTTOM_BORDER(hittest))
943 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
944 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
946 SendMessage( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
948 if (GetCapture() != hwnd) SetCapture( hwnd );
950 if (wndPtr->dwStyle & WS_CHILD) hdc = GetDC( wndPtr->hwndParent );
951 else
952 { /* Grab the server only when moving top-level windows without desktop */
953 hdc = GetDC( 0 );
954 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
956 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
958 while(1)
960 int dx = 0, dy = 0;
962 MSG_GetHardwareMessage( &msg );
964 /* Exit on button-up, Return, or Esc */
965 if ((msg.message == WM_LBUTTONUP) ||
966 ((msg.message == WM_KEYDOWN) &&
967 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
969 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
970 continue; /* We are not interested in other messages */
972 pt = msg.pt;
973 if (wndPtr->dwStyle & WS_CHILD)
974 ScreenToClient( wndPtr->hwndParent, &pt );
977 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
979 case VK_UP: pt.y -= 8; break;
980 case VK_DOWN: pt.y += 8; break;
981 case VK_LEFT: pt.x -= 8; break;
982 case VK_RIGHT: pt.x += 8; break;
985 pt.x = max( pt.x, mouseRect.left );
986 pt.x = min( pt.x, mouseRect.right );
987 pt.y = max( pt.y, mouseRect.top );
988 pt.y = min( pt.y, mouseRect.bottom );
990 dx = pt.x - capturePoint.x;
991 dy = pt.y - capturePoint.y;
993 if (dx || dy)
995 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
996 else
998 RECT newRect = sizingRect;
1000 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1001 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1002 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1003 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1004 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1005 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1006 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1007 capturePoint = pt;
1008 sizingRect = newRect;
1013 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1014 ReleaseCapture();
1015 if (wndPtr->dwStyle & WS_CHILD) ReleaseDC( wndPtr->hwndParent, hdc );
1016 else
1018 ReleaseDC( 0, hdc );
1019 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1021 SendMessage( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1023 /* If Esc key, don't move the window */
1024 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1026 if (hittest != HTCAPTION)
1027 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1028 sizingRect.right - sizingRect.left,
1029 sizingRect.bottom - sizingRect.top,
1030 SWP_NOACTIVATE | SWP_NOZORDER );
1031 else SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1032 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1036 /***********************************************************************
1037 * NC_TrackMinMaxBox
1039 * Track a mouse button press on the minimize or maximize box.
1041 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
1043 MSG msg;
1044 HDC hdc = GetWindowDC( hwnd );
1045 BOOL pressed = TRUE;
1047 SetCapture( hwnd );
1048 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1049 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1053 BOOL oldstate = pressed;
1054 MSG_GetHardwareMessage( &msg );
1056 pressed = (NC_InternalNCHitTest( hwnd, msg.pt ) == wParam);
1057 if (pressed != oldstate)
1059 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1060 else NC_DrawMaxButton( hwnd, hdc, pressed );
1062 } while (msg.message != WM_LBUTTONUP);
1064 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1065 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1067 ReleaseCapture();
1068 ReleaseDC( hwnd, hdc );
1069 if (!pressed) return;
1071 if (wParam == HTMINBUTTON)
1072 SendMessage( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1073 else
1074 SendMessage( hwnd, WM_SYSCOMMAND,
1075 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, *(LONG*)&msg.pt );
1079 /***********************************************************************
1080 * NC_TrackScrollBar
1082 * Track a mouse button press on the horizontal or vertical scroll-bar.
1084 static void NC_TrackScrollBar( HWND hwnd, WORD wParam, POINT pt )
1086 MSG msg;
1087 WORD scrollbar;
1088 if ((wParam & 0xfff0) == SC_HSCROLL)
1090 if ((wParam & 0x0f) != HTHSCROLL) return;
1091 scrollbar = SB_HORZ;
1093 else /* SC_VSCROLL */
1095 if ((wParam & 0x0f) != HTVSCROLL) return;
1096 scrollbar = SB_VERT;
1099 ScreenToClient( hwnd, &pt );
1100 ScrollBarButtonDown( hwnd, scrollbar, pt.x, pt.y );
1101 SetCapture( hwnd );
1105 MSG_GetHardwareMessage( &msg );
1106 ScreenToClient( msg.hwnd, &msg.pt );
1107 switch(msg.message)
1109 case WM_LBUTTONUP:
1110 ScrollBarButtonUp( hwnd, scrollbar, msg.pt.x, msg.pt.y );
1111 break;
1112 case WM_MOUSEMOVE:
1113 ScrollBarMouseMove(hwnd, scrollbar, msg.wParam, msg.pt.x,msg.pt.y);
1114 break;
1116 } while (msg.message != WM_LBUTTONUP);
1117 ReleaseCapture();
1120 /***********************************************************************
1121 * NC_TrackSysMenu
1123 * Track a mouse button press on the system menu.
1125 static void NC_TrackSysMenu( HWND hwnd, HDC hdc, POINT pt )
1127 RECT rect;
1128 WND *wndPtr = WIN_FindWndPtr( hwnd );
1130 if (!(wndPtr->dwStyle & WS_SYSMENU)) return;
1131 /* If window has a menu, track the menu bar normally */
1132 if (HAS_MENU(wndPtr)) MENU_TrackMouseMenuBar( hwnd, pt );
1133 else
1135 /* Otherwise track the system menu like a normal popup menu */
1136 NC_GetInsideRect( hwnd, &rect );
1137 OffsetRect( &rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top );
1138 if (wndPtr->dwStyle & WS_CHILD)
1139 ClientToScreen( wndPtr->hwndParent, (POINT *)&rect );
1140 rect.right = rect.left + SYSMETRICS_CXSIZE;
1141 rect.bottom = rect.top + SYSMETRICS_CYSIZE;
1142 NC_DrawSysButton( hwnd, hdc, TRUE );
1143 TrackPopupMenu( wndPtr->hSysMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
1144 rect.left, rect.bottom, 0, hwnd, &rect );
1145 NC_DrawSysButton( hwnd, hdc, FALSE );
1150 /***********************************************************************
1151 * NC_HandleNCLButtonDown
1153 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1155 LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam )
1157 HDC hdc = GetWindowDC( hwnd );
1159 switch(wParam) /* Hit test */
1161 case HTCAPTION:
1162 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1163 break;
1165 case HTSYSMENU:
1166 NC_TrackSysMenu( hwnd, hdc, MAKEPOINT(lParam) );
1167 break;
1169 case HTMENU:
1170 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1171 break;
1173 case HTHSCROLL:
1174 SendMessage( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1175 break;
1177 case HTVSCROLL:
1178 SendMessage( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1179 break;
1181 case HTMINBUTTON:
1182 case HTMAXBUTTON:
1183 NC_TrackMinMaxBox( hwnd, wParam );
1184 break;
1186 case HTLEFT:
1187 case HTRIGHT:
1188 case HTTOP:
1189 case HTTOPLEFT:
1190 case HTTOPRIGHT:
1191 case HTBOTTOM:
1192 case HTBOTTOMLEFT:
1193 case HTBOTTOMRIGHT:
1194 SendMessage( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1195 break;
1197 case HTBORDER:
1198 break;
1201 ReleaseDC( hwnd, hdc );
1202 return 0;
1206 /***********************************************************************
1207 * NC_HandleNCLButtonDblClk
1209 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1211 LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam )
1213 switch(wParam) /* Hit test */
1215 case HTCAPTION:
1216 SendMessage( hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, lParam );
1217 break;
1219 case HTSYSMENU:
1220 SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, lParam );
1221 break;
1223 return 0;
1227 /***********************************************************************
1228 * NC_HandleSysCommand
1230 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1232 LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt )
1234 WND *wndPtr = WIN_FindWndPtr( hwnd );
1236 #ifdef DEBUG_NONCLIENT
1237 printf( "Handling WM_SYSCOMMAND %x %d,%d\n", wParam, pt.x, pt.y );
1238 #endif
1240 if (wndPtr->dwStyle & WS_CHILD) ScreenToClient( wndPtr->hwndParent, &pt );
1242 switch (wParam & 0xfff0)
1244 case SC_SIZE:
1245 case SC_MOVE:
1246 NC_DoSizeMove( hwnd, wParam, pt );
1247 break;
1249 case SC_MINIMIZE:
1250 ICON_Iconify( hwnd );
1251 /*ShowWindow( hwnd, SW_MINIMIZE );*/
1252 break;
1254 case SC_MAXIMIZE:
1255 ShowWindow( hwnd, SW_MAXIMIZE );
1256 break;
1258 case SC_RESTORE:
1259 ICON_Deiconify(hwnd);
1260 ShowWindow( hwnd, SW_RESTORE );
1261 break;
1263 case SC_NEXTWINDOW:
1264 case SC_PREVWINDOW:
1265 break;
1267 case SC_CLOSE:
1268 return SendMessage( hwnd, WM_CLOSE, 0, 0 );
1270 case SC_VSCROLL:
1271 case SC_HSCROLL:
1272 if (wndPtr->dwStyle & WS_CHILD) ClientToScreen(wndPtr->hwndParent, &pt);
1273 NC_TrackScrollBar( hwnd, wParam, pt );
1274 break;
1276 case SC_MOUSEMENU:
1277 MENU_TrackMouseMenuBar( hwnd, pt );
1278 break;
1280 case SC_KEYMENU:
1281 MENU_TrackKbdMenuBar( hwnd, wParam );
1282 break;
1284 case SC_ARRANGE:
1285 break;
1287 case SC_TASKLIST:
1288 /* WinExec( "taskman.exe", SW_SHOWNORMAL ); */
1289 break;
1291 case SC_HOTKEY:
1292 break;
1294 case SC_SCREENSAVE:
1295 if (wParam == SC_ABOUTWINE)
1296 DialogBox( hSysRes, MAKEINTRESOURCE(2),
1297 hwnd, (FARPROC)AboutWine_Proc );
1298 break;
1300 return 0;