2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
17 #include "sysmetrics.h"
18 #include "cursoricon.h"
23 #include "nonclient.h"
28 #include "shm_main_blk.h"
31 #include "clipboard.h"
34 /* #define DEBUG_WIN */
35 /* #define DEBUG_MENU */
39 static WND
*pWndDesktop
= NULL
;
41 static HWND hwndSysModal
= 0;
43 static WORD wDragWidth
= 4;
44 static WORD wDragHeight
= 3;
46 extern HCURSOR
CURSORICON_IconToCursor(HICON
);
47 extern HQUEUE
QUEUE_GetDoomedQueue();
49 /***********************************************************************
52 * Return a pointer to the WND structure corresponding to a HWND.
54 WND
* WIN_FindWndPtr( HWND hwnd
)
58 if (!hwnd
) return NULL
;
59 ptr
= (WND
*) USER_HEAP_LIN_ADDR( hwnd
);
60 if (ptr
->dwMagic
!= WND_MAGIC
) return NULL
;
61 if (ptr
->hwndSelf
!= hwnd
)
63 fprintf( stderr
, "Can't happen: hwnd %04x self pointer is %04x\n",
64 hwnd
, ptr
->hwndSelf
);
71 /***********************************************************************
74 * Dump the content of a window structure to stderr.
76 void WIN_DumpWindow( HWND hwnd
)
82 if (!(ptr
= WIN_FindWndPtr( hwnd
)))
84 fprintf( stderr
, "%04x is not a window handle\n", hwnd
);
88 if (!GetClassName32A( hwnd
, className
, sizeof(className
) ))
89 strcpy( className
, "#NULL#" );
91 fprintf( stderr
, "Window %04x (%p):\n", hwnd
, ptr
);
93 "next=%p child=%p parent=%p owner=%p class=%p '%s'\n"
94 "inst=%04x taskQ=%04x updRgn=%04x active=%04x hdce=%04x idmenu=%04x\n"
95 "style=%08lx exstyle=%08lx wndproc=%08x text='%s'\n"
96 "client=%d,%d-%d,%d window=%d,%d-%d,%d iconpos=%d,%d maxpos=%d,%d\n"
97 "sysmenu=%04x flags=%04x props=%04x vscroll=%04x hscroll=%04x\n",
98 ptr
->next
, ptr
->child
, ptr
->parent
, ptr
->owner
,
99 ptr
->class, className
, ptr
->hInstance
, ptr
->hmemTaskQ
,
100 ptr
->hrgnUpdate
, ptr
->hwndLastActive
, ptr
->hdce
, ptr
->wIDmenu
,
101 ptr
->dwStyle
, ptr
->dwExStyle
, ptr
->winproc
,
102 ptr
->text
? ptr
->text
: "",
103 ptr
->rectClient
.left
, ptr
->rectClient
.top
, ptr
->rectClient
.right
,
104 ptr
->rectClient
.bottom
, ptr
->rectWindow
.left
, ptr
->rectWindow
.top
,
105 ptr
->rectWindow
.right
, ptr
->rectWindow
.bottom
, ptr
->ptIconPos
.x
,
106 ptr
->ptIconPos
.y
, ptr
->ptMaxPos
.x
, ptr
->ptMaxPos
.y
, ptr
->hSysMenu
,
107 ptr
->flags
, ptr
->hProp
, ptr
->hVScroll
, ptr
->hHScroll
);
109 if (ptr
->class->cbWndExtra
)
111 fprintf( stderr
, "extra bytes:" );
112 for (i
= 0; i
< ptr
->class->cbWndExtra
; i
++)
113 fprintf( stderr
, " %02x", *((BYTE
*)ptr
->wExtra
+i
) );
114 fprintf( stderr
, "\n" );
116 fprintf( stderr
, "\n" );
120 /***********************************************************************
123 * Walk the windows tree and print each window on stderr.
125 void WIN_WalkWindows( HWND hwnd
, int indent
)
130 ptr
= hwnd
? WIN_FindWndPtr( hwnd
) : pWndDesktop
;
133 fprintf( stderr
, "*** Invalid window handle\n" );
137 if (!indent
) /* first time around */
138 fprintf( stderr
, "%-16.16s %-8.8s %-6.6s %-17.17s %-8.8s %s\n",
139 "hwnd", " wndPtr", "queue", "Class Name", " Style", " WndProc");
143 fprintf(stderr
, "%*s%04x%*s", indent
, "", ptr
->hwndSelf
, 13-indent
,"");
145 GlobalGetAtomName16(ptr
->class->atomName
,className
,sizeof(className
));
147 fprintf( stderr
, "%08lx %-6.4x %-17.17s %08x %08x\n",
148 (DWORD
)ptr
, ptr
->hmemTaskQ
, className
,
149 (unsigned) ptr
->dwStyle
, ptr
->winproc
);
151 if (ptr
->child
) WIN_WalkWindows( ptr
->child
->hwndSelf
, indent
+1 );
157 /***********************************************************************
160 * Return the X window associated to a window.
162 Window
WIN_GetXWindow( HWND hwnd
)
164 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
165 while (wndPtr
&& !wndPtr
->window
) wndPtr
= wndPtr
->parent
;
166 return wndPtr
? wndPtr
->window
: 0;
170 /***********************************************************************
173 * Remove a window from the siblings linked list.
175 BOOL
WIN_UnlinkWindow( HWND hwnd
)
177 WND
*wndPtr
, **ppWnd
;
179 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)) || !wndPtr
->parent
) return FALSE
;
180 ppWnd
= &wndPtr
->parent
->child
;
181 while (*ppWnd
!= wndPtr
) ppWnd
= &(*ppWnd
)->next
;
182 *ppWnd
= wndPtr
->next
;
187 /***********************************************************************
190 * Insert a window into the siblings linked list.
191 * The window is inserted after the specified window, which can also
192 * be specified as HWND_TOP or HWND_BOTTOM.
194 BOOL
WIN_LinkWindow( HWND hwnd
, HWND hwndInsertAfter
)
196 WND
*wndPtr
, **ppWnd
;
198 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)) || !wndPtr
->parent
) return FALSE
;
200 if ((hwndInsertAfter
== HWND_TOP
) || (hwndInsertAfter
== HWND_BOTTOM
))
202 ppWnd
= &wndPtr
->parent
->child
; /* Point to first sibling hwnd */
203 if (hwndInsertAfter
== HWND_BOTTOM
) /* Find last sibling hwnd */
204 while (*ppWnd
) ppWnd
= &(*ppWnd
)->next
;
206 else /* Normal case */
208 WND
* afterPtr
= WIN_FindWndPtr( hwndInsertAfter
);
209 if (!afterPtr
) return FALSE
;
210 ppWnd
= &afterPtr
->next
;
212 wndPtr
->next
= *ppWnd
;
218 /***********************************************************************
219 * WIN_FindWinToRepaint
221 * Find a window that needs repaint.
223 HWND
WIN_FindWinToRepaint( HWND hwnd
, HQUEUE hQueue
)
226 WND
*pWnd
= pWndDesktop
;
228 /* Note: the desktop window never gets WM_PAINT messages */
229 pWnd
= hwnd
? WIN_FindWndPtr( hwnd
) : pWndDesktop
->child
;
231 for ( ; pWnd
; pWnd
= pWnd
->next
)
233 if (!(pWnd
->dwStyle
& WS_VISIBLE
) || (pWnd
->flags
& WIN_NO_REDRAW
))
235 dprintf_win( stddeb
, "FindWinToRepaint: skipping window %04x\n",
239 if ((pWnd
->hmemTaskQ
== hQueue
) &&
240 (pWnd
->hrgnUpdate
|| (pWnd
->flags
& WIN_INTERNAL_PAINT
))) break;
243 if ((hwndRet
= WIN_FindWinToRepaint( pWnd
->child
->hwndSelf
, hQueue
)) )
249 hwndRet
= pWnd
->hwndSelf
;
251 /* look among siblings if we got a transparent window */
252 while (pWnd
&& ((pWnd
->dwExStyle
& WS_EX_TRANSPARENT
) ||
253 !(pWnd
->hrgnUpdate
|| (pWnd
->flags
& WIN_INTERNAL_PAINT
))))
257 if (pWnd
) hwndRet
= pWnd
->hwndSelf
;
258 dprintf_win(stddeb
,"FindWinToRepaint: found %04x\n",hwndRet
);
263 /***********************************************************************
264 * WIN_SendParentNotify
266 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
267 * the window has the WS_EX_NOPARENTNOTIFY style.
269 void WIN_SendParentNotify( HWND hwnd
, WORD event
, WORD idChild
, LONG lValue
)
271 LPPOINT16 lppt
= (LPPOINT16
)&lValue
;
272 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
273 BOOL bMouse
= ((event
<= WM_MOUSELAST
) && (event
>= WM_MOUSEFIRST
));
275 /* if lValue contains cursor coordinates they have to be
276 * mapped to the client area of parent window */
278 if (bMouse
) MapWindowPoints16(0, hwnd
, lppt
, 1);
280 else lValue
= MAKELONG( LOWORD(lValue
), idChild
);
285 if ((wndPtr
->dwExStyle
& WS_EX_NOPARENTNOTIFY
) ||
286 !(wndPtr
->dwStyle
& WS_CHILD
)) break;
290 lppt
->x
+= wndPtr
->rectClient
.left
;
291 lppt
->y
+= wndPtr
->rectClient
.top
;
294 wndPtr
= wndPtr
->parent
;
296 SendMessage32A( wndPtr
->hwndSelf
, WM_PARENTNOTIFY
,
297 MAKEWPARAM( event
, idChild
), lValue
);
299 SendMessage16( wndPtr
->hwndSelf
, WM_PARENTNOTIFY
, event
, (LPARAM
)lValue
);
305 /***********************************************************************
308 * Set the window procedure and return the old one.
310 static HANDLE32
WIN_SetWndProc( WND
*pWnd
, HANDLE32 proc
, WINDOWPROCTYPE type
)
312 HANDLE32 oldProc
= pWnd
->winproc
;
313 pWnd
->winproc
= WINPROC_AllocWinProc( proc
, type
);
314 if (oldProc
) WINPROC_FreeWinProc( oldProc
);
319 /***********************************************************************
322 * Destroy storage associated to a window
324 static void WIN_DestroyWindow( HWND hwnd
)
326 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
330 DDE_DestroyWindow(hwnd
);
331 #endif /* CONFIG_IPC */
334 WIN_UnlinkWindow( hwnd
); /* Remove the window from the linked list */
335 TIMER_RemoveWindowTimers( hwnd
);
336 wndPtr
->dwMagic
= 0; /* Mark it as invalid */
337 wndPtr
->hwndSelf
= 0;
338 if ((wndPtr
->hrgnUpdate
) || (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
340 if (wndPtr
->hrgnUpdate
) DeleteObject( wndPtr
->hrgnUpdate
);
341 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
343 if (!(wndPtr
->dwStyle
& WS_CHILD
))
345 if (wndPtr
->wIDmenu
) DestroyMenu( (HMENU
)wndPtr
->wIDmenu
);
347 if (wndPtr
->hSysMenu
) DestroyMenu( wndPtr
->hSysMenu
);
348 if (wndPtr
->window
) XDestroyWindow( display
, wndPtr
->window
);
349 if (wndPtr
->class->style
& CS_OWNDC
) DCE_FreeDCE( wndPtr
->hdce
);
350 WIN_SetWndProc( wndPtr
, (WNDPROC16
)0, WIN_PROC_16
);
351 wndPtr
->class->cWindows
--;
352 USER_HEAP_FREE( hwnd
);
356 /***********************************************************************
357 * WIN_DestroyQueueWindows
359 void WIN_DestroyQueueWindows( WND
* wnd
, HQUEUE hQueue
)
366 if (wnd
->hmemTaskQ
== hQueue
) DestroyWindow( wnd
->hwndSelf
);
367 else WIN_DestroyQueueWindows( wnd
->child
, hQueue
);
373 /***********************************************************************
374 * WIN_CreateDesktopWindow
376 * Create the desktop window.
378 BOOL
WIN_CreateDesktopWindow(void)
384 dprintf_win(stddeb
,"Creating desktop window\n");
386 if (!(class = CLASS_FindClassByAtom( DESKTOP_CLASS_ATOM
, 0 )))
389 hwndDesktop
= USER_HEAP_ALLOC( sizeof(WND
)+class->cbWndExtra
);
390 if (!hwndDesktop
) return FALSE
;
391 pWndDesktop
= (WND
*) USER_HEAP_LIN_ADDR( hwndDesktop
);
393 pWndDesktop
->next
= NULL
;
394 pWndDesktop
->child
= NULL
;
395 pWndDesktop
->parent
= NULL
;
396 pWndDesktop
->owner
= NULL
;
397 pWndDesktop
->class = class;
398 pWndDesktop
->winproc
= WINPROC_CopyWinProc( class->winproc
);
399 pWndDesktop
->dwMagic
= WND_MAGIC
;
400 pWndDesktop
->hwndSelf
= hwndDesktop
;
401 pWndDesktop
->hInstance
= 0;
402 pWndDesktop
->rectWindow
.left
= 0;
403 pWndDesktop
->rectWindow
.top
= 0;
404 pWndDesktop
->rectWindow
.right
= SYSMETRICS_CXSCREEN
;
405 pWndDesktop
->rectWindow
.bottom
= SYSMETRICS_CYSCREEN
;
406 pWndDesktop
->rectClient
= pWndDesktop
->rectWindow
;
407 pWndDesktop
->rectNormal
= pWndDesktop
->rectWindow
;
408 pWndDesktop
->ptIconPos
.x
= -1;
409 pWndDesktop
->ptIconPos
.y
= -1;
410 pWndDesktop
->ptMaxPos
.x
= -1;
411 pWndDesktop
->ptMaxPos
.y
= -1;
412 pWndDesktop
->text
= NULL
;
413 pWndDesktop
->hmemTaskQ
= 0; /* Desktop does not belong to a task */
414 pWndDesktop
->hrgnUpdate
= 0;
415 pWndDesktop
->hwndLastActive
= hwndDesktop
;
416 pWndDesktop
->dwStyle
= WS_VISIBLE
| WS_CLIPCHILDREN
|
418 pWndDesktop
->dwExStyle
= 0;
419 pWndDesktop
->hdce
= 0;
420 pWndDesktop
->hVScroll
= 0;
421 pWndDesktop
->hHScroll
= 0;
422 pWndDesktop
->wIDmenu
= 0;
423 pWndDesktop
->flags
= 0;
424 pWndDesktop
->window
= rootWindow
;
425 pWndDesktop
->hSysMenu
= 0;
426 pWndDesktop
->hProp
= 0;
427 pWndDesktop
->userdata
= 0;
429 EVENT_RegisterWindow( pWndDesktop
->window
, hwndDesktop
);
430 SendMessage32A( hwndDesktop
, WM_NCCREATE
, 0, 0 );
431 if ((hdc
= GetDC( hwndDesktop
)) != 0)
433 SendMessage32A( hwndDesktop
, WM_ERASEBKGND
, hdc
, 0 );
434 ReleaseDC( hwndDesktop
, hdc
);
440 /***********************************************************************
443 * Implementation of CreateWindowEx().
445 static HWND
WIN_CreateWindowEx( CREATESTRUCT32A
*cs
, ATOM classAtom
,
451 POINT16 maxSize
, maxPos
, minTrack
, maxTrack
;
454 dprintf_win( stddeb
, "CreateWindowEx: " );
455 if (HIWORD(cs
->lpszName
)) dprintf_win( stddeb
, "'%s' ", cs
->lpszName
);
456 else dprintf_win( stddeb
, "#%04x ", LOWORD(cs
->lpszName
) );
457 if (HIWORD(cs
->lpszClass
)) dprintf_win( stddeb
, "'%s' ", cs
->lpszClass
);
458 else dprintf_win( stddeb
, "#%04x ", LOWORD(cs
->lpszClass
) );
460 dprintf_win( stddeb
, "%08lx %08lx %d,%d %dx%d %04x %04x %04x %p\n",
461 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
462 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
464 /* Find the parent window */
468 /* Make sure parent is valid */
469 if (!IsWindow( cs
->hwndParent
))
471 fprintf( stderr
, "CreateWindowEx: bad parent %04x\n", cs
->hwndParent
);
475 else if (cs
->style
& WS_CHILD
)
477 fprintf( stderr
, "CreateWindowEx: no parent for child window\n" );
478 return 0; /* WS_CHILD needs a parent */
481 /* Find the window class */
483 if (!(classPtr
= CLASS_FindClassByAtom( classAtom
,
484 GetExePtr(cs
->hInstance
) )))
487 GlobalGetAtomName32A( classAtom
, buffer
, sizeof(buffer
) );
488 fprintf( stderr
, "CreateWindowEx: bad class '%s'\n", buffer
);
492 /* Fix the coordinates */
494 if (cs
->x
== CW_USEDEFAULT32
) cs
->x
= cs
->y
= 0;
495 if (cs
->cx
== CW_USEDEFAULT32
)
497 /* if (!(cs->style & (WS_CHILD | WS_POPUP))) cs->cx = cs->cy = 0;
505 /* Create the window structure */
507 if (!(hwnd
= USER_HEAP_ALLOC( sizeof(*wndPtr
) + classPtr
->cbWndExtra
508 - sizeof(wndPtr
->wExtra
) )))
510 dprintf_win( stddeb
, "CreateWindowEx: out of memory\n" );
514 /* Fill the window structure */
516 wndPtr
= (WND
*) USER_HEAP_LIN_ADDR( hwnd
);
518 wndPtr
->child
= NULL
;
519 wndPtr
->parent
= (cs
->style
& WS_CHILD
) ?
520 WIN_FindWndPtr( cs
->hwndParent
) : pWndDesktop
;
521 wndPtr
->owner
= (cs
->style
& WS_CHILD
) ? NULL
:
522 WIN_FindWndPtr(WIN_GetTopParent(cs
->hwndParent
));
524 wndPtr
->class = classPtr
;
525 wndPtr
->winproc
= WINPROC_CopyWinProc( classPtr
->winproc
);
526 wndPtr
->dwMagic
= WND_MAGIC
;
527 wndPtr
->hwndSelf
= hwnd
;
528 wndPtr
->hInstance
= cs
->hInstance
;
529 wndPtr
->ptIconPos
.x
= -1;
530 wndPtr
->ptIconPos
.y
= -1;
531 wndPtr
->ptMaxPos
.x
= -1;
532 wndPtr
->ptMaxPos
.y
= -1;
534 wndPtr
->hmemTaskQ
= GetTaskQueue(0);
535 wndPtr
->hrgnUpdate
= 0;
536 wndPtr
->hwndLastActive
= hwnd
;
537 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
538 wndPtr
->dwExStyle
= cs
->dwExStyle
;
541 wndPtr
->hVScroll
= 0;
542 wndPtr
->hHScroll
= 0;
543 wndPtr
->hSysMenu
= MENU_GetDefSysMenu();
545 wndPtr
->userdata
= 0;
547 if (classPtr
->cbWndExtra
) memset( wndPtr
->wExtra
, 0, classPtr
->cbWndExtra
);
548 classPtr
->cWindows
++;
550 /* Correct the window style */
552 if (!(cs
->style
& (WS_POPUP
| WS_CHILD
))) /* Overlapped window */
554 wndPtr
->dwStyle
|= WS_CAPTION
| WS_CLIPSIBLINGS
;
555 wndPtr
->flags
|= WIN_NEED_SIZE
;
557 if (cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) wndPtr
->dwStyle
&= ~WS_THICKFRAME
;
559 /* Get class or window DC if needed */
561 if (classPtr
->style
& CS_OWNDC
) wndPtr
->hdce
= DCE_AllocDCE(hwnd
, DCE_WINDOW_DC
);
562 else if (classPtr
->style
& CS_CLASSDC
) wndPtr
->hdce
= classPtr
->hdce
;
563 else wndPtr
->hdce
= 0;
565 /* Insert the window in the linked list */
567 WIN_LinkWindow( hwnd
, HWND_TOP
);
569 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
571 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
573 NC_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
574 if (maxSize
.x
< cs
->cx
) cs
->cx
= maxSize
.x
;
575 if (maxSize
.y
< cs
->cy
) cs
->cy
= maxSize
.y
;
577 if (cs
->cx
<= 0) cs
->cx
= 1;
578 if (cs
->cy
<= 0) cs
->cy
= 1;
580 wndPtr
->rectWindow
.left
= cs
->x
;
581 wndPtr
->rectWindow
.top
= cs
->y
;
582 wndPtr
->rectWindow
.right
= cs
->x
+ cs
->cx
;
583 wndPtr
->rectWindow
.bottom
= cs
->y
+ cs
->cy
;
584 wndPtr
->rectClient
= wndPtr
->rectWindow
;
585 wndPtr
->rectNormal
= wndPtr
->rectWindow
;
587 /* Create the X window (only for top-level windows, and then only */
588 /* when there's no desktop window) */
590 if (!(cs
->style
& WS_CHILD
) && (rootWindow
== DefaultRootWindow(display
)))
592 XSetWindowAttributes win_attr
;
593 Atom XA_WM_DELETE_WINDOW
;
595 if (Options
.managed
&& ((cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)) ||
596 (cs
->dwExStyle
& WS_EX_DLGMODALFRAME
)))
598 win_attr
.event_mask
= ExposureMask
| KeyPressMask
|
599 KeyReleaseMask
| PointerMotionMask
|
600 ButtonPressMask
| ButtonReleaseMask
|
601 FocusChangeMask
| StructureNotifyMask
;
602 win_attr
.override_redirect
= FALSE
;
603 wndPtr
->flags
|= WIN_MANAGED
;
607 win_attr
.event_mask
= ExposureMask
| KeyPressMask
|
608 KeyReleaseMask
| PointerMotionMask
|
609 ButtonPressMask
| ButtonReleaseMask
|
611 win_attr
.override_redirect
= TRUE
;
613 win_attr
.colormap
= COLOR_WinColormap
;
614 win_attr
.backing_store
= Options
.backingstore
? WhenMapped
: NotUseful
;
615 win_attr
.save_under
= ((classPtr
->style
& CS_SAVEBITS
) != 0);
616 win_attr
.cursor
= CURSORICON_XCursor
;
617 wndPtr
->window
= XCreateWindow( display
, rootWindow
, cs
->x
, cs
->y
,
618 cs
->cx
, cs
->cy
, 0, CopyFromParent
,
619 InputOutput
, CopyFromParent
,
620 CWEventMask
| CWOverrideRedirect
|
621 CWColormap
| CWCursor
| CWSaveUnder
|
622 CWBackingStore
, &win_attr
);
623 XA_WM_DELETE_WINDOW
= XInternAtom( display
, "WM_DELETE_WINDOW",
625 XSetWMProtocols( display
, wndPtr
->window
, &XA_WM_DELETE_WINDOW
, 1 );
626 if (cs
->hwndParent
) /* Get window owner */
628 Window win
= WIN_GetXWindow( cs
->hwndParent
);
629 if (win
) XSetTransientForHint( display
, wndPtr
->window
, win
);
631 EVENT_RegisterWindow( wndPtr
->window
, hwnd
);
634 /* Set the window menu */
636 if ((cs
->style
& WS_CAPTION
) && !(cs
->style
& WS_CHILD
))
638 if (cs
->hMenu
) SetMenu(hwnd
, cs
->hMenu
);
641 #if 0 /* FIXME: should check if classPtr->menuNameW can be used as is */
642 if (classPtr
->menuNameA
)
643 cs
->hMenu
= HIWORD(classPtr
->menuNameA
) ?
644 LoadMenu(cs
->hInstance
,SEGPTR_GET(classPtr
->menuNameA
)):
645 LoadMenu(cs
->hInstance
,(SEGPTR
)classPtr
->menuNameA
);
647 SEGPTR menuName
= (SEGPTR
)GetClassLong16( hwnd
, GCL_MENUNAME
);
648 if (menuName
) cs
->hMenu
= LoadMenu( cs
->hInstance
, menuName
);
651 if (cs
->hMenu
) SetMenu( hwnd
, cs
->hMenu
);
653 else wndPtr
->wIDmenu
= (UINT
)cs
->hMenu
;
655 /* Send the WM_CREATE message */
659 if (!SendMessage32W( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
)) wmcreate
= -1;
662 WINPOS_SendNCCalcSize( hwnd
, FALSE
, &wndPtr
->rectWindow
,
663 NULL
, NULL
, 0, &wndPtr
->rectClient
);
664 wmcreate
= SendMessage32W( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
669 if (!SendMessage32A( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
)) wmcreate
= -1;
672 WINPOS_SendNCCalcSize( hwnd
, FALSE
, &wndPtr
->rectWindow
,
673 NULL
, NULL
, 0, &wndPtr
->rectClient
);
674 wmcreate
= SendMessage32A( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
680 /* Abort window creation */
681 dprintf_win(stddeb
,"CreateWindowEx: wmcreate==-1, aborting\n");
682 WIN_DestroyWindow( hwnd
);
686 /* Send the size messages */
688 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
691 SendMessage16( hwnd
, WM_SIZE
, SIZE_RESTORED
,
692 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
693 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
694 SendMessage16( hwnd
, WM_MOVE
, 0, MAKELONG( wndPtr
->rectClient
.left
,
695 wndPtr
->rectClient
.top
));
698 WIN_SendParentNotify( hwnd
, WM_CREATE
, wndPtr
->wIDmenu
, (LONG
)hwnd
);
699 if (!IsWindow(hwnd
)) return 0;
701 /* Show the window, maximizing or minimizing if needed */
703 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
705 wndPtr
->dwStyle
&= ~WS_MAXIMIZE
;
706 WINPOS_FindIconPos( hwnd
);
707 SetWindowPos( hwnd
, 0, wndPtr
->ptIconPos
.x
, wndPtr
->ptIconPos
.y
,
708 SYSMETRICS_CXICON
, SYSMETRICS_CYICON
, SWP_FRAMECHANGED
|
709 (cs
->style
& WS_VISIBLE
) ? SWP_SHOWWINDOW
: 0 );
711 else if (wndPtr
->dwStyle
& WS_MAXIMIZE
)
713 POINT16 maxSize
, maxPos
, minTrack
, maxTrack
;
714 NC_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
715 SetWindowPos( hwnd
, 0, maxPos
.x
, maxPos
.y
, maxSize
.x
, maxSize
.y
,
716 SWP_FRAMECHANGED
| (cs
->style
& WS_VISIBLE
) ? SWP_SHOWWINDOW
: 0 );
718 else if (cs
->style
& WS_VISIBLE
) ShowWindow( hwnd
, SW_SHOW
);
720 /* Call WH_SHELL hook */
722 if (!(wndPtr
->dwStyle
& WS_CHILD
) && !wndPtr
->owner
)
723 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, hwnd
, 0 );
725 dprintf_win(stddeb
, "CreateWindowEx: returning %04x\n", hwnd
);
730 /***********************************************************************
731 * CreateWindow16 (USER.41)
733 HWND16
CreateWindow16( LPCSTR className
, LPCSTR windowName
,
734 DWORD style
, INT16 x
, INT16 y
, INT16 width
,
735 INT16 height
, HWND16 parent
, HMENU16 menu
,
736 HINSTANCE16 instance
, LPVOID data
)
738 return CreateWindowEx16( 0, className
, windowName
, style
,
739 x
, y
, width
, height
, parent
, menu
, instance
, data
);
743 /***********************************************************************
744 * CreateWindowEx16 (USER.452)
746 HWND16
CreateWindowEx16( DWORD exStyle
, LPCSTR className
, LPCSTR windowName
,
747 DWORD style
, INT16 x
, INT16 y
, INT16 width
,
748 INT16 height
, HWND16 parent
, HMENU16 menu
,
749 HINSTANCE16 instance
, LPVOID data
)
754 /* Find the class atom */
756 if (!(classAtom
= GlobalFindAtom32A( className
)))
758 fprintf( stderr
, "CreateWindowEx16: bad class name " );
759 if (!HIWORD(className
)) fprintf( stderr
, "%04x\n", LOWORD(className
) );
760 else fprintf( stderr
, "'%s'\n", className
);
764 /* Fix the coordinates */
766 cs
.x
= (x
== CW_USEDEFAULT16
) ? CW_USEDEFAULT32
: (INT32
)x
;
767 cs
.y
= (y
== CW_USEDEFAULT16
) ? CW_USEDEFAULT32
: (INT32
)y
;
768 cs
.cx
= (width
== CW_USEDEFAULT16
) ? CW_USEDEFAULT32
: (INT32
)width
;
769 cs
.cy
= (height
== CW_USEDEFAULT16
) ? CW_USEDEFAULT32
: (INT32
)height
;
771 /* Create the window */
773 cs
.lpCreateParams
= data
;
774 cs
.hInstance
= (HINSTANCE32
)instance
;
775 cs
.hMenu
= (HMENU32
)menu
;
776 cs
.hwndParent
= (HWND32
)parent
;
778 cs
.lpszName
= windowName
;
779 cs
.lpszClass
= className
;
780 cs
.dwExStyle
= exStyle
;
781 return WIN_CreateWindowEx( &cs
, classAtom
, FALSE
);
785 /***********************************************************************
786 * CreateWindowEx32A (USER32.82)
788 HWND32
CreateWindowEx32A( DWORD exStyle
, LPCSTR className
, LPCSTR windowName
,
789 DWORD style
, INT32 x
, INT32 y
, INT32 width
,
790 INT32 height
, HWND32 parent
, HMENU32 menu
,
791 HINSTANCE32 instance
, LPVOID data
)
796 /* Find the class atom */
798 if (!(classAtom
= GlobalFindAtom32A( className
)))
800 fprintf( stderr
, "CreateWindowEx32A: bad class name " );
801 if (!HIWORD(className
)) fprintf( stderr
, "%04x\n", LOWORD(className
) );
802 else fprintf( stderr
, "'%s'\n", className
);
806 /* Create the window */
808 cs
.lpCreateParams
= data
;
809 cs
.hInstance
= instance
;
811 cs
.hwndParent
= parent
;
817 cs
.lpszName
= windowName
;
818 cs
.lpszClass
= className
;
819 cs
.dwExStyle
= exStyle
;
820 return WIN_CreateWindowEx( &cs
, classAtom
, FALSE
);
824 /***********************************************************************
825 * CreateWindowEx32W (USER32.83)
827 HWND32
CreateWindowEx32W( DWORD exStyle
, LPCWSTR className
, LPCWSTR windowName
,
828 DWORD style
, INT32 x
, INT32 y
, INT32 width
,
829 INT32 height
, HWND32 parent
, HMENU32 menu
,
830 HINSTANCE32 instance
, LPVOID data
)
835 /* Find the class atom */
837 if (!(classAtom
= GlobalFindAtom32W( className
)))
839 fprintf( stderr
, "CreateWindowEx32W: bad class name %p\n", className
);
843 /* Create the window */
845 cs
.lpCreateParams
= data
;
846 cs
.hInstance
= instance
;
848 cs
.hwndParent
= parent
;
854 cs
.lpszName
= windowName
;
855 cs
.lpszClass
= className
;
856 cs
.dwExStyle
= exStyle
;
857 /* Note: we rely on the fact that CREATESTRUCT32A and */
858 /* CREATESTRUCT32W have the same layout. */
859 return WIN_CreateWindowEx( (CREATESTRUCT32A
*)&cs
, classAtom
, TRUE
);
863 /***********************************************************************
864 * DestroyWindow (USER.53)
866 BOOL
DestroyWindow( HWND hwnd
)
870 dprintf_win(stddeb
, "DestroyWindow(%04x)\n", hwnd
);
874 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
875 if (wndPtr
== pWndDesktop
) return FALSE
; /* Can't destroy desktop */
877 /* Top-level window */
879 if (!(wndPtr
->dwStyle
& WS_CHILD
) && !wndPtr
->owner
)
881 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, hwnd
, 0L );
882 /* FIXME: clean up palette - see "Internals" p.352 */
885 /* Hide the window */
887 if (wndPtr
->dwStyle
& WS_VISIBLE
)
888 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
| SWP_NOACTIVATE
|
889 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
890 if ((hwnd
== GetCapture()) || IsChild( hwnd
, GetCapture() ))
892 if (!QUEUE_GetDoomedQueue())
893 WIN_SendParentNotify( hwnd
, WM_DESTROY
, wndPtr
->wIDmenu
, (LONG
)hwnd
);
895 /* Recursively destroy owned windows */
899 WND
*siblingPtr
= wndPtr
->parent
->child
; /* First sibling */
902 if (siblingPtr
->owner
== wndPtr
) break;
903 siblingPtr
= siblingPtr
->next
;
905 if (siblingPtr
) DestroyWindow( siblingPtr
->hwndSelf
);
909 CLIPBOARD_DisOwn( hwnd
);
911 /* Send destroy messages and destroy children */
913 SendMessage16( hwnd
, WM_DESTROY
, 0, 0 );
914 while (wndPtr
->child
) /* The child removes itself from the list */
915 DestroyWindow( wndPtr
->child
->hwndSelf
);
916 SendMessage16( hwnd
, WM_NCDESTROY
, 0, 0 );
918 /* Destroy the window */
920 WIN_DestroyWindow( hwnd
);
925 /***********************************************************************
926 * CloseWindow (USER.43)
928 BOOL
CloseWindow(HWND hWnd
)
930 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
931 if (wndPtr
->dwStyle
& WS_CHILD
) return TRUE
;
932 ShowWindow(hWnd
, SW_MINIMIZE
);
937 /***********************************************************************
940 BOOL
OpenIcon(HWND hWnd
)
942 if (!IsIconic(hWnd
)) return FALSE
;
943 ShowWindow(hWnd
, SW_SHOWNORMAL
);
948 /***********************************************************************
951 * Implementation of FindWindow() and FindWindowEx().
953 static HWND
WIN_FindWindow( HWND parent
, HWND child
, ATOM className
,
957 CLASS
*pClass
= NULL
;
961 if (!(pWnd
= WIN_FindWndPtr( child
))) return 0;
964 if (!pWnd
->parent
|| (pWnd
->parent
->hwndSelf
!= parent
)) return 0;
966 else if (pWnd
->parent
!= pWndDesktop
) return 0;
971 if (!(pWnd
= parent
? WIN_FindWndPtr(parent
) : pWndDesktop
)) return 0;
976 /* For a child window, all siblings will have the same hInstance, */
977 /* so we can look for the class once and for all. */
979 if (className
&& (pWnd
->dwStyle
& WS_CHILD
))
981 if (!(pClass
= CLASS_FindClassByAtom( className
, pWnd
->hInstance
)))
985 for ( ; pWnd
; pWnd
= pWnd
->next
)
987 if (className
&& !(pWnd
->dwStyle
& WS_CHILD
))
989 if (!(pClass
= CLASS_FindClassByAtom( className
, pWnd
->hInstance
)))
990 continue; /* Skip this window */
992 if (pClass
&& (pWnd
->class != pClass
))
993 continue; /* Not the right class */
995 /* Now check the title */
997 if (!title
) return pWnd
->hwndSelf
;
998 if (pWnd
->text
&& !strcmp( pWnd
->text
, title
)) return pWnd
->hwndSelf
;
1005 /***********************************************************************
1006 * FindWindow16 (USER.50)
1008 HWND
FindWindow16( SEGPTR className
, LPCSTR title
)
1010 return FindWindowEx16( 0, 0, className
, title
);
1014 /***********************************************************************
1015 * FindWindowEx16 (USER.427)
1017 HWND
FindWindowEx16( HWND parent
, HWND child
, SEGPTR className
, LPCSTR title
)
1021 atom
= className
? GlobalFindAtom16( className
) : 0;
1022 return WIN_FindWindow( parent
, child
, atom
, title
);
1026 /***********************************************************************
1027 * FindWindow32A (USER32.197)
1029 HWND
FindWindow32A( LPCSTR className
, LPCSTR title
)
1031 return FindWindowEx32A( 0, 0, className
, title
);
1035 /***********************************************************************
1036 * FindWindowEx32A (USER32.198)
1038 HWND
FindWindowEx32A( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
1042 atom
= className
? GlobalFindAtom32A( className
) : 0;
1043 return WIN_FindWindow( 0, 0, atom
, title
);
1047 /***********************************************************************
1048 * FindWindowEx32W (USER32.199)
1050 HWND
FindWindowEx32W(HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
1056 atom
= className
? GlobalFindAtom32W( className
) : 0;
1057 buffer
= STRING32_DupUniToAnsi( title
);
1058 hwnd
= WIN_FindWindow( 0, 0, atom
, buffer
);
1064 /***********************************************************************
1065 * FindWindow32W (USER32.200)
1067 HWND
FindWindow32W( LPCWSTR className
, LPCWSTR title
)
1069 return FindWindowEx32W( 0, 0, className
, title
);
1073 /**********************************************************************
1076 WND
*WIN_GetDesktop(void)
1082 /**********************************************************************
1083 * GetDesktopWindow (USER.286)
1085 HWND
GetDesktopWindow(void)
1087 return pWndDesktop
->hwndSelf
;
1091 /**********************************************************************
1092 * GetDesktopHwnd (USER.278)
1094 * Exactly the same thing as GetDesktopWindow(), but not documented.
1095 * Don't ask me why...
1097 HWND
GetDesktopHwnd(void)
1099 return pWndDesktop
->hwndSelf
;
1103 /*******************************************************************
1104 * EnableWindow (USER.34)
1106 BOOL
EnableWindow( HWND hwnd
, BOOL enable
)
1110 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
1111 if (enable
&& (wndPtr
->dwStyle
& WS_DISABLED
))
1114 wndPtr
->dwStyle
&= ~WS_DISABLED
;
1115 SendMessage16( hwnd
, WM_ENABLE
, TRUE
, 0 );
1118 else if (!enable
&& !(wndPtr
->dwStyle
& WS_DISABLED
))
1120 /* Disable window */
1121 wndPtr
->dwStyle
|= WS_DISABLED
;
1122 if ((hwnd
== GetFocus()) || IsChild( hwnd
, GetFocus() ))
1123 SetFocus( 0 ); /* A disabled window can't have the focus */
1124 if ((hwnd
== GetCapture()) || IsChild( hwnd
, GetCapture() ))
1125 ReleaseCapture(); /* A disabled window can't capture the mouse */
1126 SendMessage16( hwnd
, WM_ENABLE
, FALSE
, 0 );
1129 return ((wndPtr
->dwStyle
& WS_DISABLED
) != 0);
1133 /***********************************************************************
1134 * IsWindowEnabled (USER.35) (USER32.348)
1136 BOOL
IsWindowEnabled(HWND hWnd
)
1140 if (!(wndPtr
= WIN_FindWndPtr(hWnd
))) return FALSE
;
1141 return !(wndPtr
->dwStyle
& WS_DISABLED
);
1145 /***********************************************************************
1146 * IsWindowUnicode (USER32.349)
1148 BOOL
IsWindowUnicode( HWND hwnd
)
1152 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return FALSE
;
1153 return (WINPROC_GetWinProcType( wndPtr
->winproc
) == WIN_PROC_32W
);
1157 /**********************************************************************
1158 * GetWindowWord (USER.133) (USER32.313)
1160 WORD
GetWindowWord( HWND32 hwnd
, INT32 offset
)
1162 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1163 if (!wndPtr
) return 0;
1164 if (offset
>= 0) return *(WORD
*)(((char *)wndPtr
->wExtra
) + offset
);
1167 case GWW_ID
: return wndPtr
->wIDmenu
;
1168 case GWW_HWNDPARENT
: return wndPtr
->parent
? wndPtr
->parent
->hwndSelf
: 0;
1169 case GWW_HINSTANCE
: return (WORD
)wndPtr
->hInstance
;
1171 fprintf( stderr
, "GetWindowWord: invalid offset %d\n", offset
);
1177 /**********************************************************************
1178 * WIN_GetWindowInstance
1180 HINSTANCE
WIN_GetWindowInstance(HWND hwnd
)
1182 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1183 if (!wndPtr
) return (HINSTANCE
)0;
1184 return wndPtr
->hInstance
;
1188 /**********************************************************************
1189 * SetWindowWord (USER.134) (USER32.523)
1191 WORD
SetWindowWord( HWND32 hwnd
, INT32 offset
, WORD newval
)
1194 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1195 if (!wndPtr
) return 0;
1196 if (offset
>= 0) ptr
= (WORD
*)(((char *)wndPtr
->wExtra
) + offset
);
1199 case GWW_ID
: ptr
= (WORD
*)&wndPtr
->wIDmenu
; break;
1200 case GWW_HINSTANCE
: ptr
= (WORD
*)&wndPtr
->hInstance
; break;
1202 fprintf( stderr
, "SetWindowWord: invalid offset %d\n", offset
);
1211 /**********************************************************************
1212 * GetWindowLong16 (USER.135)
1214 LONG
GetWindowLong16( HWND16 hwnd
, INT16 offset
)
1216 LONG ret
= GetWindowLong32A( (HWND32
)hwnd
, offset
);
1217 if (offset
== GWL_WNDPROC
) return (LONG
)WINPROC_GetFunc16( (HANDLE32
)ret
);
1222 /**********************************************************************
1223 * GetWindowLong32A (USER32.304)
1225 LONG
GetWindowLong32A( HWND32 hwnd
, INT32 offset
)
1227 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1228 if (!wndPtr
) return 0;
1229 if (offset
>= 0) return *(LONG
*)(((char *)wndPtr
->wExtra
) + offset
);
1232 case GWL_USERDATA
: return wndPtr
->userdata
;
1233 case GWL_STYLE
: return wndPtr
->dwStyle
;
1234 case GWL_EXSTYLE
: return wndPtr
->dwExStyle
;
1235 case GWL_ID
: return wndPtr
->wIDmenu
;
1236 case GWL_WNDPROC
: return (LONG
)WINPROC_GetFunc32( wndPtr
->winproc
);
1237 case GWL_HWNDPARENT
: return wndPtr
->parent
?
1238 (HWND32
)wndPtr
->parent
->hwndSelf
: 0;
1239 case GWL_HINSTANCE
: return (HINSTANCE32
)wndPtr
->hInstance
;
1241 fprintf( stderr
, "GetWindowLong32A: unknown offset %d\n", offset
);
1247 /**********************************************************************
1248 * GetWindowLong32W (USER32.305)
1250 LONG
GetWindowLong32W( HWND32 hwnd
, INT32 offset
)
1252 return GetWindowLong32A( hwnd
, offset
);
1256 /**********************************************************************
1257 * SetWindowLong16 (USER.136)
1259 LONG
SetWindowLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
1261 if (offset
== GWL_WNDPROC
)
1264 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1265 if (!wndPtr
) return 0;
1266 ret
= WIN_SetWndProc( wndPtr
, (HANDLE32
)newval
, WIN_PROC_16
);
1267 return (LONG
)WINPROC_GetFunc16( ret
);
1269 return SetWindowLong32A( hwnd
, offset
, newval
);
1273 /**********************************************************************
1274 * SetWindowLong32A (USER32.516)
1276 LONG
SetWindowLong32A( HWND32 hwnd
, INT32 offset
, LONG newval
)
1279 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1280 if (!wndPtr
) return 0;
1281 if (offset
>= 0) ptr
= (LONG
*)(((char *)wndPtr
->wExtra
) + offset
);
1286 return SetWindowWord( hwnd
, offset
, (WORD
)newval
);
1288 return (LONG
)WINPROC_GetFunc32( WIN_SetWndProc( wndPtr
,
1291 case GWL_USERDATA
: ptr
= &wndPtr
->userdata
; break;
1292 case GWL_STYLE
: ptr
= &wndPtr
->dwStyle
; break;
1293 case GWL_EXSTYLE
: ptr
= &wndPtr
->dwExStyle
; break;
1295 fprintf( stderr
, "SetWindowLong: invalid offset %d\n", offset
);
1304 /**********************************************************************
1305 * SetWindowLong32W (USER32.517)
1307 LONG
SetWindowLong32W( HWND32 hwnd
, INT32 offset
, LONG newval
)
1309 if (offset
== GCL_WNDPROC
)
1311 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1312 if (!wndPtr
) return 0;
1313 return (LONG
)WINPROC_GetFunc32( WIN_SetWndProc( wndPtr
,
1317 return SetWindowLong32A( hwnd
, offset
, newval
);
1321 /*******************************************************************
1322 * GetWindowText16 (USER.36)
1324 INT16
GetWindowText16( HWND16 hwnd
, SEGPTR lpString
, INT16 nMaxCount
)
1326 return (INT16
)SendMessage16(hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1330 /*******************************************************************
1331 * GetWindowText32A (USER32.308)
1333 INT32
GetWindowText32A( HWND32 hwnd
, LPSTR lpString
, INT32 nMaxCount
)
1335 return (INT32
)SendMessage32A( hwnd
, WM_GETTEXT
, nMaxCount
,
1340 /*******************************************************************
1341 * GetWindowText32W (USER32.311)
1343 INT32
GetWindowText32W( HWND32 hwnd
, LPWSTR lpString
, INT32 nMaxCount
)
1345 return (INT32
)SendMessage32W( hwnd
, WM_GETTEXT
, nMaxCount
,
1350 /*******************************************************************
1351 * SetWindowText16 (USER.37)
1353 void SetWindowText16( HWND16 hwnd
, SEGPTR lpString
)
1355 SendMessage16( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1359 /*******************************************************************
1360 * SetWindowText32A (USER32.)
1362 void SetWindowText32A( HWND32 hwnd
, LPCSTR lpString
)
1364 SendMessage32A( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1368 /*******************************************************************
1369 * SetWindowText32W (USER32.)
1371 void SetWindowText32W( HWND32 hwnd
, LPCWSTR lpString
)
1373 SendMessage32W( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1377 /*******************************************************************
1378 * GetWindowTextLength (USER.38)
1380 int GetWindowTextLength(HWND hwnd
)
1382 return (int)SendMessage16(hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
1386 /*******************************************************************
1387 * IsWindow (USER.47)
1389 BOOL
IsWindow( HWND hwnd
)
1391 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1392 return ((wndPtr
!= NULL
) && (wndPtr
->dwMagic
== WND_MAGIC
));
1396 /*****************************************************************
1397 * GetParent (USER.46)
1399 HWND
GetParent(HWND hwnd
)
1401 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1402 if (!wndPtr
) return 0;
1403 wndPtr
= (wndPtr
->dwStyle
& WS_CHILD
) ? wndPtr
->parent
: wndPtr
->owner
;
1404 return wndPtr
? wndPtr
->hwndSelf
: 0;
1408 /*****************************************************************
1411 * Get the top-level parent for a child window.
1413 HWND
WIN_GetTopParent( HWND hwnd
)
1415 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1416 while (wndPtr
&& (wndPtr
->dwStyle
& WS_CHILD
)) wndPtr
= wndPtr
->parent
;
1417 return wndPtr
? wndPtr
->hwndSelf
: 0;
1421 /*****************************************************************
1422 * SetParent (USER.233)
1424 HWND
SetParent(HWND hwndChild
, HWND hwndNewParent
)
1428 WND
*wndPtr
= WIN_FindWndPtr(hwndChild
);
1429 WND
*pWndParent
= WIN_FindWndPtr( hwndNewParent
);
1430 if (!wndPtr
|| !pWndParent
|| !(wndPtr
->dwStyle
& WS_CHILD
)) return 0;
1432 oldParent
= wndPtr
->parent
->hwndSelf
;
1434 WIN_UnlinkWindow(hwndChild
);
1435 if (hwndNewParent
) wndPtr
->parent
= pWndParent
;
1436 WIN_LinkWindow(hwndChild
, HWND_BOTTOM
);
1438 if (IsWindowVisible(hwndChild
)) UpdateWindow(hwndChild
);
1445 /*******************************************************************
1448 BOOL
IsChild( HWND parent
, HWND child
)
1450 WND
* wndPtr
= WIN_FindWndPtr( child
);
1451 while (wndPtr
&& (wndPtr
->dwStyle
& WS_CHILD
))
1453 wndPtr
= wndPtr
->parent
;
1454 if (wndPtr
->hwndSelf
== parent
) return TRUE
;
1460 /***********************************************************************
1461 * IsWindowVisible (USER.49) (USER32.350)
1463 BOOL
IsWindowVisible( HWND hwnd
)
1465 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1466 while (wndPtr
&& (wndPtr
->dwStyle
& WS_CHILD
))
1468 if (!(wndPtr
->dwStyle
& WS_VISIBLE
)) return FALSE
;
1469 wndPtr
= wndPtr
->parent
;
1471 return (wndPtr
&& (wndPtr
->dwStyle
& WS_VISIBLE
));
1476 /*******************************************************************
1477 * GetTopWindow (USER.229)
1479 HWND
GetTopWindow( HWND hwnd
)
1481 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1482 if (wndPtr
&& wndPtr
->child
) return wndPtr
->child
->hwndSelf
;
1487 /*******************************************************************
1488 * GetWindow (USER.262)
1490 HWND
GetWindow( HWND hwnd
, WORD rel
)
1492 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1493 if (!wndPtr
) return 0;
1497 if (wndPtr
->parent
) return wndPtr
->parent
->child
->hwndSelf
;
1501 if (!wndPtr
->parent
) return 0; /* Desktop window */
1502 while (wndPtr
->next
) wndPtr
= wndPtr
->next
;
1503 return wndPtr
->hwndSelf
;
1506 if (!wndPtr
->next
) return 0;
1507 return wndPtr
->next
->hwndSelf
;
1510 if (!wndPtr
->parent
) return 0; /* Desktop window */
1511 wndPtr
= wndPtr
->parent
->child
; /* First sibling */
1512 if (wndPtr
->hwndSelf
== hwnd
) return 0; /* First in list */
1513 while (wndPtr
->next
)
1515 if (wndPtr
->next
->hwndSelf
== hwnd
) return wndPtr
->hwndSelf
;
1516 wndPtr
= wndPtr
->next
;
1521 return wndPtr
->owner
? wndPtr
->owner
->hwndSelf
: 0;
1524 return wndPtr
->child
? wndPtr
->child
->hwndSelf
: 0;
1530 /*******************************************************************
1531 * GetNextWindow (USER.230)
1533 HWND
GetNextWindow( HWND hwnd
, WORD flag
)
1535 if ((flag
!= GW_HWNDNEXT
) && (flag
!= GW_HWNDPREV
)) return 0;
1536 return GetWindow( hwnd
, flag
);
1539 /*******************************************************************
1540 * ShowOwnedPopups (USER.265)
1542 void ShowOwnedPopups( HWND owner
, BOOL fShow
)
1544 WND
*pWnd
= pWndDesktop
->child
;
1547 if (pWnd
->owner
&& (pWnd
->owner
->hwndSelf
== owner
) &&
1548 (pWnd
->dwStyle
& WS_POPUP
))
1549 ShowWindow( pWnd
->hwndSelf
, fShow
? SW_SHOW
: SW_HIDE
);
1555 /*******************************************************************
1556 * GetLastActivePopup (USER.287)
1558 HWND
GetLastActivePopup(HWND hwnd
)
1561 wndPtr
= WIN_FindWndPtr(hwnd
);
1562 if (wndPtr
== NULL
) return hwnd
;
1563 return wndPtr
->hwndLastActive
;
1567 /*******************************************************************
1568 * EnumWindows (USER.54)
1570 BOOL
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
1576 /* We have to build a list of all windows first, to avoid */
1577 /* unpleasant side-effects, for instance if the callback */
1578 /* function changes the Z-order of the windows. */
1580 /* First count the windows */
1583 for (wndPtr
= pWndDesktop
->child
; wndPtr
; wndPtr
= wndPtr
->next
) count
++;
1584 if (!count
) return TRUE
;
1586 /* Now build the list of all windows */
1588 if (!(pWnd
= list
= (HWND
*)malloc( sizeof(HWND
) * count
))) return FALSE
;
1589 for (wndPtr
= pWndDesktop
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
1590 *pWnd
++ = wndPtr
->hwndSelf
;
1592 /* Now call the callback function for every window */
1594 for (pWnd
= list
; count
> 0; count
--, pWnd
++)
1596 /* Make sure that window still exists */
1597 if (!IsWindow(*pWnd
)) continue;
1598 if (!CallEnumWindowsProc( lpEnumFunc
, *pWnd
, lParam
)) break;
1605 /**********************************************************************
1606 * EnumTaskWindows (USER.225)
1608 BOOL
EnumTaskWindows( HTASK hTask
, WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
1612 HANDLE hQueue
= GetTaskQueue( hTask
);
1615 /* This function is the same as EnumWindows(), */
1616 /* except for an added check on the window queue. */
1618 /* First count the windows */
1621 for (wndPtr
= pWndDesktop
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
1622 if (wndPtr
->hmemTaskQ
== hQueue
) count
++;
1623 if (!count
) return TRUE
;
1625 /* Now build the list of all windows */
1627 if (!(pWnd
= list
= (HWND
*)malloc( sizeof(HWND
) * count
))) return FALSE
;
1628 for (wndPtr
= pWndDesktop
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
1629 if (wndPtr
->hmemTaskQ
== hQueue
) *pWnd
++ = wndPtr
->hwndSelf
;
1631 /* Now call the callback function for every window */
1633 for (pWnd
= list
; count
> 0; count
--, pWnd
++)
1635 /* Make sure that window still exists */
1636 if (!IsWindow(*pWnd
)) continue;
1637 if (!CallEnumTaskWndProc( lpEnumFunc
, *pWnd
, lParam
)) break;
1644 /*******************************************************************
1647 * o hwnd is the first child to use, loop until all next windows
1652 * o call ourselves with the next child window
1655 static BOOL
WIN_EnumChildWin( WND
*wndPtr
, FARPROC wndenumprc
, LPARAM lParam
)
1657 WND
*pWndNext
, *pWndChild
;
1660 pWndNext
= wndPtr
->next
; /* storing hwnd is a way to avoid.. */
1661 pWndChild
= wndPtr
->child
; /* ..side effects after wndenumprc */
1662 if (!CallEnumWindowsProc( wndenumprc
, wndPtr
->hwndSelf
, lParam
))
1664 if (pWndChild
&& IsWindow(pWndChild
->hwndSelf
))
1665 if (!WIN_EnumChildWin(pWndChild
, wndenumprc
, lParam
)) return 0;
1672 /*******************************************************************
1673 * EnumChildWindows (USER.55)
1675 * o gets the first child of hwnd
1677 * o calls WIN_EnumChildWin to do a recursive decent of child windows
1679 BOOL
EnumChildWindows(HWND hwnd
, WNDENUMPROC wndenumprc
, LPARAM lParam
)
1683 dprintf_enum(stddeb
,"EnumChildWindows\n");
1685 if (hwnd
== 0) return 0;
1686 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
1687 return WIN_EnumChildWin(wndPtr
->child
, wndenumprc
, lParam
);
1691 /*******************************************************************
1692 * AnyPopup (USER.52)
1697 for (wndPtr
= pWndDesktop
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
1698 if (wndPtr
->owner
&& (wndPtr
->dwStyle
& WS_VISIBLE
)) return TRUE
;
1702 /*******************************************************************
1703 * FlashWindow [USER.105]
1705 BOOL
FlashWindow(HWND hWnd
, BOOL bInvert
)
1707 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1709 dprintf_win(stddeb
,"FlashWindow: %04x\n", hWnd
);
1711 if (!wndPtr
) return FALSE
;
1713 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1715 if (bInvert
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
1717 HDC hDC
= GetDC(hWnd
);
1719 if (!SendMessage16( hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, (LPARAM
)0 ))
1720 wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
1722 ReleaseDC( hWnd
, hDC
);
1723 wndPtr
->flags
|= WIN_NCACTIVATED
;
1727 RedrawWindow32( hWnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
|
1728 RDW_UPDATENOW
| RDW_FRAME
);
1729 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
1736 if (bInvert
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
1737 else wparam
= (hWnd
== GetActiveWindow());
1739 SendMessage16( hWnd
, WM_NCACTIVATE
, wparam
, (LPARAM
)0 );
1745 /*******************************************************************
1746 * SetSysModalWindow [USER.188]
1748 HWND
SetSysModalWindow(HWND hWnd
)
1750 HWND hWndOldModal
= hwndSysModal
;
1751 hwndSysModal
= hWnd
;
1752 dprintf_win(stdnimp
,"EMPTY STUB !! SetSysModalWindow(%04x) !\n", hWnd
);
1753 return hWndOldModal
;
1757 /*******************************************************************
1758 * GetSysModalWindow [USER.189]
1760 HWND
GetSysModalWindow(void)
1762 return hwndSysModal
;
1765 /*******************************************************************
1768 * recursively find a child that contains spDragInfo->pt point
1769 * and send WM_QUERYDROPOBJECT
1771 BOOL
DRAG_QueryUpdate( HWND hQueryWnd
, SEGPTR spDragInfo
)
1773 BOOL wParam
,bResult
= 0;
1775 LPDRAGINFO ptrDragInfo
= (LPDRAGINFO
) PTR_SEG_TO_LIN(spDragInfo
);
1776 WND
*ptrQueryWnd
= WIN_FindWndPtr(hQueryWnd
),*ptrWnd
;
1777 RECT16 tempRect
; /* this sucks */
1779 if( !ptrQueryWnd
|| !ptrDragInfo
) return 0;
1781 pt
= ptrDragInfo
->pt
;
1783 GetWindowRect16(hQueryWnd
,&tempRect
);
1785 if( !PtInRect16(&tempRect
,pt
) ||
1786 (ptrQueryWnd
->dwStyle
& WS_DISABLED
) )
1789 if( !(ptrQueryWnd
->dwStyle
& WS_MINIMIZE
) )
1791 tempRect
= ptrQueryWnd
->rectClient
;
1792 if(ptrQueryWnd
->dwStyle
& WS_CHILD
)
1793 MapWindowPoints16(ptrQueryWnd
->parent
->hwndSelf
,0,(LPPOINT16
)&tempRect
,2);
1795 if( PtInRect16(&tempRect
,pt
) )
1799 for (ptrWnd
= ptrQueryWnd
->child
; ptrWnd
;ptrWnd
= ptrWnd
->next
)
1800 if( ptrWnd
->dwStyle
& WS_VISIBLE
)
1802 GetWindowRect16(ptrWnd
->hwndSelf
,&tempRect
);
1804 if( PtInRect16(&tempRect
,pt
) )
1810 dprintf_msg(stddeb
,"DragQueryUpdate: hwnd = %04x, %d %d - %d %d\n",
1811 ptrWnd
->hwndSelf
, ptrWnd
->rectWindow
.left
, ptrWnd
->rectWindow
.top
,
1812 ptrWnd
->rectWindow
.right
, ptrWnd
->rectWindow
.bottom
);
1813 if( !(ptrWnd
->dwStyle
& WS_DISABLED
) )
1814 bResult
= DRAG_QueryUpdate(ptrWnd
->hwndSelf
, spDragInfo
);
1817 if(bResult
) return bResult
;
1823 ScreenToClient16(hQueryWnd
,&ptrDragInfo
->pt
);
1825 ptrDragInfo
->hScope
= hQueryWnd
;
1827 bResult
= SendMessage16( hQueryWnd
,WM_QUERYDROPOBJECT
,
1828 (WPARAM
)wParam
,(LPARAM
) spDragInfo
);
1830 ptrDragInfo
->pt
= pt
;
1835 /*******************************************************************
1836 * DragDetect ( USER.465 )
1839 BOOL16
DragDetect(HWND16 hWnd
, POINT16 pt
)
1844 rect
.left
= pt
.x
- wDragWidth
;
1845 rect
.right
= pt
.x
+ wDragWidth
;
1847 rect
.top
= pt
.y
- wDragHeight
;
1848 rect
.bottom
= pt
.y
+ wDragHeight
;
1854 while(PeekMessage(&msg
,0 ,WM_MOUSEFIRST
,WM_MOUSELAST
,PM_REMOVE
))
1856 if( msg
.message
== WM_LBUTTONUP
)
1861 if( msg
.message
== WM_MOUSEMOVE
)
1863 if( !PtInRect16( &rect
, MAKEPOINT16(msg
.lParam
) ) )
1876 /******************************************************************************
1877 * DragObject ( USER.464 )
1880 DWORD
DragObject(HWND hwndScope
, HWND hWnd
, WORD wObj
, HANDLE hOfStruct
,
1881 WORD szList
, HCURSOR hCursor
)
1884 LPDRAGINFO lpDragInfo
;
1886 HCURSOR hDragCursor
=0, hOldCursor
=0, hBummer
=0;
1887 HANDLE hDragInfo
= GlobalAlloc16( GMEM_SHARE
| GMEM_ZEROINIT
, 2*sizeof(DRAGINFO
));
1888 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1891 HCURSOR hCurrentCursor
= 0;
1892 HWND hCurrentWnd
= 0;
1895 lpDragInfo
= (LPDRAGINFO
) GlobalLock16(hDragInfo
);
1896 spDragInfo
= (SEGPTR
) WIN16_GlobalLock16(hDragInfo
);
1898 if( !lpDragInfo
|| !spDragInfo
) return 0L;
1900 hBummer
= LoadCursor(0,IDC_BUMMER
);
1902 if( !hBummer
|| !wndPtr
)
1904 GlobalFree16(hDragInfo
);
1910 if( !(hDragCursor
= CURSORICON_IconToCursor(hCursor
)) )
1912 GlobalFree16(hDragInfo
);
1916 if( hDragCursor
== hCursor
) hDragCursor
= 0;
1917 else hCursor
= hDragCursor
;
1919 hOldCursor
= SetCursor(hDragCursor
);
1922 lpDragInfo
->hWnd
= hWnd
;
1923 lpDragInfo
->hScope
= 0;
1924 lpDragInfo
->wFlags
= wObj
;
1925 lpDragInfo
->hList
= szList
; /* near pointer! */
1926 lpDragInfo
->hOfStruct
= hOfStruct
;
1936 if( !PeekMessage(&msg
,0,WM_MOUSEFIRST
,WM_MOUSELAST
,PM_REMOVE
) )
1939 *(lpDragInfo
+1) = *lpDragInfo
;
1941 lpDragInfo
->pt
= msg
.pt
;
1943 /* update DRAGINFO struct */
1944 dprintf_msg(stddeb
,"drag: lpDI->hScope = %04x\n",lpDragInfo
->hScope
);
1946 if( (btemp
= (WORD
)DRAG_QueryUpdate(hwndScope
, spDragInfo
)) > 0 )
1947 hCurrentCursor
= hCursor
;
1950 hCurrentCursor
= hBummer
;
1951 lpDragInfo
->hScope
= 0;
1953 if( hCurrentCursor
)
1954 SetCursor(hCurrentCursor
);
1956 dprintf_msg(stddeb
,"drag: got %04x\n",btemp
);
1958 /* send WM_DRAGLOOP */
1959 SendMessage16( hWnd
, WM_DRAGLOOP
, (WPARAM
)(hCurrentCursor
!= hBummer
) ,
1960 (LPARAM
) spDragInfo
);
1961 /* send WM_DRAGSELECT or WM_DRAGMOVE */
1962 if( hCurrentWnd
!= lpDragInfo
->hScope
)
1965 SendMessage16( hCurrentWnd
, WM_DRAGSELECT
, 0,
1966 (LPARAM
)MAKELONG(LOWORD(spDragInfo
)+sizeof(DRAGINFO
),
1967 HIWORD(spDragInfo
)) );
1968 hCurrentWnd
= lpDragInfo
->hScope
;
1970 SendMessage16( hCurrentWnd
, WM_DRAGSELECT
, 1, (LPARAM
)spDragInfo
);
1974 SendMessage16( hCurrentWnd
, WM_DRAGMOVE
, 0, (LPARAM
)spDragInfo
);
1977 /* check if we're done */
1978 if( msg
.message
== WM_LBUTTONUP
|| msg
.message
== WM_NCLBUTTONUP
)
1987 SetCursor(hOldCursor
);
1989 DestroyCursor(hDragCursor
);
1992 if( hCurrentCursor
!= hBummer
)
1993 dwRet
= SendMessage16( lpDragInfo
->hScope
, WM_DROPOBJECT
,
1994 (WPARAM
)hWnd
, (LPARAM
)spDragInfo
);
1995 GlobalFree16(hDragInfo
);