HWND* FASTCALL
IntWinListChildren(PWND Window)
{
- PWND Child;
- HWND *List;
- UINT Index, NumChildren = 0;
+ PWND Child;
+ HWND *List;
+ UINT Index, NumChildren = 0;
- if (!Window) return NULL;
+ if (!Window) return NULL;
- for (Child = Window->spwndChild; Child; Child = Child->spwndNext)
- ++NumChildren;
+ for (Child = Window->spwndChild; Child; Child = Child->spwndNext)
+ {
+ ++NumChildren;
+ }
- List = ExAllocatePoolWithTag(PagedPool, (NumChildren + 1) * sizeof(HWND), USERTAG_WINDOWLIST);
- if(!List)
- {
- ERR("Failed to allocate memory for children array\n");
- EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
- }
- for (Child = Window->spwndChild, Index = 0;
- Child != NULL;
- Child = Child->spwndNext, ++Index)
- List[Index] = Child->head.h;
- List[Index] = NULL;
+ List = ExAllocatePoolWithTag(PagedPool, (NumChildren + 1) * sizeof(HWND), USERTAG_WINDOWLIST);
+ if(!List)
+ {
+ ERR("Failed to allocate memory for children array\n");
+ EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return NULL;
+ }
+
+ Index = 0;
+ for (Child = Window->spwndChild; Child; Child = Child->spwndNext)
+ {
+ List[Index++] = Child->head.h;
+ }
+ List[Index] = NULL;
+
+ return List;
+}
+
+HWND* FASTCALL
+IntWinListOwnedPopups(PWND Window)
+{
+ PWND Child, Desktop;
+ HWND *List;
+ UINT Index, NumOwned = 0;
+
+ Desktop = co_GetDesktopWindow(Window);
+ if (!Desktop)
+ return NULL;
+
+ for (Child = Desktop->spwndChild; Child; Child = Child->spwndNext)
+ {
+ if (Child->spwndOwner == Window)
+ ++NumOwned;
+ }
+
+ List = ExAllocatePoolWithTag(PagedPool, (NumOwned + 1) * sizeof(HWND), USERTAG_WINDOWLIST);
+ if (!List)
+ {
+ ERR("Failed to allocate memory for children array\n");
+ EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return NULL;
+ }
+
+ Index = 0;
+ for (Child = Desktop->spwndChild; Child; Child = Child->spwndNext)
+ {
+ if (Child->spwndOwner == Window)
+ List[Index++] = Child->head.h;
+ }
+ List[Index] = NULL;
- return List;
+ return List;
}
PWND FASTCALL
return HelpId;
}
+
+VOID
+FASTCALL
+IntRemoveTrackMouseEvent(
+ PDESKTOP pDesk);
+
/***********************************************************************
* IntSendDestroyMsg
*/
{
co_IntDestroyCaret(ti);
}
+
+ /* If the window being destroyed is currently tracked... */
+ if (ti->rpdesk->spwndTrack == Window)
+ {
+ IntRemoveTrackMouseEvent(ti->rpdesk);
+ }
}
/* If the window being destroyed is the current clipboard owner... */
}
////
-/*
- Link the window into siblings list
- children and parent are kept in place.
-*/
+/* Link the window into siblings list. Children and parent are kept in place. */
VOID FASTCALL
IntLinkWindow(
- PWND Wnd,
- PWND WndInsertAfter /* set to NULL if top sibling */
+ PWND Wnd,
+ PWND WndInsertAfter /* Set to NULL if top sibling */
)
{
- if ((Wnd->spwndPrev = WndInsertAfter))
- {
- /* link after WndInsertAfter */
- if ((Wnd->spwndNext = WndInsertAfter->spwndNext))
- Wnd->spwndNext->spwndPrev = Wnd;
+ if (Wnd == WndInsertAfter)
+ {
+ ERR("IntLinkWindow -- Trying to link window 0x%p to itself!!\n", Wnd);
+ return;
+ }
- Wnd->spwndPrev->spwndNext = Wnd;
- }
- else
- {
- /* link at top */
- if ((Wnd->spwndNext = Wnd->spwndParent->spwndChild))
- Wnd->spwndNext->spwndPrev = Wnd;
+ Wnd->spwndPrev = WndInsertAfter;
+ if (Wnd->spwndPrev)
+ {
+ /* Link after WndInsertAfter */
+ ASSERT(Wnd != WndInsertAfter->spwndNext);
+ Wnd->spwndNext = WndInsertAfter->spwndNext;
+ if (Wnd->spwndNext)
+ Wnd->spwndNext->spwndPrev = Wnd;
+
+ ASSERT(Wnd != Wnd->spwndPrev);
+ Wnd->spwndPrev->spwndNext = Wnd;
+ }
+ else
+ {
+ /* Link at the top */
+ ASSERT(Wnd != Wnd->spwndParent->spwndChild);
+ Wnd->spwndNext = Wnd->spwndParent->spwndChild;
+ if (Wnd->spwndNext)
+ Wnd->spwndNext->spwndPrev = Wnd;
- Wnd->spwndParent->spwndChild = Wnd;
- }
+ Wnd->spwndParent->spwndChild = Wnd;
+ }
}
/*
{
if (hWndPrev == HWND_NOTOPMOST)
{
- if (!(Wnd->ExStyle & WS_EX_TOPMOST) &&
- (Wnd->ExStyle2 & WS_EX2_LINKED)) return; /* nothing to do */
+ if (!(Wnd->ExStyle & WS_EX_TOPMOST) && (Wnd->ExStyle2 & WS_EX2_LINKED))
+ return; /* nothing to do */
Wnd->ExStyle &= ~WS_EX_TOPMOST;
hWndPrev = HWND_TOP; /* fallback to the HWND_TOP case */
}
PWND WndInsertAfter;
WndInsertAfter = Wnd->spwndParent->spwndChild;
- while( WndInsertAfter && WndInsertAfter->spwndNext)
+ while (WndInsertAfter && WndInsertAfter->spwndNext)
+ {
WndInsertAfter = WndInsertAfter->spwndNext;
+ }
IntLinkWindow(Wnd, WndInsertAfter);
Wnd->ExStyle &= ~WS_EX_TOPMOST;
{
/* Link in the top of the list */
IntLinkWindow(Wnd, NULL);
-
Wnd->ExStyle |= WS_EX_TOPMOST;
}
else if (hWndPrev == HWND_TOP)
{
while (WndInsertBefore != NULL && WndInsertBefore->spwndNext != NULL)
{
- if (!(WndInsertBefore->ExStyle & WS_EX_TOPMOST)) break;
+ if (!(WndInsertBefore->ExStyle & WS_EX_TOPMOST))
+ break;
+
if (WndInsertBefore == Wnd->spwndOwner) /* keep it above owner */
{
Wnd->ExStyle |= WS_EX_TOPMOST;
WndInsertAfter = UserGetWindowObject(hWndPrev);
/* Are we called with an erroneous handle */
- if(WndInsertAfter == NULL)
+ if (WndInsertAfter == NULL)
{
/* Link in a default position */
IntLinkHwnd(Wnd, HWND_TOP);
return;
}
+ if (Wnd == WndInsertAfter)
+ ERR("IntLinkHwnd -- Trying to link window 0x%p to itself!!\n", Wnd);
IntLinkWindow(Wnd, WndInsertAfter);
/* Fix the WS_EX_TOPMOST flag */
}
else
{
- if(WndInsertAfter->spwndNext &&
- WndInsertAfter->spwndNext->ExStyle & WS_EX_TOPMOST)
+ if (WndInsertAfter->spwndNext &&
+ (WndInsertAfter->spwndNext->ExStyle & WS_EX_TOPMOST))
{
Wnd->ExStyle |= WS_EX_TOPMOST;
}
return( hWndOldParent);
}
-/* Unlink the window from siblings. children and parent are kept in place. */
+/* Unlink the window from siblings. Children and parent are kept in place. */
VOID FASTCALL
IntUnlinkWindow(PWND Wnd)
{
- if (Wnd->spwndNext)
- Wnd->spwndNext->spwndPrev = Wnd->spwndPrev;
+ ASSERT(Wnd != Wnd->spwndNext);
+ ASSERT(Wnd != Wnd->spwndPrev);
+
+ if (Wnd->spwndNext)
+ Wnd->spwndNext->spwndPrev = Wnd->spwndPrev;
- if (Wnd->spwndPrev)
- Wnd->spwndPrev->spwndNext = Wnd->spwndNext;
+ if (Wnd->spwndPrev)
+ Wnd->spwndPrev->spwndNext = Wnd->spwndNext;
- if (Wnd->spwndParent && Wnd->spwndParent->spwndChild == Wnd)
- Wnd->spwndParent->spwndChild = Wnd->spwndNext;
+ if (Wnd->spwndParent && Wnd->spwndParent->spwndChild == Wnd)
+ Wnd->spwndParent->spwndChild = Wnd->spwndNext;
- Wnd->spwndPrev = Wnd->spwndNext = NULL;
+ Wnd->spwndPrev = Wnd->spwndNext = NULL;
}
/* FUNCTIONS *****************************************************************/
PWND Window;
HWND *List = NULL;
- Status = PsLookupThreadByThreadId((HANDLE)dwThreadId, &Thread);
+ Status = PsLookupThreadByThreadId(UlongToHandle(dwThreadId), &Thread);
if (!NT_SUCCESS(Status))
{
ERR("Thread Id is not valid!\n");
}
}
else // Not a child
- pWnd->IDMenu = (UINT) Cs->hMenu;
+ pWnd->IDMenu = (UINT_PTR)Cs->hMenu;
if ( ParentWindow &&
hWnd = Window->head.h;
ti = PsGetCurrentThreadWin32Thread();
- TRACE("co_UserDestroyWindow \n");
+ TRACE("co_UserDestroyWindow(Window = 0x%p, hWnd = 0x%p)\n", Window, hWnd);
/* Check for owner thread */
if ( Window->head.pti != PsGetCurrentThreadWin32Thread())
}
}
- // Adjust last active.
+ /* Adjust last active */
if ((pwndTemp = Window->spwndOwner))
{
while (pwndTemp->spwndOwner)
return FALSE;
}
-static LONG
-co_IntSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi, BOOL bAlter)
+static LONG_PTR
+co_IntSetWindowLongPtr(HWND hWnd, DWORD Index, LONG_PTR NewValue, BOOL Ansi, ULONG Size, BOOL bAlter)
{
PWND Window, Parent;
PWINSTATION_OBJECT WindowStation;
- LONG OldValue;
+ LONG_PTR OldValue;
STYLESTRUCT Style;
if (!(Window = UserGetWindowObject(hWnd)))
if ((INT)Index >= 0)
{
- if ((Index + sizeof(LONG)) > Window->cbwndExtra)
+ if ((Index + Size) > Window->cbwndExtra)
{
EngSetLastError(ERROR_INVALID_INDEX);
return( 0);
}
- OldValue = *((LONG *)((PCHAR)(Window + 1) + Index));
-/*
- if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
+#ifdef _WIN64
+ if (Size == sizeof(LONG))
{
- OldValue = (LONG)IntSetWindowProc( Wnd,
- (WNDPROC)NewValue,
- Ansi);
- if (!OldValue) return 0;
+ OldValue = *((LONG *)((PCHAR)(Window + 1) + Index));
+ *((LONG*)((PCHAR)(Window + 1) + Index)) = (LONG)NewValue;
}
- */
- *((LONG *)((PCHAR)(Window + 1) + Index)) = NewValue;
+ else
+#endif
+ {
+ OldValue = *((LONG_PTR *)((PCHAR)(Window + 1) + Index));
+ /*
+ if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
+ {
+ OldValue = (LONG_PTR)IntSetWindowProc( Wnd, (WNDPROC)NewValue, Ansi);
+ if (!OldValue) return 0;
+ }
+ */
+ *((LONG_PTR*)((PCHAR)(Window + 1) + Index)) = NewValue;
+ }
+
}
else
{
+#ifdef _WIN64
+ if (Size == sizeof(LONG))
+ {
+ if ((Index != GWL_STYLE) &&
+ (Index != GWL_EXSTYLE) &&
+ (Index != GWL_ID) &&
+ (Index != GWL_USERDATA))
+ {
+ ERR("NtUserSetWindowLong(): Index requires pointer size: %lu\n", Index);
+ EngSetLastError(ERROR_INVALID_INDEX);
+ return 0;
+ }
+ }
+#endif
+
switch (Index)
{
- case GWL_EXSTYLE:
+ case GWL_EXSTYLE: // LONG
OldValue = (LONG) Window->ExStyle;
Style.styleOld = OldValue;
Style.styleNew = NewValue;
co_IntSendMessage(hWnd, WM_STYLECHANGED, GWL_EXSTYLE, (LPARAM) &Style);
break;
- case GWL_STYLE:
+ case GWL_STYLE: // LONG
OldValue = (LONG) Window->style;
Style.styleOld = OldValue;
Style.styleNew = NewValue;
co_IntSendMessage(hWnd, WM_STYLECHANGED, GWL_STYLE, (LPARAM) &Style);
break;
- case GWL_WNDPROC:
+ case GWLP_WNDPROC: // LONG_PTR
{
if ( Window->head.pti->ppi != PsGetCurrentProcessWin32Process() ||
Window->fnid & FNID_FREED)
EngSetLastError(ERROR_ACCESS_DENIED);
return( 0);
}
- OldValue = (LONG)IntSetWindowProc(Window,
- (WNDPROC)NewValue,
- Ansi);
+ OldValue = (LONG_PTR)IntSetWindowProc(Window,
+ (WNDPROC)NewValue,
+ Ansi);
break;
}
- case GWL_HINSTANCE:
- OldValue = (LONG) Window->hModule;
+ case GWLP_HINSTANCE: // LONG_PTR
+ OldValue = (LONG_PTR) Window->hModule;
Window->hModule = (HINSTANCE) NewValue;
break;
- case GWL_HWNDPARENT:
+ case GWLP_HWNDPARENT: // LONG_PTR
Parent = Window->spwndParent;
if (Parent && (Parent->head.h == IntGetDesktopWindow()))
- OldValue = (LONG) IntSetOwner(Window->head.h, (HWND) NewValue);
+ OldValue = (LONG_PTR) IntSetOwner(Window->head.h, (HWND) NewValue);
else
- OldValue = (LONG) co_UserSetParent(Window->head.h, (HWND) NewValue);
+ OldValue = (LONG_PTR) co_UserSetParent(Window->head.h, (HWND) NewValue);
break;
- case GWL_ID:
+ case GWLP_ID: // LONG
OldValue = (LONG) Window->IDMenu;
Window->IDMenu = (UINT) NewValue;
break;
- case GWL_USERDATA:
+ case GWLP_USERDATA: // LONG or LONG_PTR
OldValue = Window->dwUserData;
Window->dwUserData = NewValue;
break;
return( OldValue);
}
-
LONG FASTCALL
co_UserSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi)
{
- return co_IntSetWindowLong(hWnd, Index, NewValue, Ansi, FALSE);
+ return (LONG)co_IntSetWindowLongPtr(hWnd, Index, NewValue, Ansi, sizeof(LONG), FALSE);
+}
+
+LONG_PTR FASTCALL
+co_UserSetWindowLongPtr(HWND hWnd, DWORD Index, LONG_PTR NewValue, BOOL Ansi)
+{
+ return co_IntSetWindowLongPtr(hWnd, Index, NewValue, Ansi, sizeof(LONG_PTR), FALSE);
}
/*
return 0;
}
- ret = co_IntSetWindowLong(hWnd, Index, NewValue, Ansi, FALSE);
+ ret = (LONG)co_IntSetWindowLongPtr(hWnd, Index, NewValue, Ansi, sizeof(LONG), FALSE);
UserLeave();
return ret;
}
+#ifdef _WIN64
+LONG_PTR APIENTRY
+NtUserSetWindowLongPtr(HWND hWnd, DWORD Index, LONG_PTR NewValue, BOOL Ansi)
+{
+ LONG_PTR ret;
+
+ UserEnterExclusive();
+
+ if (hWnd == IntGetDesktopWindow())
+ {
+ EngSetLastError(STATUS_ACCESS_DENIED);
+ UserLeave();
+ return 0;
+ }
+
+ ret = co_IntSetWindowLongPtr(hWnd, Index, NewValue, Ansi, sizeof(LONG_PTR), FALSE);
+
+ UserLeave();
+
+ return ret;
+}
+#endif // _WIN64
+
DWORD APIENTRY
NtUserAlterWindowStyle(HWND hWnd, DWORD Index, LONG NewValue)
{
return 0;
}
- ret = co_IntSetWindowLong(hWnd, Index, NewValue, FALSE, TRUE);
+ ret = co_IntSetWindowLongPtr(hWnd, Index, NewValue, FALSE, sizeof(LONG), TRUE);
UserLeave();
/*
* @implemented
*/
-DWORD APIENTRY
+DWORD_PTR APIENTRY
NtUserQueryWindow(HWND hWnd, DWORD Index)
{
/* Console Leader Process CID Window offsets */
#define GWLP_CONSOLE_LEADER_TID 4
PWND pWnd;
- DWORD Result;
+ DWORD_PTR Result;
DECLARE_RETURN(UINT);
TRACE("Enter NtUserQueryWindow\n");
(pWnd->pcls->atomClassName == gaGuiConsoleWndClass) )
{
// IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
- Result = (DWORD)(*((LONG_PTR*)((PCHAR)(pWnd + 1) + GWLP_CONSOLE_LEADER_PID)));
+ Result = (DWORD_PTR)(*((LONG_PTR*)((PCHAR)(pWnd + 1) + GWLP_CONSOLE_LEADER_PID)));
}
else
{
- Result = (DWORD)IntGetWndProcessId(pWnd);
+ Result = (DWORD_PTR)IntGetWndProcessId(pWnd);
}
break;
}
(pWnd->pcls->atomClassName == gaGuiConsoleWndClass) )
{
// IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
- Result = (DWORD)(*((LONG_PTR*)((PCHAR)(pWnd + 1) + GWLP_CONSOLE_LEADER_TID)));
+ Result = (DWORD_PTR)(*((LONG_PTR*)((PCHAR)(pWnd + 1) + GWLP_CONSOLE_LEADER_TID)));
}
else
{
- Result = (DWORD)IntGetWndThreadId(pWnd);
+ Result = (DWORD_PTR)IntGetWndThreadId(pWnd);
}
break;
}
case QUERY_WINDOW_ACTIVE:
- Result = (DWORD)(pWnd->head.pti->MessageQueue->spwndActive ? UserHMGetHandle(pWnd->head.pti->MessageQueue->spwndActive) : 0);
+ Result = (DWORD_PTR)(pWnd->head.pti->MessageQueue->spwndActive ? UserHMGetHandle(pWnd->head.pti->MessageQueue->spwndActive) : 0);
break;
case QUERY_WINDOW_FOCUS:
- Result = (DWORD)(pWnd->head.pti->MessageQueue->spwndFocus ? UserHMGetHandle(pWnd->head.pti->MessageQueue->spwndFocus) : 0);
+ Result = (DWORD_PTR)(pWnd->head.pti->MessageQueue->spwndFocus ? UserHMGetHandle(pWnd->head.pti->MessageQueue->spwndFocus) : 0);
break;
case QUERY_WINDOW_ISHUNG:
- Result = (DWORD)MsqIsHung(pWnd->head.pti);
+ Result = (DWORD_PTR)MsqIsHung(pWnd->head.pti);
break;
case QUERY_WINDOW_REAL_ID:
- Result = (DWORD)pWnd->head.pti->pEThread->Cid.UniqueProcess;
+ Result = (DWORD_PTR)pWnd->head.pti->pEThread->Cid.UniqueProcess;
break;
case QUERY_WINDOW_FOREGROUND:
break;
default:
- Result = (DWORD)NULL;
+ Result = 0;
break;
}
// ASSERT(OwnerWnd);
TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow ? "TRUE" : "FALSE"));
- win_array = IntWinListChildren(OwnerWnd);
+
+ /* NOTE: Popups are not children */
+ win_array = IntWinListOwnedPopups(OwnerWnd);
if (!win_array)
return TRUE;
* regardless of the state of the owner
*/
co_IntSendMessage(win_array[count], WM_SHOWWINDOW, SW_SHOWNORMAL, SW_PARENTOPENING);
+ pWnd->state &= ~WNDS_HIDDENPOPUP;
continue;
}
}
* regardless of the state of the owner
*/
co_IntSendMessage(win_array[count], WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
+ pWnd->state |= WNDS_HIDDENPOPUP;
continue;
}
}
-
}
ExFreePoolWithTag(win_array, USERTAG_WINDOWLIST);
TRACE("Leave ShowOwnedPopups\n");