2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
19 #include "cursoricon.h"
24 #include "nonclient.h"
27 #include "clipboard.h"
36 #include "stackframe.h"
37 #include "debugtools.h"
39 DEFAULT_DEBUG_CHANNEL(win
)
40 DECLARE_DEBUG_CHANNEL(msg
)
42 /**********************************************************************/
44 WND_DRIVER
*WND_Driver
= NULL
;
47 static WND
*pWndDesktop
= NULL
;
49 static HWND hwndSysModal
= 0;
51 static WORD wDragWidth
= 4;
52 static WORD wDragHeight
= 3;
55 static SYSLEVEL WIN_SysLevel
;
57 /***********************************************************************
62 /* Initialisation of the critical section for thread safeness */
63 _CreateSysLevel( &WIN_SysLevel
, 2 );
66 /***********************************************************************
69 * Locks access to all WND structures for thread safeness
71 void WIN_LockWnds( void )
73 _EnterSysLevel( &WIN_SysLevel
);
76 /***********************************************************************
79 * Unlocks access to all WND structures
81 void WIN_UnlockWnds( void )
83 _LeaveSysLevel( &WIN_SysLevel
);
86 /***********************************************************************
89 * Suspend the lock on WND structures.
90 * Returns the number of locks suspended
92 int WIN_SuspendWndsLock( void )
94 int isuspendedLocks
= _ConfirmSysLevel( &WIN_SysLevel
);
95 int count
= isuspendedLocks
;
98 _LeaveSysLevel( &WIN_SysLevel
);
100 return isuspendedLocks
;
103 /***********************************************************************
104 * WIN_RestoreWndsLock
106 * Restore the suspended locks on WND structures
108 void WIN_RestoreWndsLock( int ipreviousLocks
)
110 while ( ipreviousLocks
-- > 0 )
111 _EnterSysLevel( &WIN_SysLevel
);
114 /***********************************************************************
117 * Return a pointer to the WND structure corresponding to a HWND.
119 WND
* WIN_FindWndPtr( HWND hwnd
)
123 if (!hwnd
|| HIWORD(hwnd
)) goto error2
;
124 ptr
= (WND
*) USER_HEAP_LIN_ADDR( hwnd
);
125 /* Lock all WND structures for thread safeness*/
127 /*and increment destruction monitoring*/
130 if (ptr
->dwMagic
!= WND_MAGIC
) goto error
;
131 if (ptr
->hwndSelf
!= hwnd
)
133 ERR("Can't happen: hwnd %04x self pointer is %04x\n",hwnd
, ptr
->hwndSelf
);
136 /* returns a locked pointer */
139 /* Unlock all WND structures for thread safeness*/
141 /* and decrement destruction monitoring value */
146 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
150 /***********************************************************************
153 * Use in case the wnd ptr is not initialized with WIN_FindWndPtr
155 * Returns the locked initialisation pointer
157 WND
*WIN_LockWndPtr(WND
*initWndPtr
)
159 if(!initWndPtr
) return 0;
161 /* Lock all WND structures for thread safeness*/
163 /*and increment destruction monitoring*/
164 initWndPtr
->irefCount
++;
170 /***********************************************************************
173 * Release the pointer to the WND structure.
175 void WIN_ReleaseWndPtr(WND
*wndPtr
)
179 /*Decrement destruction monitoring value*/
181 /* Check if it's time to release the memory*/
182 if(wndPtr
->irefCount
== 0 && !wndPtr
->dwMagic
)
185 USER_HEAP_FREE( wndPtr
->hwndSelf
);
186 wndPtr
->hwndSelf
= 0;
188 else if(wndPtr
->irefCount
< 0)
190 /* This else if is useful to monitor the WIN_ReleaseWndPtr function */
191 ERR("forgot a Lock on %p somewhere\n",wndPtr
);
193 /*unlock all WND structures for thread safeness*/
197 /***********************************************************************
200 * Updates the value of oldPtr to newPtr.
202 void WIN_UpdateWndPtr(WND
**oldPtr
, WND
*newPtr
)
206 tmpWnd
= WIN_LockWndPtr(newPtr
);
207 WIN_ReleaseWndPtr(*oldPtr
);
212 /***********************************************************************
215 * Dump the content of a window structure to stderr.
217 void WIN_DumpWindow( HWND hwnd
)
223 if (!(ptr
= WIN_FindWndPtr( hwnd
)))
225 WARN("%04x is not a window handle\n", hwnd
);
229 if (!GetClassNameA( hwnd
, className
, sizeof(className
) ))
230 strcpy( className
, "#NULL#" );
232 TRACE("Window %04x (%p):\n", hwnd
, ptr
);
233 DPRINTF( "next=%p child=%p parent=%p owner=%p class=%p '%s'\n"
234 "inst=%04x taskQ=%04x updRgn=%04x active=%04x dce=%p idmenu=%08x\n"
235 "style=%08lx exstyle=%08lx wndproc=%08x text='%s'\n"
236 "client=%d,%d-%d,%d window=%d,%d-%d,%d"
237 "sysmenu=%04x flags=%04x props=%p vscroll=%p hscroll=%p\n",
238 ptr
->next
, ptr
->child
, ptr
->parent
, ptr
->owner
,
239 ptr
->class, className
, ptr
->hInstance
, ptr
->hmemTaskQ
,
240 ptr
->hrgnUpdate
, ptr
->hwndLastActive
, ptr
->dce
, ptr
->wIDmenu
,
241 ptr
->dwStyle
, ptr
->dwExStyle
, (UINT
)ptr
->winproc
,
242 ptr
->text
? ptr
->text
: "",
243 ptr
->rectClient
.left
, ptr
->rectClient
.top
, ptr
->rectClient
.right
,
244 ptr
->rectClient
.bottom
, ptr
->rectWindow
.left
, ptr
->rectWindow
.top
,
245 ptr
->rectWindow
.right
, ptr
->rectWindow
.bottom
, ptr
->hSysMenu
,
246 ptr
->flags
, ptr
->pProp
, ptr
->pVScroll
, ptr
->pHScroll
);
248 if (ptr
->class->cbWndExtra
)
250 DPRINTF( "extra bytes:" );
251 for (i
= 0; i
< ptr
->class->cbWndExtra
; i
++)
252 DPRINTF( " %02x", *((BYTE
*)ptr
->wExtra
+i
) );
256 WIN_ReleaseWndPtr(ptr
);
260 /***********************************************************************
263 * Walk the windows tree and print each window on stderr.
265 void WIN_WalkWindows( HWND hwnd
, int indent
)
270 ptr
= hwnd
? WIN_FindWndPtr( hwnd
) : WIN_GetDesktop();
274 WARN("Invalid window handle %04x\n", hwnd
);
278 if (!indent
) /* first time around */
279 DPRINTF( "%-16.16s %-8.8s %-6.6s %-17.17s %-8.8s %s\n",
280 "hwnd", " wndPtr", "queue", "Class Name", " Style", " WndProc"
285 DPRINTF( "%*s%04x%*s", indent
, "", ptr
->hwndSelf
, 13-indent
,"");
287 GlobalGetAtomNameA(ptr
->class->atomName
,className
,sizeof(className
));
289 DPRINTF( "%08lx %-6.4x %-17.17s %08x %08x %.14s\n",
290 (DWORD
)ptr
, ptr
->hmemTaskQ
, className
,
291 (UINT
)ptr
->dwStyle
, (UINT
)ptr
->winproc
,
292 ptr
->text
?ptr
->text
:"<null>");
294 if (ptr
->child
) WIN_WalkWindows( ptr
->child
->hwndSelf
, indent
+1 );
295 WIN_UpdateWndPtr(&ptr
,ptr
->next
);
301 /***********************************************************************
304 * Remove a window from the siblings linked list.
306 BOOL
WIN_UnlinkWindow( HWND hwnd
)
308 WND
*wndPtr
, **ppWnd
;
311 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
312 else if(!wndPtr
->parent
)
314 WIN_ReleaseWndPtr(wndPtr
);
318 ppWnd
= &wndPtr
->parent
->child
;
319 while (*ppWnd
&& *ppWnd
!= wndPtr
) ppWnd
= &(*ppWnd
)->next
;
322 *ppWnd
= wndPtr
->next
;
325 WIN_ReleaseWndPtr(wndPtr
);
330 /***********************************************************************
333 * Insert a window into the siblings linked list.
334 * The window is inserted after the specified window, which can also
335 * be specified as HWND_TOP or HWND_BOTTOM.
337 BOOL
WIN_LinkWindow( HWND hwnd
, HWND hwndInsertAfter
)
339 WND
*wndPtr
, **ppWnd
;
341 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
342 else if(!wndPtr
->parent
)
344 WIN_ReleaseWndPtr(wndPtr
);
347 if ((hwndInsertAfter
== HWND_TOP
) || (hwndInsertAfter
== HWND_BOTTOM
))
349 ppWnd
= &wndPtr
->parent
->child
; /* Point to first sibling hwnd */
350 if (hwndInsertAfter
== HWND_BOTTOM
) /* Find last sibling hwnd */
351 while (*ppWnd
) ppWnd
= &(*ppWnd
)->next
;
353 else /* Normal case */
355 WND
* afterPtr
= WIN_FindWndPtr( hwndInsertAfter
);
358 WIN_ReleaseWndPtr(wndPtr
);
361 ppWnd
= &afterPtr
->next
;
362 WIN_ReleaseWndPtr(afterPtr
);
364 wndPtr
->next
= *ppWnd
;
366 WIN_ReleaseWndPtr(wndPtr
);
371 /***********************************************************************
372 * WIN_FindWinToRepaint
374 * Find a window that needs repaint.
376 HWND
WIN_FindWinToRepaint( HWND hwnd
, HQUEUE16 hQueue
)
381 /* Note: the desktop window never gets WM_PAINT messages
382 * The real reason why is because Windows DesktopWndProc
383 * does ValidateRgn inside WM_ERASEBKGND handler.
386 pWnd
= hwnd
? WIN_FindWndPtr(hwnd
) : WIN_LockWndPtr(pWndDesktop
->child
);
388 for ( ; pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
390 if (!(pWnd
->dwStyle
& WS_VISIBLE
))
392 TRACE("skipping window %04x\n",
395 else if ((pWnd
->hmemTaskQ
== hQueue
) &&
396 (pWnd
->hrgnUpdate
|| (pWnd
->flags
& WIN_INTERNAL_PAINT
)))
399 else if (pWnd
->child
)
400 if ((hwndRet
= WIN_FindWinToRepaint( pWnd
->child
->hwndSelf
, hQueue
)) )
402 WIN_ReleaseWndPtr(pWnd
);
413 hwndRet
= pWnd
->hwndSelf
;
415 /* look among siblings if we got a transparent window */
416 while (pWnd
&& ((pWnd
->dwExStyle
& WS_EX_TRANSPARENT
) ||
417 !(pWnd
->hrgnUpdate
|| (pWnd
->flags
& WIN_INTERNAL_PAINT
))))
419 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
423 hwndRet
= pWnd
->hwndSelf
;
424 WIN_ReleaseWndPtr(pWnd
);
426 TRACE("found %04x\n",hwndRet
);
431 /***********************************************************************
434 * Destroy storage associated to a window. "Internals" p.358
435 * returns a locked wndPtr->next
437 static WND
* WIN_DestroyWindow( WND
* wndPtr
)
439 HWND hwnd
= wndPtr
->hwndSelf
;
442 TRACE("%04x\n", wndPtr
->hwndSelf
);
444 /* free child windows */
445 WIN_LockWndPtr(wndPtr
->child
);
446 while ((pWnd
= wndPtr
->child
))
448 wndPtr
->child
= WIN_DestroyWindow( pWnd
);
449 WIN_ReleaseWndPtr(pWnd
);
453 * Clear the update region to make sure no WM_PAINT messages will be
454 * generated for this window while processing the WM_NCDESTROY.
456 if ((wndPtr
->hrgnUpdate
) || (wndPtr
->flags
& WIN_INTERNAL_PAINT
))
458 if (wndPtr
->hrgnUpdate
> 1)
459 DeleteObject( wndPtr
->hrgnUpdate
);
461 QUEUE_DecPaintCount( wndPtr
->hmemTaskQ
);
463 wndPtr
->hrgnUpdate
= 0;
467 * Send the WM_NCDESTROY to the window being destroyed.
469 SendMessageA( wndPtr
->hwndSelf
, WM_NCDESTROY
, 0, 0);
471 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
473 WINPOS_CheckInternalPos( wndPtr
);
474 if( hwnd
== GetCapture()) ReleaseCapture();
476 /* free resources associated with the window */
478 TIMER_RemoveWindowTimers( wndPtr
->hwndSelf
);
479 PROPERTY_RemoveWindowProps( wndPtr
);
481 wndPtr
->dwMagic
= 0; /* Mark it as invalid */
483 /* toss stale messages from the queue */
485 if( wndPtr
->hmemTaskQ
)
487 BOOL bPostQuit
= FALSE
;
488 WPARAM wQuitParam
= 0;
489 MESSAGEQUEUE
* msgQ
= (MESSAGEQUEUE
*) QUEUE_Lock(wndPtr
->hmemTaskQ
);
492 while( (qmsg
= QUEUE_FindMsg(msgQ
, hwnd
, 0, 0)) != 0 )
494 if( qmsg
->msg
.message
== WM_QUIT
)
497 wQuitParam
= qmsg
->msg
.wParam
;
499 QUEUE_RemoveMsg(msgQ
, qmsg
);
504 /* repost WM_QUIT to make sure this app exits its message loop */
505 if( bPostQuit
) PostQuitMessage(wQuitParam
);
506 wndPtr
->hmemTaskQ
= 0;
509 if (!(wndPtr
->dwStyle
& WS_CHILD
))
510 if (wndPtr
->wIDmenu
) DestroyMenu( (HMENU
)wndPtr
->wIDmenu
);
511 if (wndPtr
->hSysMenu
) DestroyMenu( wndPtr
->hSysMenu
);
512 wndPtr
->pDriver
->pDestroyWindow( wndPtr
);
513 DCE_FreeWindowDCE( wndPtr
); /* Always do this to catch orphaned DCs */
514 WINPROC_FreeProc( wndPtr
->winproc
, WIN_PROC_WINDOW
);
515 wndPtr
->class->cWindows
--;
516 wndPtr
->class = NULL
;
518 WIN_UpdateWndPtr(&pWnd
,wndPtr
->next
);
520 wndPtr
->pDriver
->pFinalize(wndPtr
);
525 /***********************************************************************
526 * WIN_ResetQueueWindows
528 * Reset the queue of all the children of a given window.
529 * Return TRUE if something was done.
531 BOOL
WIN_ResetQueueWindows( WND
* wnd
, HQUEUE16 hQueue
, HQUEUE16 hNew
)
535 if (hNew
) /* Set a new queue */
537 for (wnd
= WIN_LockWndPtr(wnd
->child
); (wnd
);WIN_UpdateWndPtr(&wnd
,wnd
->next
))
539 if (wnd
->hmemTaskQ
== hQueue
)
541 wnd
->hmemTaskQ
= hNew
;
546 ret
|= WIN_ResetQueueWindows( wnd
, hQueue
, hNew
);
550 else /* Queue is being destroyed */
554 WND
*tmp
= WIN_LockWndPtr(wnd
->child
);
559 if (tmp
->hmemTaskQ
== hQueue
)
561 DestroyWindow( tmp
->hwndSelf
);
565 tmp2
= WIN_LockWndPtr(tmp
->child
);
566 if (tmp2
&& WIN_ResetQueueWindows(tmp2
,hQueue
,0))
570 WIN_UpdateWndPtr(&tmp
,tmp
->next
);
572 WIN_ReleaseWndPtr(tmp2
);
574 WIN_ReleaseWndPtr(tmp
);
581 /***********************************************************************
582 * WIN_CreateDesktopWindow
584 * Create the desktop window.
586 BOOL
WIN_CreateDesktopWindow(void)
591 TRACE("Creating desktop window\n");
594 if (!ICONTITLE_Init() ||
595 !WINPOS_CreateInternalPosAtom() ||
596 !(class = CLASS_FindClassByAtom( DESKTOP_CLASS_ATOM
, 0 )))
599 hwndDesktop
= USER_HEAP_ALLOC( sizeof(WND
)+class->cbWndExtra
);
600 if (!hwndDesktop
) return FALSE
;
601 pWndDesktop
= (WND
*) USER_HEAP_LIN_ADDR( hwndDesktop
);
603 pWndDesktop
->pDriver
= WND_Driver
;
604 pWndDesktop
->pDriver
->pInitialize(pWndDesktop
);
606 pWndDesktop
->next
= NULL
;
607 pWndDesktop
->child
= NULL
;
608 pWndDesktop
->parent
= NULL
;
609 pWndDesktop
->owner
= NULL
;
610 pWndDesktop
->class = class;
611 pWndDesktop
->dwMagic
= WND_MAGIC
;
612 pWndDesktop
->hwndSelf
= hwndDesktop
;
613 pWndDesktop
->hInstance
= 0;
614 pWndDesktop
->rectWindow
.left
= 0;
615 pWndDesktop
->rectWindow
.top
= 0;
616 pWndDesktop
->rectWindow
.right
= GetSystemMetrics(SM_CXSCREEN
);
617 pWndDesktop
->rectWindow
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
618 pWndDesktop
->rectClient
= pWndDesktop
->rectWindow
;
619 pWndDesktop
->text
= NULL
;
620 pWndDesktop
->hmemTaskQ
= GetFastQueue16();
621 pWndDesktop
->hrgnUpdate
= 0;
622 pWndDesktop
->hwndLastActive
= hwndDesktop
;
623 pWndDesktop
->dwStyle
= WS_VISIBLE
| WS_CLIPCHILDREN
|
625 pWndDesktop
->dwExStyle
= 0;
626 pWndDesktop
->dce
= NULL
;
627 pWndDesktop
->pVScroll
= NULL
;
628 pWndDesktop
->pHScroll
= NULL
;
629 pWndDesktop
->pProp
= NULL
;
630 pWndDesktop
->wIDmenu
= 0;
631 pWndDesktop
->helpContext
= 0;
632 pWndDesktop
->flags
= Options
.desktopGeometry
? WIN_NATIVE
: 0;
633 pWndDesktop
->hSysMenu
= 0;
634 pWndDesktop
->userdata
= 0;
635 pWndDesktop
->winproc
= (WNDPROC16
)class->winproc
;
636 pWndDesktop
->irefCount
= 0;
638 /* FIXME: How do we know if it should be Unicode or not */
639 if(!pWndDesktop
->pDriver
->pCreateDesktopWindow(pWndDesktop
, class, FALSE
))
642 SendMessageA( hwndDesktop
, WM_NCCREATE
, 0, 0 );
643 pWndDesktop
->flags
|= WIN_NEEDS_ERASEBKGND
;
648 /***********************************************************************
651 * Implementation of CreateWindowEx().
653 static HWND
WIN_CreateWindowEx( CREATESTRUCTA
*cs
, ATOM classAtom
,
654 BOOL win32
, BOOL unicode
)
660 HWND16 hwnd
, hwndLinkAfter
;
661 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
662 LRESULT (CALLBACK
*localSend32
)(HWND
, UINT
, WPARAM
, LPARAM
);
664 TRACE("%s %s %08lx %08lx %d,%d %dx%d %04x %04x %08x %p\n",
665 unicode
? debugres_w((LPWSTR
)cs
->lpszName
) : debugres_a(cs
->lpszName
),
666 unicode
? debugres_w((LPWSTR
)cs
->lpszClass
) : debugres_a(cs
->lpszClass
),
667 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
668 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
670 /* Find the parent window */
674 /* Make sure parent is valid */
675 if (!IsWindow( cs
->hwndParent
))
677 WARN("Bad parent %04x\n", cs
->hwndParent
);
680 } else if ((cs
->style
& WS_CHILD
) && !(cs
->style
& WS_POPUP
)) {
681 WARN("No parent for child window\n" );
682 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
685 /* Find the window class */
686 if (!(classPtr
= CLASS_FindClassByAtom( classAtom
, win32
?cs
->hInstance
:GetExePtr(cs
->hInstance
) )))
688 WARN("Bad class '%s'\n", cs
->lpszClass
);
692 /* Fix the coordinates */
694 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
696 PDB
*pdb
= PROCESS_Current();
698 /* Never believe Microsoft's documentation... CreateWindowEx doc says
699 * that if an overlapped window is created with WS_VISIBLE style bit
700 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
701 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
704 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
705 * 2) it does not ignore the y parameter as the docs claim; instead, it
706 * uses it as second parameter to ShowWindow() unless y is either
707 * CW_USEDEFAULT or CW_USEDEFAULT16.
709 * The fact that we didn't do 2) caused bogus windows pop up when wine
710 * was running apps that were using this obscure feature. Example -
711 * calc.exe that comes with Win98 (only Win98, it's different from
712 * the one that comes with Win95 and NT)
714 if (cs
->y
!= CW_USEDEFAULT
&& cs
->y
!= CW_USEDEFAULT16
) sw
= cs
->y
;
716 /* We have saved cs->y, now we can trash it */
717 if ( !(cs
->style
& (WS_CHILD
| WS_POPUP
))
718 && (pdb
->env_db
->startup_info
->dwFlags
& STARTF_USEPOSITION
) )
720 cs
->x
= pdb
->env_db
->startup_info
->dwX
;
721 cs
->y
= pdb
->env_db
->startup_info
->dwY
;
729 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
)
731 PDB
*pdb
= PROCESS_Current();
732 if ( !(cs
->style
& (WS_CHILD
| WS_POPUP
))
733 && (pdb
->env_db
->startup_info
->dwFlags
& STARTF_USESIZE
) )
735 cs
->cx
= pdb
->env_db
->startup_info
->dwXSize
;
736 cs
->cy
= pdb
->env_db
->startup_info
->dwYSize
;
740 cs
->cx
= 600; /* FIXME */
745 /* Create the window structure */
747 if (!(hwnd
= USER_HEAP_ALLOC( sizeof(*wndPtr
) + classPtr
->cbWndExtra
748 - sizeof(wndPtr
->wExtra
) )))
750 TRACE("out of memory\n" );
754 /* Fill the window structure */
756 wndPtr
= WIN_LockWndPtr((WND
*) USER_HEAP_LIN_ADDR( hwnd
));
758 wndPtr
->child
= NULL
;
760 if ((cs
->style
& WS_CHILD
) && cs
->hwndParent
)
762 wndPtr
->parent
= WIN_FindWndPtr( cs
->hwndParent
);
763 wndPtr
->owner
= NULL
;
764 WIN_ReleaseWndPtr(wndPtr
->parent
);
768 wndPtr
->parent
= pWndDesktop
;
769 if (!cs
->hwndParent
|| (cs
->hwndParent
== pWndDesktop
->hwndSelf
))
770 wndPtr
->owner
= NULL
;
773 WND
*tmpWnd
= WIN_FindWndPtr(cs
->hwndParent
);
774 wndPtr
->owner
= WIN_GetTopParentPtr(tmpWnd
);
775 WIN_ReleaseWndPtr(wndPtr
->owner
);
776 WIN_ReleaseWndPtr(tmpWnd
);
781 wndPtr
->pDriver
= wndPtr
->parent
->pDriver
;
782 wndPtr
->pDriver
->pInitialize(wndPtr
);
784 wndPtr
->class = classPtr
;
785 wndPtr
->winproc
= classPtr
->winproc
;
786 wndPtr
->dwMagic
= WND_MAGIC
;
787 wndPtr
->hwndSelf
= hwnd
;
788 wndPtr
->hInstance
= cs
->hInstance
;
790 wndPtr
->hmemTaskQ
= GetFastQueue16();
791 wndPtr
->hrgnUpdate
= 0;
792 wndPtr
->hwndLastActive
= hwnd
;
793 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
794 wndPtr
->dwExStyle
= cs
->dwExStyle
;
796 wndPtr
->helpContext
= 0;
797 wndPtr
->flags
= win32
? WIN_ISWIN32
: 0;
798 wndPtr
->pVScroll
= NULL
;
799 wndPtr
->pHScroll
= NULL
;
800 wndPtr
->pProp
= NULL
;
801 wndPtr
->userdata
= 0;
802 wndPtr
->hSysMenu
= (wndPtr
->dwStyle
& WS_SYSMENU
)
803 ? MENU_GetSysMenu( hwnd
, 0 ) : 0;
804 wndPtr
->irefCount
= 1;
806 if (classPtr
->cbWndExtra
) memset( wndPtr
->wExtra
, 0, classPtr
->cbWndExtra
);
808 /* Call the WH_CBT hook */
810 hwndLinkAfter
= ((cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
811 ? HWND_BOTTOM
: HWND_TOP
;
813 if (HOOK_IsHooked( WH_CBT
))
819 cbtc
.hwndInsertAfter
= hwndLinkAfter
;
820 ret
= unicode
? HOOK_CallHooksW(WH_CBT
, HCBT_CREATEWND
, hwnd
, (LPARAM
)&cbtc
)
821 : HOOK_CallHooksA(WH_CBT
, HCBT_CREATEWND
, hwnd
, (LPARAM
)&cbtc
);
824 TRACE("CBT-hook returned 0\n");
825 wndPtr
->pDriver
->pFinalize(wndPtr
);
826 USER_HEAP_FREE( hwnd
);
832 /* Increment class window counter */
834 classPtr
->cWindows
++;
836 /* Correct the window style */
838 if (!(cs
->style
& WS_CHILD
))
840 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
841 if (!(cs
->style
& WS_POPUP
))
843 wndPtr
->dwStyle
|= WS_CAPTION
;
844 wndPtr
->flags
|= WIN_NEED_SIZE
;
848 /* Get class or window DC if needed */
850 if (classPtr
->style
& CS_OWNDC
) wndPtr
->dce
= DCE_AllocDCE(hwnd
,DCE_WINDOW_DC
);
851 else if (classPtr
->style
& CS_CLASSDC
) wndPtr
->dce
= classPtr
->dce
;
852 else wndPtr
->dce
= NULL
;
854 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
856 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
858 WINPOS_GetMinMaxInfo( wndPtr
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
859 if (maxSize
.x
< cs
->cx
) cs
->cx
= maxSize
.x
;
860 if (maxSize
.y
< cs
->cy
) cs
->cy
= maxSize
.y
;
861 if (cs
->cx
< minTrack
.x
) cs
->cx
= minTrack
.x
;
862 if (cs
->cy
< minTrack
.y
) cs
->cy
= minTrack
.y
;
865 if(cs
->style
& WS_CHILD
)
867 if(cs
->cx
< 0) cs
->cx
= 0;
868 if(cs
->cy
< 0) cs
->cy
= 0;
872 if (cs
->cx
<= 0) cs
->cx
= 1;
873 if (cs
->cy
<= 0) cs
->cy
= 1;
876 wndPtr
->rectWindow
.left
= cs
->x
;
877 wndPtr
->rectWindow
.top
= cs
->y
;
878 wndPtr
->rectWindow
.right
= cs
->x
+ cs
->cx
;
879 wndPtr
->rectWindow
.bottom
= cs
->y
+ cs
->cy
;
880 wndPtr
->rectClient
= wndPtr
->rectWindow
;
882 if(!wndPtr
->pDriver
->pCreateWindow(wndPtr
, classPtr
, cs
, unicode
))
888 /* Set the window menu */
890 if ((wndPtr
->dwStyle
& (WS_CAPTION
| WS_CHILD
)) == WS_CAPTION
)
892 if (cs
->hMenu
) SetMenu(hwnd
, cs
->hMenu
);
895 #if 0 /* FIXME: should check if classPtr->menuNameW can be used as is */
896 if (classPtr
->menuNameA
)
897 cs
->hMenu
= HIWORD(classPtr
->menuNameA
) ?
898 LoadMenu(cs
->hInstance
,SEGPTR_GET(classPtr
->menuNameA
)):
899 LoadMenu(cs
->hInstance
,(SEGPTR
)classPtr
->menuNameA
);
901 SEGPTR menuName
= (SEGPTR
)GetClassLong16( hwnd
, GCL_MENUNAME
);
904 if (HIWORD(cs
->hInstance
))
905 cs
->hMenu
= LoadMenuA(cs
->hInstance
,PTR_SEG_TO_LIN(menuName
));
907 cs
->hMenu
= LoadMenu16(cs
->hInstance
,menuName
);
909 if (cs
->hMenu
) SetMenu( hwnd
, cs
->hMenu
);
914 else wndPtr
->wIDmenu
= (UINT
)cs
->hMenu
;
916 /* Send the WM_CREATE message
917 * Perhaps we shouldn't allow width/height changes as well.
918 * See p327 in "Internals".
921 maxPos
.x
= wndPtr
->rectWindow
.left
; maxPos
.y
= wndPtr
->rectWindow
.top
;
923 localSend32
= unicode
? SendMessageW
: SendMessageA
;
924 if( (*localSend32
)( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
) )
926 /* Insert the window in the linked list */
928 WIN_LinkWindow( hwnd
, hwndLinkAfter
);
930 WINPOS_SendNCCalcSize( hwnd
, FALSE
, &wndPtr
->rectWindow
,
931 NULL
, NULL
, 0, &wndPtr
->rectClient
);
932 OffsetRect(&wndPtr
->rectWindow
, maxPos
.x
- wndPtr
->rectWindow
.left
,
933 maxPos
.y
- wndPtr
->rectWindow
.top
);
934 if( ((*localSend32
)( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
)) != -1 )
936 /* Send the size messages */
938 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
941 if (((wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
) <0)
942 ||((wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
)<0))
943 WARN("sending bogus WM_SIZE message 0x%08lx\n",
944 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
945 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
946 SendMessageA( hwnd
, WM_SIZE
, SIZE_RESTORED
,
947 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
948 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
949 SendMessageA( hwnd
, WM_MOVE
, 0,
950 MAKELONG( wndPtr
->rectClient
.left
,
951 wndPtr
->rectClient
.top
) );
954 /* Show the window, maximizing or minimizing if needed */
956 if (wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
))
959 UINT16 swFlag
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
960 wndPtr
->dwStyle
&= ~(WS_MAXIMIZE
| WS_MINIMIZE
);
961 WINPOS_MinMaximize( wndPtr
, swFlag
, &newPos
);
962 swFlag
= ((wndPtr
->dwStyle
& WS_CHILD
) || GetActiveWindow())
963 ? SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
964 : SWP_NOZORDER
| SWP_FRAMECHANGED
;
965 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
,
966 newPos
.right
, newPos
.bottom
, swFlag
);
969 if( wndPtr
->dwStyle
& WS_CHILD
&& !(wndPtr
->dwExStyle
& WS_EX_NOPARENTNOTIFY
) )
971 /* Notify the parent window only */
973 SendMessageA( wndPtr
->parent
->hwndSelf
, WM_PARENTNOTIFY
,
974 MAKEWPARAM(WM_CREATE
, wndPtr
->wIDmenu
), (LPARAM
)hwnd
);
975 if( !IsWindow(hwnd
) )
982 if (cs
->style
& WS_VISIBLE
) ShowWindow( hwnd
, sw
);
984 /* Call WH_SHELL hook */
986 if (!(wndPtr
->dwStyle
& WS_CHILD
) && !wndPtr
->owner
)
987 HOOK_CallHooks16( WH_SHELL
, HSHELL_WINDOWCREATED
, hwnd
, 0 );
989 TRACE("created window %04x\n", hwnd
);
993 WIN_UnlinkWindow( hwnd
);
996 /* Abort window creation */
998 WARN("aborted by WM_xxCREATE!\n");
999 WIN_ReleaseWndPtr(WIN_DestroyWindow( wndPtr
));
1002 WIN_ReleaseWndPtr(wndPtr
);
1008 /***********************************************************************
1009 * CreateWindow16 (USER.41)
1011 HWND16 WINAPI
CreateWindow16( LPCSTR className
, LPCSTR windowName
,
1012 DWORD style
, INT16 x
, INT16 y
, INT16 width
,
1013 INT16 height
, HWND16 parent
, HMENU16 menu
,
1014 HINSTANCE16 instance
, LPVOID data
)
1016 return CreateWindowEx16( 0, className
, windowName
, style
,
1017 x
, y
, width
, height
, parent
, menu
, instance
, data
);
1021 /***********************************************************************
1022 * CreateWindowEx16 (USER.452)
1024 HWND16 WINAPI
CreateWindowEx16( DWORD exStyle
, LPCSTR className
,
1025 LPCSTR windowName
, DWORD style
, INT16 x
,
1026 INT16 y
, INT16 width
, INT16 height
,
1027 HWND16 parent
, HMENU16 menu
,
1028 HINSTANCE16 instance
, LPVOID data
)
1034 /* Find the class atom */
1036 if (HIWORD(className
))
1038 if (!(classAtom
= GlobalFindAtomA( className
)))
1040 ERR( "bad class name %s\n", debugres_a(className
) );
1046 classAtom
= LOWORD(className
);
1047 if (!GlobalGetAtomNameA( classAtom
, buffer
, sizeof(buffer
) ))
1049 ERR( "bad atom %x\n", classAtom
);
1055 /* Fix the coordinates */
1057 cs
.x
= (x
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)x
;
1058 cs
.y
= (y
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)y
;
1059 cs
.cx
= (width
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)width
;
1060 cs
.cy
= (height
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)height
;
1062 /* Create the window */
1064 cs
.lpCreateParams
= data
;
1065 cs
.hInstance
= (HINSTANCE
)instance
;
1066 cs
.hMenu
= (HMENU
)menu
;
1067 cs
.hwndParent
= (HWND
)parent
;
1069 cs
.lpszName
= windowName
;
1070 cs
.lpszClass
= className
;
1071 cs
.dwExStyle
= exStyle
;
1073 return WIN_CreateWindowEx( &cs
, classAtom
, FALSE
, FALSE
);
1077 /***********************************************************************
1078 * CreateWindowEx32A (USER32.83)
1080 HWND WINAPI
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1081 LPCSTR windowName
, DWORD style
, INT x
,
1082 INT y
, INT width
, INT height
,
1083 HWND parent
, HMENU menu
,
1084 HINSTANCE instance
, LPVOID data
)
1091 instance
=GetModuleHandleA(NULL
);
1093 if(exStyle
& WS_EX_MDICHILD
)
1094 return MDI_CreateMDIWindowA(className
, windowName
, style
, x
, y
, width
, height
, parent
, instance
, (LPARAM
)data
);
1096 /* Find the class atom */
1098 if (HIWORD(className
))
1100 if (!(classAtom
= GlobalFindAtomA( className
)))
1102 ERR( "bad class name %s\n", debugres_a(className
) );
1108 classAtom
= LOWORD(className
);
1109 if (!GlobalGetAtomNameA( classAtom
, buffer
, sizeof(buffer
) ))
1111 ERR( "bad atom %x\n", classAtom
);
1117 /* Create the window */
1119 cs
.lpCreateParams
= data
;
1120 cs
.hInstance
= instance
;
1122 cs
.hwndParent
= parent
;
1128 cs
.lpszName
= windowName
;
1129 cs
.lpszClass
= className
;
1130 cs
.dwExStyle
= exStyle
;
1132 return WIN_CreateWindowEx( &cs
, classAtom
, TRUE
, FALSE
);
1136 /***********************************************************************
1137 * CreateWindowEx32W (USER32.84)
1139 HWND WINAPI
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1140 LPCWSTR windowName
, DWORD style
, INT x
,
1141 INT y
, INT width
, INT height
,
1142 HWND parent
, HMENU menu
,
1143 HINSTANCE instance
, LPVOID data
)
1150 instance
=GetModuleHandleA(NULL
);
1152 if(exStyle
& WS_EX_MDICHILD
)
1153 return MDI_CreateMDIWindowW(className
, windowName
, style
, x
, y
, width
, height
, parent
, instance
, (LPARAM
)data
);
1155 /* Find the class atom */
1157 if (HIWORD(className
))
1159 if (!(classAtom
= GlobalFindAtomW( className
)))
1161 ERR( "bad class name %s\n", debugres_w(className
) );
1167 classAtom
= LOWORD(className
);
1168 if (!GlobalGetAtomNameW( classAtom
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1170 ERR( "bad atom %x\n", classAtom
);
1176 /* Create the window */
1178 cs
.lpCreateParams
= data
;
1179 cs
.hInstance
= instance
;
1181 cs
.hwndParent
= parent
;
1187 cs
.lpszName
= windowName
;
1188 cs
.lpszClass
= className
;
1189 cs
.dwExStyle
= exStyle
;
1191 /* Note: we rely on the fact that CREATESTRUCT32A and */
1192 /* CREATESTRUCT32W have the same layout. */
1193 return WIN_CreateWindowEx( (CREATESTRUCTA
*)&cs
, classAtom
, TRUE
, TRUE
);
1197 /***********************************************************************
1200 static void WIN_CheckFocus( WND
* pWnd
)
1202 if( GetFocus16() == pWnd
->hwndSelf
)
1203 SetFocus16( (pWnd
->dwStyle
& WS_CHILD
) ? pWnd
->parent
->hwndSelf
: 0 );
1206 /***********************************************************************
1207 * WIN_SendDestroyMsg
1209 static void WIN_SendDestroyMsg( WND
* pWnd
)
1211 WIN_CheckFocus(pWnd
);
1213 if( CARET_GetHwnd() == pWnd
->hwndSelf
) DestroyCaret();
1214 CLIPBOARD_Driver
->pResetOwner( pWnd
, TRUE
);
1217 * Send the WM_DESTROY to the window.
1219 SendMessageA( pWnd
->hwndSelf
, WM_DESTROY
, 0, 0);
1222 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1223 * make sure that the window still exists when we come back.
1225 if (IsWindow(pWnd
->hwndSelf
))
1227 HWND
* pWndArray
= NULL
;
1232 * Now, if the window has kids, we have to send WM_DESTROY messages
1233 * recursively to it's kids. It seems that those calls can also
1234 * trigger re-entrant calls to DestroyWindow for the kids so we must
1235 * protect against corruption of the list of siblings. We first build
1236 * a list of HWNDs representing all the kids.
1238 pChild
= WIN_LockWndPtr(pWnd
->child
);
1242 WIN_UpdateWndPtr(&pChild
,pChild
->next
);
1246 * If there are no kids, we're done.
1251 pWndArray
= HeapAlloc(GetProcessHeap(), 0, nKidCount
*sizeof(HWND
));
1256 if (pWndArray
==NULL
)
1260 * Now, enumerate all the kids in a list, since we wait to make the SendMessage
1261 * call, our linked list of siblings should be safe.
1264 pChild
= WIN_LockWndPtr(pWnd
->child
);
1267 pWndArray
[nKidCount
] = pChild
->hwndSelf
;
1269 WIN_UpdateWndPtr(&pChild
,pChild
->next
);
1273 * Now that we have a list, go through that list again and send the destroy
1274 * message to those windows. We are using the HWND to retrieve the
1275 * WND pointer so we are effectively checking that all the kid windows are
1276 * still valid before sending the message.
1280 pChild
= WIN_FindWndPtr(pWndArray
[--nKidCount
]);
1284 WIN_SendDestroyMsg( pChild
);
1285 WIN_ReleaseWndPtr(pChild
);
1292 HeapFree(GetProcessHeap(), 0, pWndArray
);
1293 WIN_CheckFocus(pWnd
);
1296 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1300 /***********************************************************************
1301 * DestroyWindow16 (USER.53)
1303 BOOL16 WINAPI
DestroyWindow16( HWND16 hwnd
)
1305 return DestroyWindow(hwnd
);
1309 /***********************************************************************
1310 * DestroyWindow32 (USER32.135)
1312 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1317 TRACE("(%04x)\n", hwnd
);
1319 /* Initialization */
1321 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
1322 if (wndPtr
== pWndDesktop
)
1324 retvalue
= FALSE
; /* Can't destroy desktop */
1330 if( HOOK_CallHooks16( WH_CBT
, HCBT_DESTROYWND
, hwnd
, 0L) )
1336 if (!(wndPtr
->dwStyle
& WS_CHILD
) && !wndPtr
->owner
)
1338 HOOK_CallHooks16( WH_SHELL
, HSHELL_WINDOWDESTROYED
, hwnd
, 0L );
1339 /* FIXME: clean up palette - see "Internals" p.352 */
1342 if( !QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
) )
1343 if( wndPtr
->dwStyle
& WS_CHILD
&& !(wndPtr
->dwExStyle
& WS_EX_NOPARENTNOTIFY
) )
1345 /* Notify the parent window only */
1346 SendMessageA( wndPtr
->parent
->hwndSelf
, WM_PARENTNOTIFY
,
1347 MAKEWPARAM(WM_DESTROY
, wndPtr
->wIDmenu
), (LPARAM
)hwnd
);
1348 if( !IsWindow(hwnd
) )
1355 CLIPBOARD_Driver
->pResetOwner( wndPtr
, FALSE
); /* before the window is unmapped */
1357 /* Hide the window */
1359 if (wndPtr
->dwStyle
& WS_VISIBLE
)
1361 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
|
1362 SWP_NOACTIVATE
|SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|
1363 ((QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))?SWP_DEFERERASE
:0) );
1364 if (!IsWindow(hwnd
))
1371 /* Recursively destroy owned windows */
1373 if( !(wndPtr
->dwStyle
& WS_CHILD
) )
1375 /* make sure top menu popup doesn't get destroyed */
1376 MENU_PatchResidentPopup( (HQUEUE16
)0xFFFF, wndPtr
);
1380 WND
*siblingPtr
= WIN_LockWndPtr(wndPtr
->parent
->child
); /* First sibling */
1383 if (siblingPtr
->owner
== wndPtr
)
1385 if (siblingPtr
->hmemTaskQ
== wndPtr
->hmemTaskQ
)
1388 siblingPtr
->owner
= NULL
;
1390 WIN_UpdateWndPtr(&siblingPtr
,siblingPtr
->next
);
1394 DestroyWindow( siblingPtr
->hwndSelf
);
1395 WIN_ReleaseWndPtr(siblingPtr
);
1400 if( !Options
.managed
|| EVENT_CheckFocus() )
1401 WINPOS_ActivateOtherWindow(wndPtr
);
1403 if( wndPtr
->owner
&&
1404 wndPtr
->owner
->hwndLastActive
== wndPtr
->hwndSelf
)
1405 wndPtr
->owner
->hwndLastActive
= wndPtr
->owner
->hwndSelf
;
1408 /* Send destroy messages */
1410 WIN_SendDestroyMsg( wndPtr
);
1411 if (!IsWindow(hwnd
))
1417 /* Unlink now so we won't bother with the children later on */
1419 if( wndPtr
->parent
) WIN_UnlinkWindow(hwnd
);
1421 /* Destroy the window storage */
1423 WIN_ReleaseWndPtr(WIN_DestroyWindow( wndPtr
));
1426 WIN_ReleaseWndPtr(wndPtr
);
1431 /***********************************************************************
1432 * CloseWindow16 (USER.43)
1434 BOOL16 WINAPI
CloseWindow16( HWND16 hwnd
)
1436 return CloseWindow( hwnd
);
1440 /***********************************************************************
1441 * CloseWindow32 (USER32.56)
1443 BOOL WINAPI
CloseWindow( HWND hwnd
)
1445 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1448 if (!wndPtr
|| (wndPtr
->dwStyle
& WS_CHILD
))
1453 ShowWindow( hwnd
, SW_MINIMIZE
);
1456 WIN_ReleaseWndPtr(wndPtr
);
1462 /***********************************************************************
1463 * OpenIcon16 (USER.44)
1465 BOOL16 WINAPI
OpenIcon16( HWND16 hwnd
)
1467 return OpenIcon( hwnd
);
1471 /***********************************************************************
1472 * OpenIcon32 (USER32.410)
1474 BOOL WINAPI
OpenIcon( HWND hwnd
)
1476 if (!IsIconic( hwnd
)) return FALSE
;
1477 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1482 /***********************************************************************
1485 * Implementation of FindWindow() and FindWindowEx().
1487 static HWND
WIN_FindWindow( HWND parent
, HWND child
, ATOM className
,
1495 if (!(pWnd
= WIN_FindWndPtr( child
))) return 0;
1498 if (!pWnd
->parent
|| (pWnd
->parent
->hwndSelf
!= parent
))
1504 else if (pWnd
->parent
!= pWndDesktop
)
1509 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
1513 if (!(pWnd
= parent
? WIN_FindWndPtr(parent
) : WIN_LockWndPtr(pWndDesktop
)))
1518 WIN_UpdateWndPtr(&pWnd
,pWnd
->child
);
1526 for ( ; pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
1528 if (className
&& (pWnd
->class->atomName
!= className
))
1529 continue; /* Not the right class */
1531 /* Now check the title */
1535 retvalue
= pWnd
->hwndSelf
;
1538 if (pWnd
->text
&& !strcmp( pWnd
->text
, title
))
1540 retvalue
= pWnd
->hwndSelf
;
1546 WIN_ReleaseWndPtr(pWnd
);
1552 /***********************************************************************
1553 * FindWindow16 (USER.50)
1555 HWND16 WINAPI
FindWindow16( LPCSTR className
, LPCSTR title
)
1557 return FindWindowA( className
, title
);
1561 /***********************************************************************
1562 * FindWindowEx16 (USER.427)
1564 HWND16 WINAPI
FindWindowEx16( HWND16 parent
, HWND16 child
, LPCSTR className
, LPCSTR title
)
1566 return FindWindowExA( parent
, child
, className
, title
);
1570 /***********************************************************************
1571 * FindWindow32A (USER32.198)
1573 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
1575 HWND ret
= FindWindowExA( 0, 0, className
, title
);
1576 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1581 /***********************************************************************
1582 * FindWindowEx32A (USER32.199)
1584 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
,
1585 LPCSTR className
, LPCSTR title
)
1591 /* If the atom doesn't exist, then no class */
1592 /* with this name exists either. */
1593 if (!(atom
= GlobalFindAtomA( className
)))
1595 SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1599 return WIN_FindWindow( parent
, child
, atom
, title
);
1603 /***********************************************************************
1604 * FindWindowEx32W (USER32.200)
1606 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
,
1607 LPCWSTR className
, LPCWSTR title
)
1615 /* If the atom doesn't exist, then no class */
1616 /* with this name exists either. */
1617 if (!(atom
= GlobalFindAtomW( className
)))
1619 SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1623 buffer
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
1624 hwnd
= WIN_FindWindow( parent
, child
, atom
, buffer
);
1625 HeapFree( GetProcessHeap(), 0, buffer
);
1630 /***********************************************************************
1631 * FindWindow32W (USER32.201)
1633 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
1635 return FindWindowExW( 0, 0, className
, title
);
1639 /**********************************************************************
1641 * returns a locked pointer
1643 WND
*WIN_GetDesktop(void)
1645 return WIN_LockWndPtr(pWndDesktop
);
1647 /**********************************************************************
1648 * WIN_ReleaseDesktop
1649 * unlock the desktop pointer
1651 void WIN_ReleaseDesktop(void)
1653 WIN_ReleaseWndPtr(pWndDesktop
);
1657 /**********************************************************************
1658 * GetDesktopWindow16 (USER.286)
1660 HWND16 WINAPI
GetDesktopWindow16(void)
1662 return (HWND16
)pWndDesktop
->hwndSelf
;
1666 /**********************************************************************
1667 * GetDesktopWindow32 (USER32.232)
1669 HWND WINAPI
GetDesktopWindow(void)
1671 if (pWndDesktop
) return pWndDesktop
->hwndSelf
;
1672 ERR( "You need the -desktop option when running with native USER\n" );
1678 /**********************************************************************
1679 * GetDesktopHwnd (USER.278)
1681 * Exactly the same thing as GetDesktopWindow(), but not documented.
1682 * Don't ask me why...
1684 HWND16 WINAPI
GetDesktopHwnd16(void)
1686 return (HWND16
)pWndDesktop
->hwndSelf
;
1690 /*******************************************************************
1691 * EnableWindow16 (USER.34)
1693 BOOL16 WINAPI
EnableWindow16( HWND16 hwnd
, BOOL16 enable
)
1695 return EnableWindow( hwnd
, enable
);
1699 /*******************************************************************
1700 * EnableWindow32 (USER32.172)
1702 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
1707 TRACE("EnableWindow32: ( %x, %d )\n", hwnd
, enable
);
1709 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
1710 if (enable
&& (wndPtr
->dwStyle
& WS_DISABLED
))
1713 wndPtr
->dwStyle
&= ~WS_DISABLED
;
1715 if( wndPtr
->flags
& WIN_NATIVE
)
1716 wndPtr
->pDriver
->pSetHostAttr( wndPtr
, HAK_ACCEPTFOCUS
, TRUE
);
1718 SendMessageA( hwnd
, WM_ENABLE
, TRUE
, 0 );
1722 else if (!enable
&& !(wndPtr
->dwStyle
& WS_DISABLED
))
1724 SendMessageA( wndPtr
->hwndSelf
, WM_CANCELMODE
, 0, 0);
1726 /* Disable window */
1727 wndPtr
->dwStyle
|= WS_DISABLED
;
1729 if( wndPtr
->flags
& WIN_NATIVE
)
1730 wndPtr
->pDriver
->pSetHostAttr( wndPtr
, HAK_ACCEPTFOCUS
, FALSE
);
1732 if (hwnd
== GetFocus())
1734 SetFocus( 0 ); /* A disabled window can't have the focus */
1736 if (hwnd
== GetCapture())
1738 ReleaseCapture(); /* A disabled window can't capture the mouse */
1740 SendMessageA( hwnd
, WM_ENABLE
, FALSE
, 0 );
1744 retvalue
= ((wndPtr
->dwStyle
& WS_DISABLED
) != 0);
1746 WIN_ReleaseWndPtr(wndPtr
);
1751 /***********************************************************************
1752 * IsWindowEnabled16 (USER.35)
1754 BOOL16 WINAPI
IsWindowEnabled16(HWND16 hWnd
)
1756 return IsWindowEnabled(hWnd
);
1760 /***********************************************************************
1761 * IsWindowEnabled32 (USER32.349)
1763 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
1768 if (!(wndPtr
= WIN_FindWndPtr(hWnd
))) return FALSE
;
1769 retvalue
= !(wndPtr
->dwStyle
& WS_DISABLED
);
1770 WIN_ReleaseWndPtr(wndPtr
);
1776 /***********************************************************************
1777 * IsWindowUnicode (USER32.350)
1779 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
1784 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return FALSE
;
1785 retvalue
= (WINPROC_GetProcType( wndPtr
->winproc
) == WIN_PROC_32W
);
1786 WIN_ReleaseWndPtr(wndPtr
);
1791 /**********************************************************************
1792 * GetWindowWord16 (USER.133)
1794 WORD WINAPI
GetWindowWord16( HWND16 hwnd
, INT16 offset
)
1796 return GetWindowWord( hwnd
, offset
);
1800 /**********************************************************************
1801 * GetWindowWord32 (USER32.314)
1803 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
1806 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1807 if (!wndPtr
) return 0;
1810 if (offset
+ sizeof(WORD
) > wndPtr
->class->cbWndExtra
)
1812 WARN("Invalid offset %d\n", offset
);
1816 retvalue
= *(WORD
*)(((char *)wndPtr
->wExtra
) + offset
);
1822 if (HIWORD(wndPtr
->wIDmenu
))
1823 WARN("GWW_ID: discards high bits of 0x%08x!\n",
1825 retvalue
= (WORD
)wndPtr
->wIDmenu
;
1827 case GWW_HWNDPARENT
:
1828 retvalue
= GetParent(hwnd
);
1831 if (HIWORD(wndPtr
->hInstance
))
1832 WARN("GWW_HINSTANCE: discards high bits of 0x%08x!\n",
1834 retvalue
= (WORD
)wndPtr
->hInstance
;
1837 WARN("Invalid offset %d\n", offset
);
1842 WIN_ReleaseWndPtr(wndPtr
);
1846 /**********************************************************************
1847 * SetWindowWord16 (USER.134)
1849 WORD WINAPI
SetWindowWord16( HWND16 hwnd
, INT16 offset
, WORD newval
)
1851 return SetWindowWord( hwnd
, offset
, newval
);
1855 /**********************************************************************
1856 * SetWindowWord32 (USER32.524)
1858 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
1861 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1862 if (!wndPtr
) return 0;
1865 if (offset
+ sizeof(WORD
) > wndPtr
->class->cbWndExtra
)
1867 WARN("Invalid offset %d\n", offset
);
1871 ptr
= (WORD
*)(((char *)wndPtr
->wExtra
) + offset
);
1875 case GWW_ID
: ptr
= (WORD
*)&wndPtr
->wIDmenu
; break;
1876 case GWW_HINSTANCE
: ptr
= (WORD
*)&wndPtr
->hInstance
; break;
1877 case GWW_HWNDPARENT
: retval
= SetParent( hwnd
, newval
);
1880 WARN("Invalid offset %d\n", offset
);
1887 WIN_ReleaseWndPtr(wndPtr
);
1892 /**********************************************************************
1895 * Helper function for GetWindowLong().
1897 static LONG
WIN_GetWindowLong( HWND hwnd
, INT offset
, WINDOWPROCTYPE type
)
1900 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1901 if (!wndPtr
) return 0;
1904 if (offset
+ sizeof(LONG
) > wndPtr
->class->cbWndExtra
)
1906 WARN("Invalid offset %d\n", offset
);
1910 retvalue
= *(LONG
*)(((char *)wndPtr
->wExtra
) + offset
);
1911 /* Special case for dialog window procedure */
1912 if ((offset
== DWL_DLGPROC
) && (wndPtr
->flags
& WIN_ISDIALOG
))
1914 retvalue
= (LONG
)WINPROC_GetProc( (HWINDOWPROC
)retvalue
, type
);
1921 case GWL_USERDATA
: retvalue
= wndPtr
->userdata
;
1923 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
;
1925 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
;
1927 case GWL_ID
: retvalue
= (LONG
)wndPtr
->wIDmenu
;
1929 case GWL_WNDPROC
: retvalue
= (LONG
)WINPROC_GetProc( wndPtr
->winproc
,
1932 case GWL_HWNDPARENT
: retvalue
= GetParent(hwnd
);
1934 case GWL_HINSTANCE
: retvalue
= wndPtr
->hInstance
;
1937 WARN("Unknown offset %d\n", offset
);
1941 WIN_ReleaseWndPtr(wndPtr
);
1946 /**********************************************************************
1949 * Helper function for SetWindowLong().
1951 * 0 is the failure code. However, in the case of failure SetLastError
1952 * must be set to distinguish between a 0 return value and a failure.
1954 * FIXME: The error values for SetLastError may not be right. Can
1955 * someone check with the real thing?
1957 static LONG
WIN_SetWindowLong( HWND hwnd
, INT offset
, LONG newval
,
1958 WINDOWPROCTYPE type
)
1961 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1964 TRACE("%x=%p %x %lx %x\n",hwnd
, wndPtr
, offset
, newval
, type
);
1968 /* Is this the right error? */
1969 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1975 if (offset
+ sizeof(LONG
) > wndPtr
->class->cbWndExtra
)
1977 WARN("Invalid offset %d\n", offset
);
1979 /* Is this the right error? */
1980 SetLastError( ERROR_OUTOFMEMORY
);
1985 ptr
= (LONG
*)(((char *)wndPtr
->wExtra
) + offset
);
1986 /* Special case for dialog window procedure */
1987 if ((offset
== DWL_DLGPROC
) && (wndPtr
->flags
& WIN_ISDIALOG
))
1989 retval
= (LONG
)WINPROC_GetProc( (HWINDOWPROC
)*ptr
, type
);
1990 WINPROC_SetProc( (HWINDOWPROC
*)ptr
, (WNDPROC16
)newval
,
1991 type
, WIN_PROC_WINDOW
);
1998 ptr
= (DWORD
*)&wndPtr
->wIDmenu
;
2001 retval
= SetWindowWord( hwnd
, offset
, newval
);
2004 retval
= (LONG
)WINPROC_GetProc( wndPtr
->winproc
, type
);
2005 WINPROC_SetProc( &wndPtr
->winproc
, (WNDPROC16
)newval
,
2006 type
, WIN_PROC_WINDOW
);
2009 style
.styleOld
= wndPtr
->dwStyle
;
2010 newval
&= ~(WS_VISIBLE
| WS_CHILD
); /* Some bits can't be changed this way */
2011 style
.styleNew
= newval
| (style
.styleOld
& (WS_VISIBLE
| WS_CHILD
));
2013 if (wndPtr
->flags
& WIN_ISWIN32
)
2014 SendMessageA(hwnd
,WM_STYLECHANGING
,GWL_STYLE
,(LPARAM
)&style
);
2015 wndPtr
->dwStyle
= style
.styleNew
;
2016 if (wndPtr
->flags
& WIN_ISWIN32
)
2017 SendMessageA(hwnd
,WM_STYLECHANGED
,GWL_STYLE
,(LPARAM
)&style
);
2018 retval
= style
.styleOld
;
2022 ptr
= &wndPtr
->userdata
;
2025 style
.styleOld
= wndPtr
->dwExStyle
;
2026 style
.styleNew
= newval
;
2027 if (wndPtr
->flags
& WIN_ISWIN32
)
2028 SendMessageA(hwnd
,WM_STYLECHANGING
,GWL_EXSTYLE
,(LPARAM
)&style
);
2029 wndPtr
->dwExStyle
= newval
;
2030 if (wndPtr
->flags
& WIN_ISWIN32
)
2031 SendMessageA(hwnd
,WM_STYLECHANGED
,GWL_EXSTYLE
,(LPARAM
)&style
);
2032 retval
= style
.styleOld
;
2036 WARN("Invalid offset %d\n", offset
);
2038 /* Don't think this is right error but it should do */
2039 SetLastError( ERROR_OUTOFMEMORY
);
2047 WIN_ReleaseWndPtr(wndPtr
);
2052 /**********************************************************************
2053 * GetWindowLong16 (USER.135)
2055 LONG WINAPI
GetWindowLong16( HWND16 hwnd
, INT16 offset
)
2057 return WIN_GetWindowLong( (HWND
)hwnd
, offset
, WIN_PROC_16
);
2061 /**********************************************************************
2062 * GetWindowLong32A (USER32.305)
2064 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2066 return WIN_GetWindowLong( hwnd
, offset
, WIN_PROC_32A
);
2070 /**********************************************************************
2071 * GetWindowLong32W (USER32.306)
2073 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2075 return WIN_GetWindowLong( hwnd
, offset
, WIN_PROC_32W
);
2079 /**********************************************************************
2080 * SetWindowLong16 (USER.136)
2082 LONG WINAPI
SetWindowLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
2084 return WIN_SetWindowLong( hwnd
, offset
, newval
, WIN_PROC_16
);
2088 /**********************************************************************
2089 * SetWindowLong32A (USER32.517)
2091 LONG WINAPI
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2093 return WIN_SetWindowLong( hwnd
, offset
, newval
, WIN_PROC_32A
);
2097 /**********************************************************************
2098 * SetWindowLong32W (USER32.518) Set window attribute
2100 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2101 * value in a window's extra memory.
2103 * The _hwnd_ parameter specifies the window. is the handle to a
2104 * window that has extra memory. The _newval_ parameter contains the
2105 * new attribute or extra memory value. If positive, the _offset_
2106 * parameter is the byte-addressed location in the window's extra
2107 * memory to set. If negative, _offset_ specifies the window
2108 * attribute to set, and should be one of the following values:
2110 * GWL_EXSTYLE The window's extended window style
2112 * GWL_STYLE The window's window style.
2114 * GWL_WNDPROC Pointer to the window's window procedure.
2116 * GWL_HINSTANCE The window's pplication instance handle.
2118 * GWL_ID The window's identifier.
2120 * GWL_USERDATA The window's user-specified data.
2122 * If the window is a dialog box, the _offset_ parameter can be one of
2123 * the following values:
2125 * DWL_DLGPROC The address of the window's dialog box procedure.
2127 * DWL_MSGRESULT The return value of a message
2128 * that the dialog box procedure processed.
2130 * DWL_USER Application specific information.
2134 * If successful, returns the previous value located at _offset_. Otherwise,
2139 * Extra memory for a window class is specified by a nonzero cbWndExtra
2140 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2141 * time of class creation.
2143 * Using GWL_WNDPROC to set a new window procedure effectively creates
2144 * a window subclass. Use CallWindowProc() in the new windows procedure
2145 * to pass messages to the superclass's window procedure.
2147 * The user data is reserved for use by the application which created
2150 * Do not use GWL_STYLE to change the window's WS_DISABLE style;
2151 * instead, call the EnableWindow() function to change the window's
2154 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2155 * SetParent() instead.
2158 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2159 * it sends WM_STYLECHANGING before changing the settings
2160 * and WM_STYLECHANGED afterwards.
2161 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2165 * GWL_STYLE does not dispatch WM_STYLE... messages.
2172 LONG WINAPI
SetWindowLongW(
2173 HWND hwnd
, /* window to alter */
2174 INT offset
, /* offset, in bytes, of location to alter */
2175 LONG newval
/* new value of location */
2177 return WIN_SetWindowLong( hwnd
, offset
, newval
, WIN_PROC_32W
);
2181 /*******************************************************************
2182 * GetWindowText16 (USER.36)
2184 INT16 WINAPI
GetWindowText16( HWND16 hwnd
, SEGPTR lpString
, INT16 nMaxCount
)
2186 return (INT16
)SendMessage16(hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2190 /*******************************************************************
2191 * GetWindowText32A (USER32.309)
2193 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2195 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
,
2199 /*******************************************************************
2200 * InternalGetWindowText (USER32.326)
2202 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2204 FIXME("(0x%08x,%p,0x%x),stub!\n",hwnd
,lpString
,nMaxCount
);
2205 return GetWindowTextW(hwnd
,lpString
,nMaxCount
);
2209 /*******************************************************************
2210 * GetWindowText32W (USER32.312)
2212 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2214 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
,
2219 /*******************************************************************
2220 * SetWindowText16 (USER.37)
2222 BOOL16 WINAPI
SetWindowText16( HWND16 hwnd
, SEGPTR lpString
)
2224 return (BOOL16
)SendMessage16( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2228 /*******************************************************************
2229 * SetWindowText32A (USER32.521)
2231 BOOL WINAPI
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2233 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2237 /*******************************************************************
2238 * SetWindowText32W (USER32.523)
2240 BOOL WINAPI
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2242 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2246 /*******************************************************************
2247 * GetWindowTextLength16 (USER.38)
2249 INT16 WINAPI
GetWindowTextLength16( HWND16 hwnd
)
2251 return (INT16
)SendMessage16( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2255 /*******************************************************************
2256 * GetWindowTextLength32A (USER32.310)
2258 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2260 return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2263 /*******************************************************************
2264 * GetWindowTextLength32W (USER32.311)
2266 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2268 return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2272 /*******************************************************************
2273 * IsWindow16 (USER.47)
2275 BOOL16 WINAPI
IsWindow16( HWND16 hwnd
)
2277 CURRENT_STACK16
->es
= USER_HeapSel
;
2278 return IsWindow( hwnd
);
2282 /*******************************************************************
2283 * IsWindow32 (USER32.348)
2285 BOOL WINAPI
IsWindow( HWND hwnd
)
2290 if(!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
2291 retvalue
= (wndPtr
->dwMagic
== WND_MAGIC
);
2292 WIN_ReleaseWndPtr(wndPtr
);
2298 /*****************************************************************
2299 * GetParent16 (USER.46)
2301 HWND16 WINAPI
GetParent16( HWND16 hwnd
)
2303 return (HWND16
)GetParent( hwnd
);
2307 /*****************************************************************
2308 * GetParent32 (USER32.278)
2310 HWND WINAPI
GetParent( HWND hwnd
)
2315 if(!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
2316 if ((!(wndPtr
->dwStyle
& (WS_POPUP
|WS_CHILD
))))
2319 WIN_UpdateWndPtr(&wndPtr
,((wndPtr
->dwStyle
& WS_CHILD
) ? wndPtr
->parent
: wndPtr
->owner
));
2321 retvalue
= wndPtr
->hwndSelf
;
2324 WIN_ReleaseWndPtr(wndPtr
);
2329 /*****************************************************************
2332 * Get the top-level parent for a child window.
2333 * returns a locked pointer
2335 WND
* WIN_GetTopParentPtr( WND
* pWnd
)
2337 WND
*tmpWnd
= WIN_LockWndPtr(pWnd
);
2339 while( tmpWnd
&& (tmpWnd
->dwStyle
& WS_CHILD
))
2341 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
2346 /*****************************************************************
2349 * Get the top-level parent for a child window.
2351 HWND
WIN_GetTopParent( HWND hwnd
)
2354 WND
*tmpPtr
= WIN_FindWndPtr(hwnd
);
2355 WND
*wndPtr
= WIN_GetTopParentPtr (tmpPtr
);
2357 retvalue
= wndPtr
? wndPtr
->hwndSelf
: 0;
2358 WIN_ReleaseWndPtr(tmpPtr
);
2359 WIN_ReleaseWndPtr(wndPtr
);
2364 /*****************************************************************
2365 * SetParent16 (USER.233)
2367 HWND16 WINAPI
SetParent16( HWND16 hwndChild
, HWND16 hwndNewParent
)
2369 return SetParent( hwndChild
, hwndNewParent
);
2373 /*****************************************************************
2374 * SetParent32 (USER32.495)
2376 HWND WINAPI
SetParent( HWND hwndChild
, HWND hwndNewParent
)
2385 if(!(wndPtr
= WIN_FindWndPtr(hwndChild
))) return 0;
2387 dwStyle
= wndPtr
->dwStyle
;
2389 pWndNewParent
= hwndNewParent
? WIN_FindWndPtr(hwndNewParent
)
2390 : WIN_LockWndPtr(pWndDesktop
);
2392 /* Windows hides the window first, then shows it again
2393 * including the WM_SHOWWINDOW messages and all */
2394 if (dwStyle
& WS_VISIBLE
)
2395 ShowWindow( hwndChild
, SW_HIDE
);
2397 pWndOldParent
= WIN_LockWndPtr((*wndPtr
->pDriver
->pSetParent
)(wndPtr
, pWndNewParent
));
2399 /* SetParent32 additionally needs to make hwndChild the topmost window
2400 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2401 WM_WINDOWPOSCHANGED notification messages.
2403 SetWindowPos( hwndChild
, HWND_TOPMOST
, 0, 0, 0, 0,
2404 SWP_NOMOVE
|SWP_NOSIZE
|((dwStyle
& WS_VISIBLE
)?SWP_SHOWWINDOW
:0));
2405 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2406 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2408 retvalue
= pWndOldParent
?pWndOldParent
->hwndSelf
:0;
2410 WIN_ReleaseWndPtr(pWndOldParent
);
2411 WIN_ReleaseWndPtr(pWndNewParent
);
2412 WIN_ReleaseWndPtr(wndPtr
);
2418 /*******************************************************************
2419 * IsChild16 (USER.48)
2421 BOOL16 WINAPI
IsChild16( HWND16 parent
, HWND16 child
)
2423 return IsChild(parent
,child
);
2427 /*******************************************************************
2428 * IsChild32 (USER32.339)
2430 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
2432 WND
* wndPtr
= WIN_FindWndPtr( child
);
2433 while (wndPtr
&& (wndPtr
->dwStyle
& WS_CHILD
))
2435 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
2436 if (wndPtr
->hwndSelf
== parent
)
2438 WIN_ReleaseWndPtr(wndPtr
);
2442 WIN_ReleaseWndPtr(wndPtr
);
2447 /***********************************************************************
2448 * IsWindowVisible16 (USER.49)
2450 BOOL16 WINAPI
IsWindowVisible16( HWND16 hwnd
)
2452 return IsWindowVisible(hwnd
);
2456 /***********************************************************************
2457 * IsWindowVisible32 (USER32.351)
2459 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
2462 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
2463 while (wndPtr
&& (wndPtr
->dwStyle
& WS_CHILD
))
2465 if (!(wndPtr
->dwStyle
& WS_VISIBLE
))
2467 WIN_ReleaseWndPtr(wndPtr
);
2470 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
2472 retval
= (wndPtr
&& (wndPtr
->dwStyle
& WS_VISIBLE
));
2473 WIN_ReleaseWndPtr(wndPtr
);
2479 /***********************************************************************
2480 * WIN_IsWindowDrawable
2482 * hwnd is drawable when it is visible, all parents are not
2483 * minimized, and it is itself not minimized unless we are
2484 * trying to draw its default class icon.
2486 BOOL
WIN_IsWindowDrawable( WND
* wnd
, BOOL icon
)
2488 if( (wnd
->dwStyle
& WS_MINIMIZE
&&
2489 icon
&& wnd
->class->hIcon
) ||
2490 !(wnd
->dwStyle
& WS_VISIBLE
) ) return FALSE
;
2491 for(wnd
= wnd
->parent
; wnd
; wnd
= wnd
->parent
)
2492 if( wnd
->dwStyle
& WS_MINIMIZE
||
2493 !(wnd
->dwStyle
& WS_VISIBLE
) ) break;
2494 return (wnd
== NULL
);
2498 /*******************************************************************
2499 * GetTopWindow16 (USER.229)
2501 HWND16 WINAPI
GetTopWindow16( HWND16 hwnd
)
2503 return GetTopWindow(hwnd
);
2507 /*******************************************************************
2508 * GetTopWindow32 (USER.229)
2510 HWND WINAPI
GetTopWindow( HWND hwnd
)
2513 WND
* wndPtr
= (hwnd
) ?
2514 WIN_FindWndPtr( hwnd
) : WIN_GetDesktop();
2516 if (wndPtr
&& wndPtr
->child
)
2517 retval
= wndPtr
->child
->hwndSelf
;
2519 WIN_ReleaseWndPtr(wndPtr
);
2524 /*******************************************************************
2525 * GetWindow16 (USER.262)
2527 HWND16 WINAPI
GetWindow16( HWND16 hwnd
, WORD rel
)
2529 return GetWindow( hwnd
,rel
);
2533 /*******************************************************************
2534 * GetWindow32 (USER32.302)
2536 HWND WINAPI
GetWindow( HWND hwnd
, WORD rel
)
2540 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
2541 if (!wndPtr
) return 0;
2545 retval
= wndPtr
->parent
? wndPtr
->parent
->child
->hwndSelf
: 0;
2549 if (!wndPtr
->parent
)
2551 retval
= 0; /* Desktop window */
2554 while (wndPtr
->next
)
2556 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
);
2558 retval
= wndPtr
->hwndSelf
;
2562 retval
= wndPtr
->next
? wndPtr
->next
->hwndSelf
: 0;
2566 if (!wndPtr
->parent
)
2568 retval
= 0; /* Desktop window */
2571 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
->child
); /* First sibling */
2572 if (wndPtr
->hwndSelf
== hwnd
)
2574 retval
= 0; /* First in list */
2577 while (wndPtr
->next
)
2579 if (wndPtr
->next
->hwndSelf
== hwnd
)
2581 retval
= wndPtr
->hwndSelf
;
2584 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
);
2590 retval
= wndPtr
->owner
? wndPtr
->owner
->hwndSelf
: 0;
2594 retval
= wndPtr
->child
? wndPtr
->child
->hwndSelf
: 0;
2599 WIN_ReleaseWndPtr(wndPtr
);
2604 /*******************************************************************
2605 * GetNextWindow16 (USER.230)
2607 HWND16 WINAPI
GetNextWindow16( HWND16 hwnd
, WORD flag
)
2609 if ((flag
!= GW_HWNDNEXT
) && (flag
!= GW_HWNDPREV
)) return 0;
2610 return GetWindow16( hwnd
, flag
);
2613 /*******************************************************************
2614 * ShowOwnedPopups16 (USER.265)
2616 void WINAPI
ShowOwnedPopups16( HWND16 owner
, BOOL16 fShow
)
2618 ShowOwnedPopups( owner
, fShow
);
2622 /*******************************************************************
2623 * ShowOwnedPopups32 (USER32.531)
2625 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
2627 UINT totalChild
=0, count
=0;
2629 WND
**pWnd
= WIN_BuildWinArray(WIN_GetDesktop(), 0, &totalChild
);
2631 if (!pWnd
) return TRUE
;
2633 for (; count
< totalChild
; count
++)
2635 if (pWnd
[count
]->owner
&& (pWnd
[count
]->owner
->hwndSelf
== owner
) && (pWnd
[count
]->dwStyle
& WS_POPUP
))
2639 if (pWnd
[count
]->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
2641 SendMessageA(pWnd
[count
]->hwndSelf
, WM_SHOWWINDOW
, SW_SHOW
, IsIconic(owner
) ? SW_PARENTOPENING
: SW_PARENTCLOSING
);
2642 pWnd
[count
]->flags
&= ~WIN_NEEDS_SHOW_OWNEDPOPUP
;
2647 if (IsWindowVisible(pWnd
[count
]->hwndSelf
))
2649 SendMessageA(pWnd
[count
]->hwndSelf
, WM_SHOWWINDOW
, SW_HIDE
, IsIconic(owner
) ? SW_PARENTOPENING
: SW_PARENTCLOSING
);
2650 pWnd
[count
]->flags
|= WIN_NEEDS_SHOW_OWNEDPOPUP
;
2656 WIN_ReleaseDesktop();
2657 WIN_ReleaseWinArray(pWnd
);
2662 /*******************************************************************
2663 * GetLastActivePopup16 (USER.287)
2665 HWND16 WINAPI
GetLastActivePopup16( HWND16 hwnd
)
2667 return GetLastActivePopup( hwnd
);
2670 /*******************************************************************
2671 * GetLastActivePopup32 (USER32.256)
2673 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
2676 WND
*wndPtr
=WIN_FindWndPtr(hwnd
);
2677 if (!wndPtr
) return hwnd
;
2678 retval
= wndPtr
->hwndLastActive
;
2679 WIN_ReleaseWndPtr(wndPtr
);
2684 /*******************************************************************
2687 * Build an array of pointers to the children of a given window.
2688 * The array must be freed with WIN_ReleaseWinArray. Return NULL
2689 * when no windows are found.
2691 WND
**WIN_BuildWinArray( WND
*wndPtr
, UINT bwaFlags
, UINT
* pTotal
)
2693 /* Future: this function will lock all windows associated with this array */
2695 WND
**list
, **ppWnd
;
2697 UINT count
= 0, skipOwned
, skipHidden
;
2700 skipHidden
= bwaFlags
& BWA_SKIPHIDDEN
;
2701 skipOwned
= bwaFlags
& BWA_SKIPOWNED
;
2702 skipFlags
= (bwaFlags
& BWA_SKIPDISABLED
) ? WS_DISABLED
: 0;
2703 if( bwaFlags
& BWA_SKIPICONIC
) skipFlags
|= WS_MINIMIZE
;
2705 /* First count the windows */
2708 wndPtr
= WIN_GetDesktop();
2710 pWnd
= WIN_LockWndPtr(wndPtr
->child
);
2713 if( !(pWnd
->dwStyle
& skipFlags
) && !(skipOwned
&& pWnd
->owner
) &&
2714 (!skipHidden
|| (pWnd
->dwStyle
& WS_VISIBLE
)) )
2716 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
2721 /* Now build the list of all windows */
2723 if ((list
= (WND
**)HeapAlloc( GetProcessHeap(), 0, sizeof(WND
*) * (count
+ 1))))
2725 for (pWnd
= WIN_LockWndPtr(wndPtr
->child
), ppWnd
= list
, count
= 0; pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
2727 if( (pWnd
->dwStyle
& skipFlags
) || (skipOwned
&& pWnd
->owner
) );
2728 else if( !skipHidden
|| pWnd
->dwStyle
& WS_VISIBLE
)
2734 WIN_ReleaseWndPtr(pWnd
);
2740 if( pTotal
) *pTotal
= count
;
2743 /*******************************************************************
2744 * WIN_ReleaseWinArray
2746 void WIN_ReleaseWinArray(WND
**wndArray
)
2748 /* Future: this function will also unlock all windows associated with wndArray */
2749 HeapFree( GetProcessHeap(), 0, wndArray
);
2753 /*******************************************************************
2754 * EnumWindows (USER32.193)
2756 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
2758 WND
**list
, **ppWnd
;
2760 /* We have to build a list of all windows first, to avoid */
2761 /* unpleasant side-effects, for instance if the callback */
2762 /* function changes the Z-order of the windows. */
2764 if (!(list
= WIN_BuildWinArray(WIN_GetDesktop(), 0, NULL
)))
2766 WIN_ReleaseDesktop();
2770 /* Now call the callback function for every window */
2772 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
2774 LRESULT lpEnumFuncRetval
;
2776 /* Make sure that the window still exists */
2777 if (!IsWindow((*ppWnd
)->hwndSelf
)) continue;
2779 /* To avoid any deadlocks, all the locks on the windows
2780 structures must be suspended before the control
2781 is passed to the application */
2782 iWndsLocks
= WIN_SuspendWndsLock();
2783 lpEnumFuncRetval
= lpEnumFunc( (*ppWnd
)->hwndSelf
, lParam
);
2784 WIN_RestoreWndsLock(iWndsLocks
);
2786 if (!lpEnumFuncRetval
) break;
2788 WIN_ReleaseWinArray(list
);
2789 WIN_ReleaseDesktop();
2794 /**********************************************************************
2795 * EnumTaskWindows16 (USER.225)
2797 BOOL16 WINAPI
EnumTaskWindows16( HTASK16 hTask
, WNDENUMPROC16 func
,
2800 WND
**list
, **ppWnd
;
2802 /* This function is the same as EnumWindows(), */
2803 /* except for an added check on the window's task. */
2805 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
2807 WIN_ReleaseDesktop();
2811 /* Now call the callback function for every window */
2813 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
2817 /* Make sure that the window still exists */
2818 if (!IsWindow((*ppWnd
)->hwndSelf
)) continue;
2819 if (QUEUE_GetQueueTask((*ppWnd
)->hmemTaskQ
) != hTask
) continue;
2821 /* To avoid any deadlocks, all the locks on the windows
2822 structures must be suspended before the control
2823 is passed to the application */
2824 iWndsLocks
= WIN_SuspendWndsLock();
2825 funcRetval
= func( (*ppWnd
)->hwndSelf
, lParam
);
2826 WIN_RestoreWndsLock(iWndsLocks
);
2828 if (!funcRetval
) break;
2830 WIN_ReleaseWinArray(list
);
2831 WIN_ReleaseDesktop();
2836 /**********************************************************************
2837 * EnumThreadWindows (USER32.190)
2839 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
2841 TEB
*teb
= THREAD_IdToTEB(id
);
2843 return (BOOL16
)EnumTaskWindows16(teb
->htask16
, (WNDENUMPROC16
)func
, lParam
);
2847 /**********************************************************************
2848 * WIN_EnumChildWindows
2850 * Helper function for EnumChildWindows().
2852 static BOOL16
WIN_EnumChildWindows( WND
**ppWnd
, WNDENUMPROC func
, LPARAM lParam
)
2857 for ( ; *ppWnd
; ppWnd
++)
2861 /* Make sure that the window still exists */
2862 if (!IsWindow((*ppWnd
)->hwndSelf
)) continue;
2863 /* Build children list first */
2864 childList
= WIN_BuildWinArray( *ppWnd
, BWA_SKIPOWNED
, NULL
);
2866 /* To avoid any deadlocks, all the locks on the windows
2867 structures must be suspended before the control
2868 is passed to the application */
2869 iWndsLocks
= WIN_SuspendWndsLock();
2870 ret
= func( (*ppWnd
)->hwndSelf
, lParam
);
2871 WIN_RestoreWndsLock(iWndsLocks
);
2875 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
2876 WIN_ReleaseWinArray(childList
);
2878 if (!ret
) return FALSE
;
2884 /**********************************************************************
2885 * EnumChildWindows (USER32.178)
2887 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
,
2890 WND
**list
, *pParent
;
2892 if (!(pParent
= WIN_FindWndPtr( parent
))) return FALSE
;
2893 if (!(list
= WIN_BuildWinArray( pParent
, BWA_SKIPOWNED
, NULL
)))
2895 WIN_ReleaseWndPtr(pParent
);
2898 WIN_EnumChildWindows( list
, func
, lParam
);
2899 WIN_ReleaseWinArray(list
);
2900 WIN_ReleaseWndPtr(pParent
);
2905 /*******************************************************************
2906 * AnyPopup16 (USER.52)
2908 BOOL16 WINAPI
AnyPopup16(void)
2914 /*******************************************************************
2915 * AnyPopup32 (USER32.4)
2917 BOOL WINAPI
AnyPopup(void)
2919 WND
*wndPtr
= WIN_LockWndPtr(pWndDesktop
->child
);
2924 if (wndPtr
->owner
&& (wndPtr
->dwStyle
& WS_VISIBLE
))
2929 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
);
2933 WIN_ReleaseWndPtr(wndPtr
);
2938 /*******************************************************************
2939 * FlashWindow16 (USER.105)
2941 BOOL16 WINAPI
FlashWindow16( HWND16 hWnd
, BOOL16 bInvert
)
2943 return FlashWindow( hWnd
, bInvert
);
2947 /*******************************************************************
2948 * FlashWindow32 (USER32.202)
2950 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
2952 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
2954 TRACE("%04x\n", hWnd
);
2956 if (!wndPtr
) return FALSE
;
2958 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
2960 if (bInvert
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
2962 HDC hDC
= GetDC(hWnd
);
2964 if (!SendMessage16( hWnd
, WM_ERASEBKGND
, (WPARAM16
)hDC
, 0 ))
2965 wndPtr
->flags
|= WIN_NEEDS_ERASEBKGND
;
2967 ReleaseDC( hWnd
, hDC
);
2968 wndPtr
->flags
|= WIN_NCACTIVATED
;
2972 PAINT_RedrawWindow( hWnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
|
2973 RDW_UPDATENOW
| RDW_FRAME
, 0 );
2974 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
2976 WIN_ReleaseWndPtr(wndPtr
);
2982 if (bInvert
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
2983 else wparam
= (hWnd
== GetActiveWindow());
2985 SendMessage16( hWnd
, WM_NCACTIVATE
, wparam
, (LPARAM
)0 );
2986 WIN_ReleaseWndPtr(wndPtr
);
2992 /*******************************************************************
2993 * SetSysModalWindow16 (USER.188)
2995 HWND16 WINAPI
SetSysModalWindow16( HWND16 hWnd
)
2997 HWND hWndOldModal
= hwndSysModal
;
2998 hwndSysModal
= hWnd
;
2999 FIXME("EMPTY STUB !! SetSysModalWindow(%04x) !\n", hWnd
);
3000 return hWndOldModal
;
3004 /*******************************************************************
3005 * GetSysModalWindow16 (USER.52)
3007 HWND16 WINAPI
GetSysModalWindow16(void)
3009 return hwndSysModal
;
3013 /*******************************************************************
3014 * GetWindowContextHelpId (USER32.303)
3016 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3019 WND
*wnd
= WIN_FindWndPtr( hwnd
);
3021 retval
= wnd
->helpContext
;
3022 WIN_ReleaseWndPtr(wnd
);
3027 /*******************************************************************
3028 * SetWindowContextHelpId (USER32.515)
3030 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3032 WND
*wnd
= WIN_FindWndPtr( hwnd
);
3033 if (!wnd
) return FALSE
;
3034 wnd
->helpContext
= id
;
3035 WIN_ReleaseWndPtr(wnd
);
3040 /*******************************************************************
3043 * recursively find a child that contains spDragInfo->pt point
3044 * and send WM_QUERYDROPOBJECT
3046 BOOL16
DRAG_QueryUpdate( HWND hQueryWnd
, SEGPTR spDragInfo
, BOOL bNoSend
)
3048 BOOL16 wParam
, bResult
= 0;
3050 LPDRAGINFO ptrDragInfo
= (LPDRAGINFO
) PTR_SEG_TO_LIN(spDragInfo
);
3051 WND
*ptrQueryWnd
= WIN_FindWndPtr(hQueryWnd
),*ptrWnd
;
3054 if( !ptrQueryWnd
|| !ptrDragInfo
)
3057 CONV_POINT16TO32( &ptrDragInfo
->pt
, &pt
);
3059 GetWindowRect(hQueryWnd
,&tempRect
);
3061 if( !PtInRect(&tempRect
,pt
) ||
3062 (ptrQueryWnd
->dwStyle
& WS_DISABLED
) )
3065 if( !(ptrQueryWnd
->dwStyle
& WS_MINIMIZE
) )
3067 tempRect
= ptrQueryWnd
->rectClient
;
3068 if(ptrQueryWnd
->dwStyle
& WS_CHILD
)
3069 MapWindowPoints( ptrQueryWnd
->parent
->hwndSelf
, 0,
3070 (LPPOINT
)&tempRect
, 2 );
3072 if (PtInRect( &tempRect
, pt
))
3076 for (ptrWnd
= WIN_LockWndPtr(ptrQueryWnd
->child
); ptrWnd
;WIN_UpdateWndPtr(&ptrWnd
,ptrWnd
->next
))
3078 if( ptrWnd
->dwStyle
& WS_VISIBLE
)
3080 GetWindowRect( ptrWnd
->hwndSelf
, &tempRect
);
3081 if (PtInRect( &tempRect
, pt
)) break;
3087 TRACE_(msg
)("hwnd = %04x, %d %d - %d %d\n",
3088 ptrWnd
->hwndSelf
, ptrWnd
->rectWindow
.left
, ptrWnd
->rectWindow
.top
,
3089 ptrWnd
->rectWindow
.right
, ptrWnd
->rectWindow
.bottom
);
3090 if( !(ptrWnd
->dwStyle
& WS_DISABLED
) )
3091 bResult
= DRAG_QueryUpdate(ptrWnd
->hwndSelf
, spDragInfo
, bNoSend
);
3093 WIN_ReleaseWndPtr(ptrWnd
);
3103 ScreenToClient16(hQueryWnd
,&ptrDragInfo
->pt
);
3105 ptrDragInfo
->hScope
= hQueryWnd
;
3107 bResult
= ( bNoSend
)
3108 ? ptrQueryWnd
->dwExStyle
& WS_EX_ACCEPTFILES
3109 : SendMessage16( hQueryWnd
,WM_QUERYDROPOBJECT
,
3110 (WPARAM16
)wParam
,(LPARAM
) spDragInfo
);
3112 CONV_POINT32TO16( &pt
, &ptrDragInfo
->pt
);
3115 WIN_ReleaseWndPtr(ptrQueryWnd
);
3120 /*******************************************************************
3121 * DragDetect (USER.465)
3123 BOOL16 WINAPI
DragDetect16( HWND16 hWnd
, POINT16 pt
)
3126 CONV_POINT16TO32( &pt
, &pt32
);
3127 return DragDetect( hWnd
, pt32
);
3130 /*******************************************************************
3131 * DragDetect32 (USER32.151)
3133 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3138 rect
.left
= pt
.x
- wDragWidth
;
3139 rect
.right
= pt
.x
+ wDragWidth
;
3141 rect
.top
= pt
.y
- wDragHeight
;
3142 rect
.bottom
= pt
.y
+ wDragHeight
;
3148 while(PeekMessage16(&msg
,0 ,WM_MOUSEFIRST
,WM_MOUSELAST
,PM_REMOVE
))
3150 if( msg
.message
== WM_LBUTTONUP
)
3155 if( msg
.message
== WM_MOUSEMOVE
)
3157 if( !PtInRect16( &rect
, MAKEPOINT16(msg
.lParam
) ) )
3169 /******************************************************************************
3170 * DragObject16 (USER.464)
3172 DWORD WINAPI
DragObject16( HWND16 hwndScope
, HWND16 hWnd
, UINT16 wObj
,
3173 HANDLE16 hOfStruct
, WORD szList
, HCURSOR16 hCursor
)
3176 LPDRAGINFO lpDragInfo
;
3178 HCURSOR16 hDragCursor
=0, hOldCursor
=0, hBummer
=0;
3179 HGLOBAL16 hDragInfo
= GlobalAlloc16( GMEM_SHARE
| GMEM_ZEROINIT
, 2*sizeof(DRAGINFO
));
3180 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
3181 HCURSOR16 hCurrentCursor
= 0;
3182 HWND16 hCurrentWnd
= 0;
3184 lpDragInfo
= (LPDRAGINFO
) GlobalLock16(hDragInfo
);
3185 spDragInfo
= (SEGPTR
) WIN16_GlobalLock16(hDragInfo
);
3187 if( !lpDragInfo
|| !spDragInfo
)
3189 WIN_ReleaseWndPtr(wndPtr
);
3193 hBummer
= LoadCursor16(0, IDC_BUMMER16
);
3195 if( !hBummer
|| !wndPtr
)
3197 GlobalFree16(hDragInfo
);
3198 WIN_ReleaseWndPtr(wndPtr
);
3204 if( !(hDragCursor
= CURSORICON_IconToCursor(hCursor
, FALSE
)) )
3206 GlobalFree16(hDragInfo
);
3207 WIN_ReleaseWndPtr(wndPtr
);
3211 if( hDragCursor
== hCursor
) hDragCursor
= 0;
3212 else hCursor
= hDragCursor
;
3214 hOldCursor
= SetCursor(hDragCursor
);
3217 lpDragInfo
->hWnd
= hWnd
;
3218 lpDragInfo
->hScope
= 0;
3219 lpDragInfo
->wFlags
= wObj
;
3220 lpDragInfo
->hList
= szList
; /* near pointer! */
3221 lpDragInfo
->hOfStruct
= hOfStruct
;
3229 do{ WaitMessage(); }
3230 while( !PeekMessage16(&msg
,0,WM_MOUSEFIRST
,WM_MOUSELAST
,PM_REMOVE
) );
3232 *(lpDragInfo
+1) = *lpDragInfo
;
3234 lpDragInfo
->pt
= msg
.pt
;
3236 /* update DRAGINFO struct */
3237 TRACE_(msg
)("lpDI->hScope = %04x\n",lpDragInfo
->hScope
);
3239 if( DRAG_QueryUpdate(hwndScope
, spDragInfo
, FALSE
) > 0 )
3240 hCurrentCursor
= hCursor
;
3243 hCurrentCursor
= hBummer
;
3244 lpDragInfo
->hScope
= 0;
3246 if( hCurrentCursor
)
3247 SetCursor(hCurrentCursor
);
3249 /* send WM_DRAGLOOP */
3250 SendMessage16( hWnd
, WM_DRAGLOOP
, (WPARAM16
)(hCurrentCursor
!= hBummer
),
3251 (LPARAM
) spDragInfo
);
3252 /* send WM_DRAGSELECT or WM_DRAGMOVE */
3253 if( hCurrentWnd
!= lpDragInfo
->hScope
)
3256 SendMessage16( hCurrentWnd
, WM_DRAGSELECT
, 0,
3257 (LPARAM
)MAKELONG(LOWORD(spDragInfo
)+sizeof(DRAGINFO
),
3258 HIWORD(spDragInfo
)) );
3259 hCurrentWnd
= lpDragInfo
->hScope
;
3261 SendMessage16( hCurrentWnd
, WM_DRAGSELECT
, 1, (LPARAM
)spDragInfo
);
3265 SendMessage16( hCurrentWnd
, WM_DRAGMOVE
, 0, (LPARAM
)spDragInfo
);
3267 } while( msg
.message
!= WM_LBUTTONUP
&& msg
.message
!= WM_NCLBUTTONUP
);
3270 ShowCursor( FALSE
);
3274 SetCursor( hOldCursor
);
3275 if (hDragCursor
) DestroyCursor( hDragCursor
);
3278 if( hCurrentCursor
!= hBummer
)
3279 msg
.lParam
= SendMessage16( lpDragInfo
->hScope
, WM_DROPOBJECT
,
3280 (WPARAM16
)hWnd
, (LPARAM
)spDragInfo
);
3283 GlobalFree16(hDragInfo
);
3284 WIN_ReleaseWndPtr(wndPtr
);
3286 return (DWORD
)(msg
.lParam
);