DWORD APIENTRY NtUserCallHwnd( HWND hWnd, DWORD Routine) { switch (Routine) { case HWND_ROUTINE_GETWNDCONTEXTHLPID: { PWND Window; PPROPERTY HelpId; USER_REFERENCE_ENTRY Ref; UserEnterExclusive(); if (!(Window = UserGetWindowObject(hWnd))) { UserLeave(); return 0; } UserRefObjectCo(Window, &Ref); HelpId = IntGetProp(Window, gpsi->atomContextHelpIdProp); UserDerefObjectCo(Window); UserLeave(); return (DWORD)HelpId->Data; } case HWND_ROUTINE_REGISTERSHELLHOOKWINDOW: if (IntIsWindow(hWnd)) return IntRegisterShellHookWindow(hWnd); return FALSE; break; case HWND_ROUTINE_DEREGISTERSHELLHOOKWINDOW: if (IntIsWindow(hWnd)) return IntDeRegisterShellHookWindow(hWnd); return FALSE; case HWND_ROUTINE_SETMSGBOX: { PWND Window; UserEnterExclusive(); if ((Window = UserGetWindowObject(hWnd))) { Window->state |= WNDS_MSGBOX; } UserLeave(); return FALSE; } } STUB; return 0; }
DWORD APIENTRY NtUserCallHwnd( HWND hWnd, DWORD Routine) { switch (Routine) { case HWND_ROUTINE_GETWNDCONTEXTHLPID: { PWND Window; DWORD HelpId; UserEnterShared(); if (!(Window = UserGetWindowObject(hWnd))) { UserLeave(); return 0; } HelpId = (DWORD)(DWORD_PTR)UserGetProp(Window, gpsi->atomContextHelpIdProp, TRUE); UserLeave(); return HelpId; } case HWND_ROUTINE_REGISTERSHELLHOOKWINDOW: if (IntIsWindow(hWnd)) return IntRegisterShellHookWindow(hWnd); return FALSE; break; case HWND_ROUTINE_DEREGISTERSHELLHOOKWINDOW: if (IntIsWindow(hWnd)) return IntDeRegisterShellHookWindow(hWnd); return FALSE; case HWND_ROUTINE_SETMSGBOX: { PWND Window; UserEnterExclusive(); if ((Window = UserGetWindowObject(hWnd))) { Window->state |= WNDS_MSGBOX; } UserLeave(); return FALSE; } } STUB; return 0; }
/* * @implemented */ BOOL APIENTRY NtUserSetLogonNotifyWindow(HWND hWnd) { if (gpidLogon != PsGetCurrentProcessId()) { return FALSE; } if (!IntIsWindow(hWnd)) { return FALSE; } hwndSAS = hWnd; return TRUE; }
HWND APIENTRY NtUserSetActiveWindow(HWND hWnd) { USER_REFERENCE_ENTRY Ref; HWND hWndPrev; PWND Window; DECLARE_RETURN(HWND); TRACE("Enter NtUserSetActiveWindow(%p)\n", hWnd); UserEnterExclusive(); Window = NULL; if (hWnd) { if (!(Window = UserGetWindowObject(hWnd))) { ERR("NtUserSetActiveWindow: Invalid handle 0x%p!\n",hWnd); RETURN( NULL); } } if (!Window || Window->head.pti->MessageQueue == gptiCurrent->MessageQueue) { hWndPrev = gptiCurrent->MessageQueue->spwndActive ? UserHMGetHandle(gptiCurrent->MessageQueue->spwndActive) : NULL; if (Window) UserRefObjectCo(Window, &Ref); UserSetActiveWindow(Window); if (Window) UserDerefObjectCo(Window); RETURN( hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : 0) : 0 ); } RETURN( NULL); CLEANUP: TRACE("Leave NtUserSetActiveWindow, ret=%p\n",_ret_); UserLeave(); END_CLEANUP; }
HWND FASTCALL co_UserSetFocus(PWND Window) { HWND hWndPrev = 0; PWND pwndTop; PTHREADINFO pti; PUSER_MESSAGE_QUEUE ThreadQueue; if (Window) ASSERT_REFS_CO(Window); pti = PsGetCurrentThreadWin32Thread(); ThreadQueue = pti->MessageQueue; ASSERT(ThreadQueue != 0); TRACE("Enter SetFocus hWnd 0x%p pti 0x%p\n",Window ? UserHMGetHandle(Window) : 0, pti ); hWndPrev = ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : 0; if (Window != 0) { if (hWndPrev == UserHMGetHandle(Window)) { return hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : 0) : 0; /* Nothing to do */ } if (Window->head.pti->MessageQueue != ThreadQueue) { ERR("SetFocus Must have the same Q!\n"); return 0; } /* Check if we can set the focus to this window */ for (pwndTop = Window; pwndTop != NULL; pwndTop = pwndTop->spwndParent) { if (pwndTop->style & (WS_MINIMIZED|WS_DISABLED)) return 0; if ((pwndTop->style & (WS_POPUP|WS_CHILD)) != WS_CHILD) break; } if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)Window->head.h, (LPARAM)hWndPrev)) { ERR("SetFocus 1 WH_CBT Call Hook return!\n"); return 0; } /* Activate pwndTop if needed. */ if (pwndTop != ThreadQueue->spwndActive) { PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue(); // Keep it based on desktop. if (ThreadQueue != ForegroundQueue && IsAllowedFGActive(pti, pwndTop)) // Rule 2 & 3. { //ERR("SetFocus: Set Foreground!\n"); if (!(pwndTop->style & WS_VISIBLE)) { pti->ppi->W32PF_flags |= W32PF_ALLOWFOREGROUNDACTIVATE; } if (!co_IntSetForegroundAndFocusWindow(pwndTop, FALSE)) { ERR("SetFocus: Set Foreground and Focus Failed!\n"); return 0; } } /* Set Active when it is needed. */ if (pwndTop != ThreadQueue->spwndActive) { //ERR("SetFocus: Set Active!\n"); if (!co_IntSetActiveWindow(pwndTop, FALSE, FALSE, FALSE)) { ERR("SetFocus: Set Active Failed!\n"); return 0; } } /* Abort if window destroyed */ if (Window->state2 & WNDS2_INDESTROY) return 0; /* Do not change focus if the window is no longer active */ if (pwndTop != ThreadQueue->spwndActive) { ERR("SetFocus: Top window did not go active!\n"); return 0; } } // Check again! SetActiveWindow could have set the focus via WM_ACTIVATE. hWndPrev = ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : 0; IntSendFocusMessages( pti, Window); TRACE("Focus: %p -> %p\n", hWndPrev, Window->head.h); } else /* NULL hwnd passed in */ { if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)0, (LPARAM)hWndPrev)) { ERR("SetFocus: 2 WH_CBT Call Hook return!\n"); return 0; } /* set the current thread focus window null */ IntSendFocusMessages( pti, NULL); } return hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : 0) : 0; }