ReactOS  0.4.15-dev-5496-g599ba9c
focus.c File Reference
#include <win32k.h>
#include <ddk/immdev.h>
Include dependency graph for focus.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (UserFocus)
 
BOOL FASTCALL IsFGLocked (VOID)
 
HWND FASTCALL IntGetCaptureWindow (VOID)
 
HWND FASTCALL IntGetThreadFocusWindow (VOID)
 
BOOL FASTCALL IntIsWindowFullscreen (PWND Window)
 
BOOL FASTCALL IntCheckFullscreen (PWND Window)
 
VOID FASTCALL UpdateShellHook (PWND Window)
 
BOOL FASTCALL co_IntSendDeactivateMessages (HWND hWndPrev, HWND hWnd, BOOL Clear)
 
VOID IntFocusSetInputContext (PWND pWnd, BOOL bActivate, BOOL bCallback)
 
BOOL FASTCALL IntDeactivateWindow (PTHREADINFO pti, HANDLE tid)
 
VOID FASTCALL IntActivateWindow (PWND Wnd, PTHREADINFO pti, HANDLE tid, DWORD Type)
 
BOOL FASTCALL co_IntMakeWindowActive (PWND Window)
 
BOOL FASTCALL co_IntSendActivateMessages (PWND WindowPrev, PWND Window, BOOL MouseActivate, BOOL Async)
 
VOID FASTCALL IntSendFocusMessages (PTHREADINFO pti, PWND pWnd)
 
BOOL FASTCALL FindRemoveEventMsg (PTHREADINFO pti, DWORD Event, DWORD EventLast)
 
BOOL FASTCALL ToggleFGActivate (PTHREADINFO pti)
 
BOOL FASTCALL IsAllowedFGActive (PTHREADINFO pti, PWND Wnd)
 
BOOL FASTCALL CanForceFG (PPROCESSINFO ppi)
 
BOOL FASTCALL co_IntSetForegroundMessageQueue (_In_opt_ PWND Wnd, _In_ PTHREADINFO pti, _In_ BOOL MouseActivate, _In_ DWORD Type)
 
static BOOL FASTCALL co_IntSetForegroundAndFocusWindow (_In_opt_ PWND Wnd, _In_ BOOL MouseActivate, _In_ BOOL bFlash)
 
BOOL FASTCALL co_IntSetActiveWindow (_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
 
BOOL FASTCALL IntUserSetActiveWindow (_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
 
BOOL FASTCALL co_IntMouseActivateWindow (PWND Wnd)
 
BOOL FASTCALL UserSetActiveWindow (_In_opt_ PWND Wnd)
 
HWND FASTCALL co_UserSetFocus (PWND Window)
 
HWND FASTCALL UserGetForegroundWindow (VOID)
 
HWND FASTCALL UserGetActiveWindow (VOID)
 
HWND APIENTRY IntGetCapture (VOID)
 
HWND FASTCALL co_UserSetCapture (HWND hWnd)
 
BOOL FASTCALL IntReleaseCapture (VOID)
 
BOOL FASTCALL co_IntSetForegroundWindow (PWND Window)
 
BOOL FASTCALL co_IntSetForegroundWindowMouse (PWND Window)
 
BOOL FASTCALL IntLockSetForegroundWindow (UINT uLockCode)
 
BOOL FASTCALL IntAllowSetForegroundWindow (DWORD dwProcessId)
 
HWND APIENTRY NtUserGetForegroundWindow (VOID)
 
HWND APIENTRY NtUserSetActiveWindow (HWND hWnd)
 
HWND APIENTRY NtUserSetCapture (HWND hWnd)
 
HWND APIENTRY NtUserSetFocus (HWND hWnd)
 

Variables

PUSER_MESSAGE_QUEUE gpqForeground = NULL
 
PUSER_MESSAGE_QUEUE gpqForegroundPrev = NULL
 
PTHREADINFO gptiForeground = NULL
 
PPROCESSINFO gppiLockSFW = NULL
 
ULONG guSFWLockCount = 0
 
PTHREADINFO ptiLastInput = NULL
 
HWND ghwndOldFullscreen = NULL
 

Function Documentation

◆ CanForceFG()

BOOL FASTCALL CanForceFG ( PPROCESSINFO  ppi)

Definition at line 749 of file focus.c.

750 {
751  if (!ptiLastInput ||
752  ptiLastInput->ppi == ppi ||
753  !gptiForeground ||
754  gptiForeground->ppi == ppi ||
756  gppiInputProvider == ppi ||
758  ) return TRUE;
759  //ERR("CanForceFG is FALSE\n");
760  return FALSE;
761 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
PTHREADINFO gptiForeground
Definition: focus.c:15
#define TRUE
Definition: types.h:120
#define W32PF_SETFOREGROUNDALLOWED
Definition: win32.h:20
PPROCESSINFO ppi
Definition: win32.h:88
#define W32PF_ALLOWFOREGROUNDACTIVATE
Definition: win32.h:12
#define FALSE
Definition: types.h:117
PPROCESSINFO gppiInputProvider
Definition: ntuser.c:16
PTHREADINFO ptiLastInput
Definition: focus.c:18

Referenced by co_IntSetForegroundAndFocusWindow(), IntAllowSetForegroundWindow(), and IntLockSetForegroundWindow().

◆ co_IntMakeWindowActive()

BOOL FASTCALL co_IntMakeWindowActive ( PWND  Window)

Definition at line 426 of file focus.c.

427 {
428  PWND spwndOwner;
429  if (VerifyWnd(Window))
430  { // Set last active for window and it's owner.
431  spwndOwner = Window;
432  while (spwndOwner->spwndOwner)
433  {
434  spwndOwner = spwndOwner->spwndOwner;
435  }
436  spwndOwner->spwndLastActive = Window;
437  return TRUE;
438  }
439  ERR("MakeWindowActive Failed!\n");
440  return FALSE;
441 }
#define TRUE
Definition: types.h:120
Definition: window.c:28
#define FALSE
Definition: types.h:117
struct _WND * spwndOwner
Definition: ntuser.h:710
int Window
Definition: x11stubs.h:26
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
struct _WND * spwndLastActive
Definition: ntuser.h:734
PWND FASTCALL VerifyWnd(PWND pWnd)
Definition: window.c:86

Referenced by co_IntSendActivateMessages().

◆ co_IntMouseActivateWindow()

BOOL FASTCALL co_IntMouseActivateWindow ( PWND  Wnd)

Definition at line 1250 of file focus.c.

1251 {
1252  TRACE("Mouse Active\n");
1253  if (Wnd && (Wnd->ExStyle & WS_EX_NOACTIVATE))
1254  return TRUE;
1256 }
DWORD ExStyle
Definition: ntuser.h:699
#define TRUE
Definition: types.h:120
#define WS_EX_NOACTIVATE
Definition: winuser.h:395
static BOOL FASTCALL co_IntSetForegroundAndFocusWindow(_In_opt_ PWND Wnd, _In_ BOOL MouseActivate, _In_ BOOL bFlash)
Definition: focus.c:924
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by co_IntProcessMouseMessage().

◆ co_IntSendActivateMessages()

BOOL FASTCALL co_IntSendActivateMessages ( PWND  WindowPrev,
PWND  Window,
BOOL  MouseActivate,
BOOL  Async 
)

Definition at line 444 of file focus.c.

445 {
446  USER_REFERENCE_ENTRY Ref, RefPrev, RefCall;
447  HANDLE OldTID, NewTID;
448  PTHREADINFO pti, ptiOld, ptiNew;
449  BOOL InAAPM = FALSE;
450 
451  //ERR("SendActivateMessages\n");
452 
454 
455  if (Window)
456  {
457  UserRefObjectCo(Window, &Ref);
458 
459  if (WindowPrev) UserRefObjectCo(WindowPrev, &RefPrev);
460 
461  pti->MessageQueue->QF_flags &= ~QF_EVENTDEACTIVATEREMOVED;
462 
463  /* Send palette messages */
464  if (gpsi->PUSIFlags & PUSIF_PALETTEDISPLAY &&
465  //co_IntPostOrSendMessage(UserHMGetHandle(Window), WM_QUERYNEWPALETTE, 0, 0))
467  {
471  0);
472  }
474  if (!(Window->style & WS_CHILD))
475  {
477 
478  while (pwndTemp && !(pwndTemp->style & WS_VISIBLE)) pwndTemp = pwndTemp->spwndNext;
479 
480  if (Window != pwndTemp || (WindowPrev && !IntIsWindowVisible(WindowPrev)))
481  {
482  if (!Async || pti->MessageQueue == gpqForeground)
483  {
485  if (Window == pwndTemp) flags |= SWP_NOACTIVATE;
486  //ERR("co_IntSendActivateMessages SetWindowPos! Async %d pti Q == FGQ %d\n",Async,pti->MessageQueue == gpqForeground);
488  }
489  }
490  }
493  if (Window->spwndPrev)
494  {
495  HWND *phwndTopLevel, *phwndCurrent;
496  PWND pwndCurrent, pwndDesktop;
497 
498  pwndDesktop = co_GetDesktopWindow(Window);//UserGetDesktopWindow();
499  if (Window->spwndParent == pwndDesktop )
500  {
501  phwndTopLevel = IntWinListChildren(pwndDesktop);
502  phwndCurrent = phwndTopLevel;
503  while(*phwndCurrent)
504  {
505  pwndCurrent = UserGetWindowObject(*phwndCurrent);
506 
507  if (pwndCurrent && pwndCurrent->spwndOwner == Window )
508  {
510  }
511  phwndCurrent++;
512  }
513  ExFreePoolWithTag(phwndTopLevel, USERTAG_WINDOWLIST);
514  }
515  }
517  }
518 
519  OldTID = WindowPrev ? IntGetWndThreadId(WindowPrev) : NULL;
520  NewTID = Window ? IntGetWndThreadId(Window) : NULL;
521  ptiOld = WindowPrev ? WindowPrev->head.pti : NULL;
522  ptiNew = Window ? Window->head.pti : NULL;
523 
524  //ERR("SendActivateMessage Old -> %x, New -> %x\n", OldTID, NewTID);
525 
526  if (!(pti->TIF_flags & TIF_INACTIVATEAPPMSG) &&
527  (OldTID != NewTID) )
528  {
529  PWND cWindow;
530  HWND *List, *phWnd;
531 
533  if ( List )
534  {
535  if ( OldTID )
536  {
537  ptiOld->TIF_flags |= TIF_INACTIVATEAPPMSG;
538  // Note: Do not set pci flags, this does crash!
539  for (phWnd = List; *phWnd; ++phWnd)
540  {
541  cWindow = ValidateHwndNoErr(*phWnd);
542  if (cWindow && cWindow->head.pti == ptiOld)
543  { // FALSE if the window is being deactivated,
544  // ThreadId that owns the window being activated.
545  //ERR("SAM : WM_ACTIVATEAPP(0) tid Old %p New %p\n",OldTID,NewTID);
546  UserRefObjectCo(cWindow, &RefCall);
547  co_IntSendMessage(*phWnd, WM_ACTIVATEAPP, FALSE, (LPARAM)NewTID);
548  UserDerefObjectCo(cWindow);
549  }
550  }
551  ptiOld->TIF_flags &= ~TIF_INACTIVATEAPPMSG;
552  }
553  if ( NewTID )
554  {
555  InAAPM = TRUE;
558  for (phWnd = List; *phWnd; ++phWnd)
559  {
560  cWindow = ValidateHwndNoErr(*phWnd);
561  if (cWindow && cWindow->head.pti == ptiNew)
562  { // TRUE if the window is being activated,
563  // ThreadId that owns the window being deactivated.
564  //ERR("SAM : WM_ACTIVATEAPP(1) hwnd %p tid New %p Old %p\n",UserHMGetHandle(cWindow),NewTID,OldTID);
565  UserRefObjectCo(cWindow, &RefCall);
566  co_IntSendMessage(*phWnd, WM_ACTIVATEAPP, TRUE, (LPARAM)OldTID);
567  UserDerefObjectCo(cWindow);
568  }
569  }
570  }
572  }
573  }
574 
575  if (Window)
576  {
577  if (WindowPrev)
578  UserDerefObjectCo(WindowPrev); // Now allow the previous window to die.
579 
580  if (Window->state & WNDS_ACTIVEFRAME)
581  { // If already active frame do not allow NCPaint.
582  //ERR("SendActivateMessage Is Active Frame!\n");
583  Window->state |= WNDS_NONCPAINT;
584  }
585 
586  if (Window->style & WS_MINIMIZE)
587  {
588  TRACE("Widow was minimized\n");
589  }
590 
592 
596  0);
597 
599  WM_ACTIVATE,
600  MAKEWPARAM(MouseActivate ? WA_CLICKACTIVE : WA_ACTIVE, (Window->style & WS_MINIMIZE) != 0),
601  (LPARAM)(WindowPrev ? UserHMGetHandle(WindowPrev) : 0));
602 
603  if (Window->style & WS_VISIBLE)
605 
606  Window->state &= ~WNDS_NONCPAINT;
607 
609  }
610  return InAAPM;
611 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
#define MAKEWPARAM(l, h)
Definition: winuser.h:3999
#define QF_EVENTDEACTIVATEREMOVED
Definition: msgqueue.h:107
#define TRUE
Definition: types.h:120
FLONG TIF_flags
Definition: win32.h:95
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
BOOLEAN FASTCALL co_WinPosSetWindowPos(PWND Window, HWND WndInsertAfter, INT x, INT y, INT cx, INT cy, UINT flags)
Definition: winpos.c:1748
BOOL FASTCALL UserSendNotifyMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:2037
PSERVERINFO gpsi
Definition: imm.c:18
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
#define HWND_TOP
Definition: winuser.h:1197
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
Definition: window.c:28
#define FALSE
Definition: types.h:117
#define WM_NCACTIVATE
Definition: winuser.h:1678
#define WS_MINIMIZE
Definition: pedump.c:622
unsigned int BOOL
Definition: ntddk_ex.h:94
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
struct _WND * spwndOwner
Definition: ntuser.h:710
THRDESKHEAD head
Definition: ntuser.h:690
Definition: object.h:3
LONG_PTR LPARAM
Definition: windef.h:208
PWND FASTCALL co_GetDesktopWindow(PWND pWnd)
Definition: desktop.c:1366
struct _WND * spwndNext
Definition: ntuser.h:706
#define WM_PALETTEISCHANGING
Definition: winuser.h:1866
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:126
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define WM_QUERYNEWPALETTE
Definition: winuser.h:1868
#define TRACE(s)
Definition: solgame.cpp:4
BOOL FASTCALL co_IntMakeWindowActive(PWND Window)
Definition: focus.c:426
#define SWP_NOACTIVATE
Definition: winuser.h:1232
#define TIF_INACTIVATEAPPMSG
Definition: ntuser.h:271
#define ValidateHwndNoErr(hwnd)
Definition: precomp.h:84
#define WA_ACTIVE
Definition: winuser.h:2613
#define WA_CLICKACTIVE
Definition: winuser.h:2614
GLbitfield flags
Definition: glext.h:7161
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1386
BOOL FASTCALL IntIsWindowVisible(PWND Wnd)
Definition: window.c:193
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
HWND *FASTCALL IntWinListChildren(PWND Window)
Definition: window.c:278
#define WNDS_ACTIVEFRAME
Definition: ntuser.h:606
#define SWP_NOSIZE
Definition: winuser.h:1235
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define WM_ACTIVATEAPP
Definition: winuser.h:1622
#define WM_ACTIVATE
Definition: winuser.h:1602
#define IntGetWndThreadId(WndObj)
Definition: window.h:34
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define WNDS_NONCPAINT
Definition: ntuser.h:608
#define PUSIF_PALETTEDISPLAY
Definition: ntuser.h:988
#define SWP_NOMOVE
Definition: winuser.h:1234
#define USERTAG_WINDOWLIST
Definition: tags.h:298
struct _WND * spwndChild
Definition: ntuser.h:709
#define WS_VISIBLE
Definition: pedump.c:620
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define HWND_BROADCAST
Definition: winuser.h:1194
VOID FASTCALL UpdateShellHook(PWND Window)
Definition: focus.c:99
DWORD style
Definition: ntuser.h:701

Referenced by co_IntSetActiveWindow().

◆ co_IntSendDeactivateMessages()

BOOL FASTCALL co_IntSendDeactivateMessages ( HWND  hWndPrev,
HWND  hWnd,
BOOL  Clear 
)

Definition at line 118 of file focus.c.

119 {
120  USER_REFERENCE_ENTRY RefPrev;
121  PWND WndPrev;
122  BOOL Ret = TRUE;
123  LPARAM lParam = hWnd ? (LPARAM)hWnd : 0;
124 
125  if (hWndPrev && (WndPrev = ValidateHwndNoErr(hWndPrev)))
126  {
127  UserRefObjectCo(WndPrev, &RefPrev);
128 
129  if (co_IntSendMessage(hWndPrev, WM_NCACTIVATE, FALSE, lParam))
130  {
131  co_IntSendMessage(hWndPrev, WM_ACTIVATE,
132  MAKEWPARAM(WA_INACTIVE, (WndPrev->style & WS_MINIMIZE) != 0),
133  (LPARAM)hWnd);
134 
135  if (WndPrev && Clear)
136  WndPrev->state &= ~(WNDS_ACTIVEFRAME|WNDS_HASCAPTION);
137  }
138  else
139  {
140  ERR("Application is keeping itself Active to prevent the change!\n");
141  Ret = FALSE;
142  }
143 
144  UserDerefObjectCo(WndPrev);
145  }
146  return Ret;
147 }
#define MAKEWPARAM(l, h)
Definition: winuser.h:3999
#define TRUE
Definition: types.h:120
HWND hWnd
Definition: settings.c:17
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
#define FALSE
Definition: types.h:117
#define WM_NCACTIVATE
Definition: winuser.h:1678
#define WS_MINIMIZE
Definition: pedump.c:622
unsigned int BOOL
Definition: ntddk_ex.h:94
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
Definition: object.h:3
LONG_PTR LPARAM
Definition: windef.h:208
#define ValidateHwndNoErr(hwnd)
Definition: precomp.h:84
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
#define WNDS_ACTIVEFRAME
Definition: ntuser.h:606
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
#define WM_ACTIVATE
Definition: winuser.h:1602
DWORD state
Definition: ntuser.h:696
#define WA_INACTIVE
Definition: winuser.h:2612
void Clear(USHORT Window)
Definition: hardware.c:684
LPARAM lParam
Definition: combotst.c:139
#define WNDS_HASCAPTION
Definition: ntuser.h:603
DWORD style
Definition: ntuser.h:701

Referenced by co_IntSetActiveWindow(), and IntDeactivateWindow().

◆ co_IntSetActiveWindow()

BOOL FASTCALL co_IntSetActiveWindow ( _In_ PWND  Wnd,
_In_ BOOL  bMouse,
_In_ BOOL  bFocus,
_In_ BOOL  Async 
)

Definition at line 1024 of file focus.c.

1029 {
1030  PTHREADINFO pti;
1031  PUSER_MESSAGE_QUEUE ThreadQueue;
1032  PWND pWndChg, WndPrev; // State changes.
1033  HWND hWndPrev;
1034  HWND hWnd = 0;
1035  BOOL InAAPM;
1036  CBTACTIVATESTRUCT cbt;
1037 
1038  //ERR("co_IntSetActiveWindow 1\n");
1039 
1041  ThreadQueue = pti->MessageQueue;
1042  ASSERT(ThreadQueue != 0);
1043 
1044  pWndChg = ThreadQueue->spwndActive; // Keep to notify of a preemptive switch.
1045  hWndPrev = (pWndChg ? UserHMGetHandle(pWndChg) : NULL);
1046 
1047  if ( !Wnd || Wnd == UserGetDesktopWindow() )
1048  {
1049  //ERR("ISAW : NULL %p\n",Wnd);
1050  return FALSE;
1051  }
1052 
1053  ASSERT_REFS_CO(Wnd);
1054  hWnd = UserHMGetHandle(Wnd);
1055  //ERR("co_IntSetActiveWindow 2 hWnd 0x%p\n",hWnd);
1056 
1057  if (Wnd->ExStyle & WS_EX_NOACTIVATE)
1058  return TRUE;
1059 
1060  /* check if the specified window can be set in the input data of a given queue */
1061  if ( ThreadQueue != Wnd->head.pti->MessageQueue )
1062  {
1063  //ERR("ISAW : Must have the same Message Queue\n");
1064  return FALSE;
1065  }
1066 
1067  if (!VerifyWnd(Wnd))
1068  {
1069  //ERR("ISAW : Window is in Destroy!\n");
1070  return FALSE;
1071  }
1072 
1073  if ( Wnd == pWndChg )
1074  {
1075  //ERR("ISAW : Nothing to do\n");
1076  return TRUE; // Fix CORE-8780 and CORE-11979. See CORE-11324 for breakage.
1077  }
1078 
1079  if ( Wnd->state & WNDS_BEINGACTIVATED ) return TRUE;
1080 
1081  /* Call CBT hook chain */
1082  cbt.fMouse = bMouse;
1083  cbt.hWndActive = hWndPrev;
1085  {
1086  ERR("SetActiveWindow: WH_CBT Call Hook return!\n");
1087  return FALSE;
1088  }
1089 
1090  ThreadQueue->QF_flags &= ~QF_EVENTDEACTIVATEREMOVED;
1091 
1092  if ( ThreadQueue->spwndActive && ThreadQueue->spwndActive->state & WNDS_DESTROYED )
1093  ThreadQueue->spwndActive = NULL;
1094  else
1095  ThreadQueue->spwndActivePrev = ThreadQueue->spwndActive;
1096 
1097  WndPrev = ThreadQueue->spwndActive; // Keep to save changing active.
1098 
1099  if (WndPrev)
1100  {
1101  if (ThreadQueue == gpqForeground) gpqForegroundPrev = ThreadQueue;
1102  if (!co_IntSendDeactivateMessages(UserHMGetHandle(WndPrev), hWnd, TRUE)) return FALSE;
1103  }
1104 
1105  WndPrev = ThreadQueue->spwndActive; // Again keep to save changing active.
1106 
1107  // While in calling message proc or hook:
1108  // Fail if a preemptive switch was made, current active not made previous,
1109  // focus window is dead or no longer the same thread queue.
1110  if ( ThreadQueue->spwndActivePrev != ThreadQueue->spwndActive ||
1111  pWndChg != WndPrev ||
1112  (Wnd && !VerifyWnd(Wnd)) ||
1113  ThreadQueue != pti->MessageQueue )
1114  {
1115  ERR("SetActiveWindow: Summary ERROR, active state changed!\n");
1116  return FALSE;
1117  }
1118 
1119  if (!WndPrev) ThreadQueue->QF_flags &= ~QF_FOCUSNULLSINCEACTIVE;
1120 
1121  /* set the current thread active window */
1122  ThreadQueue->spwndActive = Wnd;
1123 
1124  // Set state flag to prevent recursions.
1125  Wnd->state |= WNDS_BEINGACTIVATED;
1126 
1127  IntNotifyWinEvent(EVENT_SYSTEM_FOREGROUND, Wnd, OBJID_WINDOW, CHILDID_SELF, WEF_SETBYWNDPTI);
1128 
1129  // Clear out activate EVENT messages.
1131 
1132  WndPrev = VerifyWnd(ThreadQueue->spwndActivePrev); // Now should be set but verify it again.
1133 
1134  InAAPM = co_IntSendActivateMessages(WndPrev, Wnd, bMouse, Async);
1135 
1136  /* now change focus if necessary */
1138  if (bFocus && !(ThreadQueue->QF_flags & QF_FOCUSNULLSINCEACTIVE))
1139  {
1140  /* Do not change focus if the window is no longer active */
1141  if (pti->MessageQueue->spwndActive != IntGetNonChildAncestor(pti->MessageQueue->spwndFocus))
1142  {
1143  PWND pWndSend = pti->MessageQueue->spwndActive;
1144  // Clear focus if the active window is minimized.
1145  if (pWndSend && pti->MessageQueue->spwndActive->style & WS_MINIMIZE) pWndSend = NULL;
1146  // Send focus messages and if so, set the focus.
1147  IntSendFocusMessages( pti, pWndSend);
1148  }
1149  }
1151  if (InAAPM)
1152  {
1154  }
1155 
1156  // Checked in MENU_TrackMenu
1157  ThreadQueue->QF_flags |= QF_ACTIVATIONCHANGE;
1158 
1159  //ERR("co_IntSetActiveWindow Exit\n");
1160  Wnd->state &= ~WNDS_BEINGACTIVATED;
1161  return (ThreadQueue->spwndActive == Wnd);
1162 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
BOOL FASTCALL FindRemoveEventMsg(PTHREADINFO pti, DWORD Event, DWORD EventLast)
Definition: focus.c:679
#define QF_FOCUSNULLSINCEACTIVE
Definition: msgqueue.h:105
#define QF_EVENTDEACTIVATEREMOVED
Definition: msgqueue.h:107
VOID FASTCALL IntSendFocusMessages(PTHREADINFO pti, PWND pWnd)
Definition: focus.c:615
#define TRUE
Definition: types.h:120
#define ASSERT_REFS_CO(_obj_)
Definition: userfuncs.h:14
FLONG TIF_flags
Definition: win32.h:95
VOID FASTCALL IntNotifyWinEvent(DWORD Event, PWND pWnd, LONG idObject, LONG idChild, DWORD flags)
Definition: event.c:179
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define OBJID_WINDOW
Definition: winable.h:15
HWND hWnd
Definition: settings.c:17
UINT_PTR WPARAM
Definition: windef.h:207
#define WNDS_BEINGACTIVATED
Definition: ntuser.h:620
#define FALSE
Definition: types.h:117
#define WS_MINIMIZE
Definition: pedump.c:622
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CHILDID_SELF
Definition: winable.h:14
LONG_PTR LPARAM
Definition: windef.h:208
#define WH_CBT
Definition: winuser.h:35
#define WS_EX_NOACTIVATE
Definition: winuser.h:395
#define WEF_SETBYWNDPTI
Definition: ntuser.h:235
BOOL FASTCALL co_IntSendDeactivateMessages(HWND hWndPrev, HWND hWnd, BOOL Clear)
Definition: focus.c:118
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define ASSERT(a)
Definition: mode.c:44
#define TIF_INACTIVATEAPPMSG
Definition: ntuser.h:271
LRESULT APIENTRY co_HOOK_CallHooks(INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:1103
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1386
BOOL FASTCALL co_IntSendActivateMessages(PWND WindowPrev, PWND Window, BOOL MouseActivate, BOOL Async)
Definition: focus.c:444
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define QF_ACTIVATIONCHANGE
Definition: msgqueue.h:100
DWORD state
Definition: ntuser.h:696
#define NULL
Definition: types.h:112
#define POSTEVENT_DAW
Definition: msgqueue.h:123
PWND FASTCALL IntGetNonChildAncestor(PWND pWnd)
Definition: window.c:346
PUSER_MESSAGE_QUEUE gpqForegroundPrev
Definition: focus.c:14
#define HCBT_ACTIVATE
Definition: winuser.h:60
PWND FASTCALL VerifyWnd(PWND pWnd)
Definition: window.c:86
#define POSTEVENT_SAW
Definition: msgqueue.h:124
#define WNDS_DESTROYED
Definition: ntuser.h:631

Referenced by co_IntSetForegroundMessageQueue(), co_UserSetFocus(), IntActivateWindow(), and IntUserSetActiveWindow().

◆ co_IntSetForegroundAndFocusWindow()

static BOOL FASTCALL co_IntSetForegroundAndFocusWindow ( _In_opt_ PWND  Wnd,
_In_ BOOL  MouseActivate,
_In_ BOOL  bFlash 
)
static

Definition at line 924 of file focus.c.

928 {
929  HWND hWnd = Wnd ? UserHMGetHandle(Wnd) : NULL;
930  PUSER_MESSAGE_QUEUE PrevForegroundQueue;
931  PTHREADINFO pti;
932  BOOL Ret = FALSE;
933 
934  if (Wnd) ASSERT_REFS_CO(Wnd);
935 
936  TRACE("SetForegroundAndFocusWindow(%x, %s)\n", hWnd, (MouseActivate ? "TRUE" : "FALSE"));
937 
938  PrevForegroundQueue = IntGetFocusMessageQueue(); // Use this active desktop.
940 
941  if (Wnd && PrevForegroundQueue)
942  { // Same Window Q as foreground just do active.
943  if (Wnd->head.pti->MessageQueue == PrevForegroundQueue)
944  {
945  //ERR("Same Window Q as foreground just do active.\n");
946  if (pti->MessageQueue == PrevForegroundQueue)
947  { // Same WQ and TQ go active.
948  //ERR("Same WQ and TQ go active.\n");
949  Ret = IntUserSetActiveWindow(Wnd, MouseActivate, TRUE, FALSE);
950  }
951  else if (Wnd->head.pti->MessageQueue->spwndActive == Wnd)
952  { // Same WQ and it is active.
953  //ERR("Same WQ and it is active.\n");
954  Ret = TRUE;
955  }
956  else
957  { // Same WQ as FG but not the same TQ send active.
958  //ERR("Same WQ as FG but not the same TQ send active.\n");
959  MSG Msg;
960  PTHREADINFO ptiNew = Wnd->head.pti;
961 
962  Msg.message = WM_ASYNC_SETACTIVEWINDOW;
963  Msg.hwnd = hWnd;
964  Msg.wParam = (WPARAM)Wnd;
965  Msg.lParam = 0;
966  Msg.time = 0;
967  //ERR("SFAFW 1 : SAW P pti 0x%p hWnd 0x%p\n",ptiNew,hWnd);
968  MsqPostMessage(ptiNew, &Msg, FALSE, QS_EVENT, POSTEVENT_SAW, (LONG_PTR)MouseActivate);
969 
970  Ret = TRUE;
971  }
972  return Ret;
973  }
974  }
975 
976  if ( (( !IsFGLocked() || pti->ppi == gppiInputProvider ) &&
978  pti->ppi == ppiScrnSaver
979  )
980  {
981 
982  ToggleFGActivate(pti);
983 
984  return co_IntSetForegroundMessageQueue( Wnd, pti, MouseActivate, 0 );
985  }
986 
987  if (!Wnd) return FALSE; // No window, always return FALSE.
988 
990 
991  if (pti->MessageQueue == Wnd->head.pti->MessageQueue)
992  {
993  //ERR("Same PQ and WQ go active.\n");
994  Ret = IntUserSetActiveWindow(Wnd, MouseActivate, TRUE, FALSE);
995  //if (!Ret) ERR("ISFAFW : IUSAW : return error\n");
996  }
997  else if (Wnd->head.pti->MessageQueue->spwndActive == Wnd)
998  {
999  TRACE("Same Active and Wnd.\n"); // Leave this for now.
1000  }
1001  else
1002  {
1003  //ERR("Activate Not same PQ and WQ and Wnd.\n");
1005  MSG Msg;
1006  PTHREADINFO ptiNew = Wnd->head.pti;
1007 
1008  Msg.message = WM_ASYNC_SETACTIVEWINDOW;
1009  Msg.hwnd = hWnd;
1010  Msg.wParam = (WPARAM)Wnd;
1011  Msg.lParam = 0;
1012  Msg.time = 0;
1013  //ERR("SFAFW 2 : SAW P pti 0x%p hWnd 0x%p\n",ptiNew,hWnd);
1014  MsqPostMessage(ptiNew, &Msg, FALSE, QS_EVENT, POSTEVENT_SAW, (LONG_PTR)MouseActivate);
1015  }
1016  // Always return FALSE.
1017  return FALSE;
1018 }
PPROCESSINFO ppiScrnSaver
Definition: main.c:30
BOOL FASTCALL IntUserSetActiveWindow(_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
Definition: focus.c:1170
#define TRUE
Definition: types.h:120
#define ASSERT_REFS_CO(_obj_)
Definition: userfuncs.h:14
BOOL FASTCALL IsFGLocked(VOID)
Definition: focus.c:25
FLONG TIF_flags
Definition: win32.h:95
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
HWND hWnd
Definition: settings.c:17
UINT_PTR WPARAM
Definition: windef.h:207
#define TIF_SYSTEMTHREAD
Definition: ntuser.h:264
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1307
PPROCESSINFO ppi
Definition: win32.h:88
#define FALSE
Definition: types.h:117
#define TIF_CSRSSTHREAD
Definition: ntuser.h:265
unsigned int BOOL
Definition: ntddk_ex.h:94
PPROCESSINFO gppiInputProvider
Definition: ntuser.c:16
#define TIF_ALLOWFOREGROUNDACTIVATE
Definition: ntuser.h:267
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define TRACE(s)
Definition: solgame.cpp:4
#define QS_EVENT
Definition: undocuser.h:97
VOID FASTCALL MsqPostMessage(PTHREADINFO pti, MSG *Msg, BOOLEAN HardwareMessage, DWORD MessageBits, DWORD dwQEvent, LONG_PTR ExtraInfo)
Definition: msgqueue.c:1337
BOOL FASTCALL co_IntSetForegroundMessageQueue(_In_opt_ PWND Wnd, _In_ PTHREADINFO pti, _In_ BOOL MouseActivate, _In_ DWORD Type)
Definition: focus.c:767
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
BOOL FASTCALL ToggleFGActivate(PTHREADINFO pti)
Definition: focus.c:710
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
BOOL FASTCALL CanForceFG(PPROCESSINFO ppi)
Definition: focus.c:749
#define POSTEVENT_SAW
Definition: msgqueue.h:124
struct @1595 Msg[]

Referenced by co_IntMouseActivateWindow(), co_IntSetForegroundWindow(), co_IntSetForegroundWindowMouse(), co_UserSetFocus(), and IntUserSetActiveWindow().

◆ co_IntSetForegroundMessageQueue()

BOOL FASTCALL co_IntSetForegroundMessageQueue ( _In_opt_ PWND  Wnd,
_In_ PTHREADINFO  pti,
_In_ BOOL  MouseActivate,
_In_ DWORD  Type 
)

Definition at line 767 of file focus.c.

772 {
773  PTHREADINFO ptiChg, ptiPrev;
774  PUSER_MESSAGE_QUEUE pumq, pumqChg, pumqPrev;
775  BOOL Removed, Ret = TRUE;
776 
777  if (Wnd && !VerifyWnd(Wnd))
778  {
779  return FALSE;
780  }
781 
783  ptiPrev = NULL;
784  else
785  ptiPrev = gptiForeground;
786 
787  if (Wnd)
788  {
789  ptiChg = Wnd->head.pti;
790  IntSetFocusMessageQueue(Wnd->head.pti->MessageQueue);
791  gptiForeground = Wnd->head.pti;
792  //ERR("Set Foreground pti 0x%p Q 0x%p hWnd 0x%p\n",Wnd->head.pti, Wnd->head.pti->MessageQueue,Wnd->head.h);
793  }
794  else
795  {
796  ptiChg = NULL;
799  //ERR("Set Foreground pti 0x0 Q 0x0 hWnd 0x0\n");
800  }
801 
802  //
803  // Process the changing out of the message queues.
804  //
806  {
807  pumqPrev = NULL;
808  if ( ptiPrev && !(ptiPrev->TIF_flags & TIF_INCLEANUP) )
809  {
810  pumqPrev = ptiPrev->MessageQueue;
811  }
812 
813  pumq = pti ? pti->MessageQueue : NULL;
814 
815  // Deactivate the previous message queue.
816  if (pumqPrev)
817  {
818  if ( pumq != pumqPrev )
819  {
820  MSG Msg;
821  HWND hWndPrev = pumqPrev->spwndActive ? UserHMGetHandle(pumqPrev->spwndActive) : NULL;
822  HANDLE tid = gptiForeground ? PsGetThreadId(gptiForeground->pEThread) : NULL; // TID from changing Window PTI.
823 
824  Msg.message = WM_ASYNC_SETACTIVEWINDOW;
825  Msg.hwnd = hWndPrev;
826  Msg.wParam = (WPARAM)pumqPrev->spwndActive;
827  Msg.lParam = 0;
828  Msg.time = 0;
829  //ERR("SFWAMQ : DAW P pti 0x%p tid 0x%p hWndPrev 0x%p\n",ptiPrev,tid,hWndPrev);
831  }
832  }
833 
834  pumqChg = NULL;
835  if ( ptiChg && !(ptiChg->TIF_flags & TIF_INCLEANUP) )
836  {
837  pumqChg = ptiChg->MessageQueue;
838  }
839 
840  pumq = pti ? pti->MessageQueue : NULL;
841 
842  // Activate changing message queue.
843  if (pumqChg)
844  {
845  /*
846  Henri Verbeet,
847  What happens is that we get the WM_WINE_SETACTIVEWINDOW message sent by the
848  other thread after we already changed the foreground window back to our own
849  window.
850  */
851  //ERR("SFWAMQ : 1\n");
853 
854  if (pumqChg != pumq)
855  {
856  MSG Msg;
857  HWND hWnd = Wnd ? UserHMGetHandle(Wnd) : NULL;
858  HANDLE tid = ptiPrev ? PsGetThreadId(ptiPrev->pEThread) : NULL;
859 
860  if (Removed) pumqChg->QF_flags |= QF_EVENTDEACTIVATEREMOVED;
861 
862  Msg.message = WM_ASYNC_SETACTIVEWINDOW;
863  Msg.hwnd = hWnd;
864  Msg.wParam = (WPARAM)Wnd;
865  Msg.lParam = (LPARAM)tid;
866  Msg.time = 0;
867  //ERR("SFWAMQ : SAW P pti 0x%p tid 0x%p hWnd 0x%p\n",ptiChg,tid,hWnd);
868  MsqPostMessage(ptiChg, &Msg, FALSE, QS_EVENT, POSTEVENT_SAW, (LONG_PTR)Type|MouseActivate);
869  }
870  else // Current message queue same as changed message queue.
871  {
872  if (pumq->spwndActive == Wnd)
873  {
875 
876  UpdateShellHook(Wnd);
877 
879  }
880  else
881  {
882  //ERR("SFWAMQ : SAW I pti 0x%p hWnd 0x%p\n",ptiChg,Wnd->head.h);
883  Ret = co_IntSetActiveWindow(Wnd, MouseActivate, TRUE/*Type*/, FALSE);
884  //if (!Ret) ERR("SFWAMQ : ISAW : return error\n");
885  return Ret;
886  }
887  }
888  }
889 
890  // Handle same message queue after switch out.
891  pumqPrev = NULL;
892  if ( ptiPrev && !(ptiPrev->TIF_flags & TIF_INCLEANUP) )
893  {
894  pumqPrev = ptiPrev->MessageQueue;
895  }
896  pumq = pti ? pti->MessageQueue : NULL;
897 
898  if ( pumqPrev && pumq == pumqPrev )
899  {
900  HANDLE tid = Wnd ? PsGetThreadId(Wnd->head.pti->pEThread) : NULL;
901  //ERR("SFWAMQ : DAW I pti 0x%p tid 0x%p hWnd 0x%p\n",ptiPrev,tid,Wnd ? Wnd->head.h : 0);
902  IntDeactivateWindow(pti, tid);
903  }
904  }
905  return Ret;
906 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
PTHREADINFO gptiForeground
Definition: focus.c:15
BOOL FASTCALL co_IntSetActiveWindow(_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
Definition: focus.c:1024
BOOL FASTCALL FindRemoveEventMsg(PTHREADINFO pti, DWORD Event, DWORD EventLast)
Definition: focus.c:679
#define QF_EVENTDEACTIVATEREMOVED
Definition: msgqueue.h:107
#define TRUE
Definition: types.h:120
#define POSTEVENT_NONE
Definition: msgqueue.h:126
FLONG TIF_flags
Definition: win32.h:95
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOLEAN FASTCALL co_WinPosSetWindowPos(PWND Window, HWND WndInsertAfter, INT x, INT y, INT cx, INT cy, UINT flags)
Definition: winpos.c:1748
HWND hWnd
Definition: settings.c:17
#define HWND_TOP
Definition: winuser.h:1197
UINT_PTR WPARAM
Definition: windef.h:207
#define FALSE
Definition: types.h:117
#define WM_NCACTIVATE
Definition: winuser.h:1678
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG_PTR LPARAM
Definition: windef.h:208
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define QS_EVENT
Definition: undocuser.h:97
Type
Definition: Type.h:6
VOID FASTCALL MsqPostMessage(PTHREADINFO pti, MSG *Msg, BOOLEAN HardwareMessage, DWORD MessageBits, DWORD dwQEvent, LONG_PTR ExtraInfo)
Definition: msgqueue.c:1337
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
#define SWP_NOSIZE
Definition: winuser.h:1235
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
VOID FASTCALL IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue)
Definition: desktop.c:1319
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
#define POSTEVENT_DAW
Definition: msgqueue.h:123
PUSER_MESSAGE_QUEUE gpqForegroundPrev
Definition: focus.c:14
BOOL FASTCALL IntDeactivateWindow(PTHREADINFO pti, HANDLE tid)
Definition: focus.c:191
#define SWP_NOMOVE
Definition: winuser.h:1234
Definition: fbtusb.h:86
PWND FASTCALL VerifyWnd(PWND pWnd)
Definition: window.c:86
#define POSTEVENT_SAW
Definition: msgqueue.h:124
struct @1595 Msg[]
static TfClientId tid
VOID FASTCALL UpdateShellHook(PWND Window)
Definition: focus.c:99
#define TIF_INCLEANUP
Definition: ntuser.h:262

Referenced by co_IntSetForegroundAndFocusWindow(), and IntActivateWindow().

◆ co_IntSetForegroundWindow()

BOOL FASTCALL co_IntSetForegroundWindow ( PWND  Window)

Definition at line 1550 of file focus.c.

1551 {
1553 
1555 }
#define TRUE
Definition: types.h:120
#define ASSERT_REFS_CO(_obj_)
Definition: userfuncs.h:14
Definition: window.c:28
#define FALSE
Definition: types.h:117
static BOOL FASTCALL co_IntSetForegroundAndFocusWindow(_In_opt_ PWND Wnd, _In_ BOOL MouseActivate, _In_ BOOL bFlash)
Definition: focus.c:924

Referenced by ActivateOtherWindowMin(), co_WinPosActivateOtherWindow(), co_WinPosSetWindowPos(), co_WinPosShowWindow(), DefWndHandleSetCursor(), DefWndHandleSysCommand(), and NtUserCallHwndLock().

◆ co_IntSetForegroundWindowMouse()

BOOL FASTCALL co_IntSetForegroundWindowMouse ( PWND  Window)

Definition at line 1561 of file focus.c.

1562 {
1564 
1566 }
#define TRUE
Definition: types.h:120
#define ASSERT_REFS_CO(_obj_)
Definition: userfuncs.h:14
Definition: window.c:28
#define FALSE
Definition: types.h:117
static BOOL FASTCALL co_IntSetForegroundAndFocusWindow(_In_opt_ PWND Wnd, _In_ BOOL MouseActivate, _In_ BOOL bFlash)
Definition: focus.c:924

Referenced by NC_HandleNCLButtonDown(), NtUserCallHwndLock(), and NtUserCallTwoParam().

◆ co_UserSetCapture()

HWND FASTCALL co_UserSetCapture ( HWND  hWnd)

These are HACKS!

Definition at line 1458 of file focus.c.

1459 {
1460  PTHREADINFO pti;
1461  PUSER_MESSAGE_QUEUE ThreadQueue;
1462  PWND pWnd, Window = NULL;
1463  HWND hWndPrev;
1464 
1466  ThreadQueue = pti->MessageQueue;
1467 
1468  if (ThreadQueue->QF_flags & QF_CAPTURELOCKED)
1469  return NULL;
1470 
1471  if (hWnd && (Window = UserGetWindowObject(hWnd)))
1472  {
1473  if (Window->head.pti->MessageQueue != ThreadQueue)
1474  {
1475  ERR("Window Thread does not match Current!\n");
1476  return NULL;
1477  }
1478  }
1479 
1480  hWndPrev = MsqSetStateWindow(pti, MSQ_STATE_CAPTURE, hWnd);
1481 
1482  if (hWndPrev)
1483  {
1484  pWnd = UserGetWindowObject(hWndPrev);
1485  if (pWnd)
1486  IntNotifyWinEvent(EVENT_SYSTEM_CAPTUREEND, pWnd, OBJID_WINDOW, CHILDID_SELF, WEF_SETBYWNDPTI);
1487  }
1488 
1489  if (Window)
1490  IntNotifyWinEvent(EVENT_SYSTEM_CAPTURESTART, Window, OBJID_WINDOW, CHILDID_SELF, WEF_SETBYWNDPTI);
1491 
1492  //
1493  // Only send the message if we have a previous Window!
1494  // Fix msg_menu tracking popup menu and win test_capture_4!!!!
1495  //
1496  if (hWndPrev)
1497  {
1498  if (ThreadQueue->MenuOwner && Window) ThreadQueue->QF_flags |= QF_CAPTURELOCKED;
1499 
1501 
1502  ThreadQueue->QF_flags &= ~QF_CAPTURELOCKED;
1503  }
1504 
1505  if (hWnd == NULL) // Release mode.
1506  {
1507  MOUSEINPUT mi;
1509  /* Also remove other windows if not capturing anymore */
1513  /* Somebody may have missed some mouse movements */
1514  mi.dx = 0;
1515  mi.dy = 0;
1516  mi.mouseData = 0;
1518  mi.time = 0;
1519  mi.dwExtraInfo = 0;
1521  }
1522  return hWndPrev;
1523 }
#define MSQ_STATE_MOVESIZE
Definition: ntuser.h:3703
BOOL NTAPI UserSendMouseInput(MOUSEINPUT *pMouseInput, BOOL bInjected)
Definition: mouse.c:168
VOID FASTCALL IntNotifyWinEvent(DWORD Event, PWND pWnd, LONG idObject, LONG idChild, DWORD flags)
Definition: event.c:179
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define WM_CAPTURECHANGED
Definition: winuser.h:1798
#define OBJID_WINDOW
Definition: winable.h:15
HWND hWnd
Definition: settings.c:17
static MONITORINFO mi
Definition: win.c:7338
Definition: window.c:28
#define FALSE
Definition: types.h:117
#define QF_CAPTURELOCKED
Definition: msgqueue.h:111
#define CHILDID_SELF
Definition: winable.h:14
LONG_PTR LPARAM
Definition: windef.h:208
#define WEF_SETBYWNDPTI
Definition: ntuser.h:235
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:126
HWND FASTCALL MsqSetStateWindow(PTHREADINFO pti, ULONG Type, HWND hWnd)
Definition: msgqueue.c:2551
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define MSQ_STATE_CAPTURE
Definition: ntuser.h:3699
#define MOUSEEVENTF_MOVE
Definition: winuser.h:1173
#define NULL
Definition: types.h:112
DWORD dwFlags
Definition: winuser.h:3777
#define MSQ_STATE_MENUOWNER
Definition: ntuser.h:3702

Referenced by DefWndDoSizeMove(), IntReleaseCapture(), IntTrackPopupMenuEx(), MENU_DoNextMenu(), MENU_InitTracking(), MENU_TrackMenu(), NC_DoButton(), NC_HandleNCRButtonDown(), NtUserDragDetect(), and NtUserSetCapture().

◆ co_UserSetFocus()

HWND FASTCALL co_UserSetFocus ( PWND  Window)

Definition at line 1314 of file focus.c.

1315 {
1316  HWND hWndPrev = 0;
1317  PWND pwndTop;
1318  PTHREADINFO pti;
1319  PUSER_MESSAGE_QUEUE ThreadQueue;
1320 
1321  if (Window)
1323 
1325  ThreadQueue = pti->MessageQueue;
1326  ASSERT(ThreadQueue != 0);
1327 
1328  TRACE("Enter SetFocus hWnd 0x%p pti 0x%p\n",Window ? UserHMGetHandle(Window) : 0, pti );
1329 
1330  hWndPrev = ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : 0;
1331 
1332  if (Window != 0)
1333  {
1334  if (hWndPrev == UserHMGetHandle(Window))
1335  {
1336  return hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : 0) : 0; /* Nothing to do */
1337  }
1338 
1339  if (Window->head.pti->MessageQueue != ThreadQueue)
1340  {
1341  ERR("SetFocus Must have the same Q!\n");
1342  return 0;
1343  }
1344 
1345  /* Check if we can set the focus to this window */
1347  for (pwndTop = Window; pwndTop; pwndTop = pwndTop->spwndParent)
1348  {
1349  if (pwndTop->style & (WS_MINIMIZED|WS_DISABLED)) return 0;
1350  if ((pwndTop->style & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1351  if (pwndTop->spwndParent == NULL) break;
1352  }
1354  if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)Window->head.h, (LPARAM)hWndPrev))
1355  {
1356  ERR("SetFocus 1 WH_CBT Call Hook return!\n");
1357  return 0;
1358  }
1359 
1360  /* Activate pwndTop if needed. */
1361  if (pwndTop != ThreadQueue->spwndActive)
1362  {
1363  PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue(); // Keep it based on desktop.
1364  if (ThreadQueue != ForegroundQueue && IsAllowedFGActive(pti, pwndTop)) // Rule 2 & 3.
1365  {
1366  //ERR("SetFocus: Set Foreground!\n");
1367  if (!(pwndTop->style & WS_VISIBLE))
1368  {
1369  pti->ppi->W32PF_flags |= W32PF_ALLOWFOREGROUNDACTIVATE;
1370  }
1372  {
1373  ERR("SetFocus: Set Foreground and Focus Failed!\n");
1374  return 0;
1375  }
1376  }
1377 
1378  /* Set Active when it is needed. */
1379  if (pwndTop != ThreadQueue->spwndActive)
1380  {
1381  //ERR("SetFocus: Set Active! %p\n",pwndTop?UserHMGetHandle(pwndTop):0);
1382  if (!co_IntSetActiveWindow(pwndTop, FALSE, FALSE, FALSE))
1383  {
1384  ERR("SetFocus: Set Active Failed!\n");
1385  return 0;
1386  }
1387  }
1388 
1389  /* Abort if window destroyed */
1390  if (Window->state2 & WNDS2_INDESTROY) return 0;
1391  /* Do not change focus if the window is no longer active */
1392  if (pwndTop != ThreadQueue->spwndActive)
1393  {
1394  ERR("SetFocus: Top window did not go active!\n");
1395  return 0;
1396  }
1397  }
1398 
1399  // Check again! SetActiveWindow could have set the focus via WM_ACTIVATE.
1400  hWndPrev = ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : 0;
1401 
1403 
1404  TRACE("Focus: %p -> %p\n", hWndPrev, Window->head.h);
1405  }
1406  else /* NULL hwnd passed in */
1407  {
1408  if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)0, (LPARAM)hWndPrev))
1409  {
1410  ERR("SetFocus: 2 WH_CBT Call Hook return!\n");
1411  return 0;
1412  }
1413  //ERR("SetFocus: Set Focus NULL\n");
1414  /* set the current thread focus window null */
1415  IntSendFocusMessages( pti, NULL);
1416  }
1417  return hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : 0) : 0;
1418 }
#define WS_DISABLED
Definition: pedump.c:621
BOOL FASTCALL co_IntSetActiveWindow(_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
Definition: focus.c:1024
VOID FASTCALL IntSendFocusMessages(PTHREADINFO pti, PWND pWnd)
Definition: focus.c:615
#define TRUE
Definition: types.h:120
#define ASSERT_REFS_CO(_obj_)
Definition: userfuncs.h:14
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
#define HCBT_SETFOCUS
Definition: winuser.h:64
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1307
PPROCESSINFO ppi
Definition: win32.h:88
Definition: window.c:28
#define W32PF_ALLOWFOREGROUNDACTIVATE
Definition: win32.h:12
#define FALSE
Definition: types.h:117
LONG_PTR LPARAM
Definition: windef.h:208
#define WH_CBT
Definition: winuser.h:35
#define WS_MINIMIZED
Definition: undocuser.h:18
static BOOL FASTCALL co_IntSetForegroundAndFocusWindow(_In_opt_ PWND Wnd, _In_ BOOL MouseActivate, _In_ BOOL bFlash)
Definition: focus.c:924
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
BOOL FASTCALL IntIsWindow(HWND hWnd)
Definition: window.c:180
LRESULT APIENTRY co_HOOK_CallHooks(INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:1103
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define WS_POPUP
Definition: pedump.c:616
#define NULL
Definition: types.h:112
struct _WND * spwndParent
Definition: ntuser.h:708
BOOL FASTCALL IsAllowedFGActive(PTHREADINFO pti, PWND Wnd)
Definition: focus.c:730
#define WS_VISIBLE
Definition: pedump.c:620
#define WNDS2_INDESTROY
Definition: ntuser.h:643
DWORD style
Definition: ntuser.h:701

Referenced by co_WinPosShowWindow(), IntDefWindowProc(), IntEnableWindow(), IntSendDestroyMsg(), and NtUserSetFocus().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserFocus  )

◆ FindRemoveEventMsg()

BOOL FASTCALL FindRemoveEventMsg ( PTHREADINFO  pti,
DWORD  Event,
DWORD  EventLast 
)

Definition at line 679 of file focus.c.

680 {
683  BOOL Ret = FALSE;
684 
686  while (Entry != &pti->PostedMessagesListHead)
687  {
688  // Scan posted queue messages to see if we received async messages.
690  Entry = Entry->Flink;
691 
692  if (Message->dwQEvent == EventLast)
693  {
694  //ERR("Event D/SAW: Last Activate/Deactivate %d\n", EventLast);
695  return Ret;
696  }
697 
698  if (Message->dwQEvent == Event)
699  {
700  //ERR("Event D/SAW: Found one in the Post Msg Queue! Activate/Deactivate %d\n", Event);
701  ClearMsgBitsMask(pti, Message->QS_Flags);
703  Ret = TRUE;
704  }
705  }
706  return Ret;
707 }
struct _Entry Entry
Definition: kefuncs.h:629
#define TRUE
Definition: types.h:120
VOID FASTCALL MsqDestroyMessage(PUSER_MESSAGE Message)
Definition: msgqueue.c:748
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
VOID FASTCALL ClearMsgBitsMask(PTHREADINFO pti, UINT MessageBits)
Definition: msgqueue.c:445
CHAR Message[80]
Definition: alive.c:5
Definition: typedefs.h:119
LIST_ENTRY PostedMessagesListHead
Definition: win32.h:137
base of all file and directory entries
Definition: entries.h:82

Referenced by co_IntSetActiveWindow(), and co_IntSetForegroundMessageQueue().

◆ IntActivateWindow()

VOID FASTCALL IntActivateWindow ( PWND  Wnd,
PTHREADINFO  pti,
HANDLE  tid,
DWORD  Type 
)

Definition at line 357 of file focus.c.

358 {
361 
362  if (Wnd)
363  {
364  Wnd = VerifyWnd(Wnd);
365 
366  if (!Wnd) return;
367 
368  UserRefObjectCo(Wnd, &Ref);
369 
370  if (!gpqForeground)
371  {
372  // No foreground queue set.
373  co_IntSetForegroundMessageQueue( Wnd, pti, (BOOL)Type, 0);
374  }
375  else
376  {
377  // Same Active and Wnd.
378  if ( pmq->spwndActive == Wnd )
379  {
380  WPARAM wParam = (Wnd->head.pti->MessageQueue == gpqForeground);
381 
383 
384  if (wParam)
385  {
386  UpdateShellHook(Wnd);
387 
389  }
390  }
391  else // Not the same, set the active Wnd.
392  {
394  }
395  }
396  UserDerefObjectCo(Wnd);
397  }
398  else // Handle no Wnd!
399  {
400  if ( tid && // TID,
401  pmq->spwndActive && // Active WND not zero,
402  gpqForeground == pmq ) // Same message queues.
403  {
404  Wnd = pmq->spwndActive; // Use active window from current queue.
405 
406  UserRefObjectCo(Wnd, &Ref);
407 
409 
410  UpdateShellHook(Wnd);
411 
413 
414  UserDerefObjectCo(Wnd);
415  }
416  else if (gpqForeground != pmq)
417  {
418  // Not the same message queue so clear flags for foreground switching.
420  pti->ppi->W32PF_flags &= ~W32PF_ALLOWFOREGROUNDACTIVATE;
421  }
422  }
423 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
BOOL FASTCALL co_IntSetActiveWindow(_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
Definition: focus.c:1024
#define TRUE
Definition: types.h:120
FLONG TIF_flags
Definition: win32.h:95
BOOLEAN FASTCALL co_WinPosSetWindowPos(PWND Window, HWND WndInsertAfter, INT x, INT y, INT cx, INT cy, UINT flags)
Definition: winpos.c:1748
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
#define HWND_TOP
Definition: winuser.h:1197
UINT_PTR WPARAM
Definition: windef.h:207
WPARAM wParam
Definition: combotst.c:138
PPROCESSINFO ppi
Definition: win32.h:88
#define W32PF_ALLOWFOREGROUNDACTIVATE
Definition: win32.h:12
#define WM_NCACTIVATE
Definition: winuser.h:1678
unsigned int BOOL
Definition: ntddk_ex.h:94
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
THRDESKHEAD head
Definition: ntuser.h:690
Definition: object.h:3
#define TIF_ALLOWFOREGROUNDACTIVATE
Definition: ntuser.h:267
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
Type
Definition: Type.h:6
BOOL FASTCALL co_IntSetForegroundMessageQueue(_In_opt_ PWND Wnd, _In_ PTHREADINFO pti, _In_ BOOL MouseActivate, _In_ DWORD Type)
Definition: focus.c:767
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
#define SWP_NOSIZE
Definition: winuser.h:1235
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define SWP_NOMOVE
Definition: winuser.h:1234
PWND FASTCALL VerifyWnd(PWND pWnd)
Definition: window.c:86
static TfClientId tid
VOID FASTCALL UpdateShellHook(PWND Window)
Definition: focus.c:99

Referenced by handle_internal_events().

◆ IntAllowSetForegroundWindow()

BOOL FASTCALL IntAllowSetForegroundWindow ( DWORD  dwProcessId)

Definition at line 1603 of file focus.c.

1604 {
1605  PPROCESSINFO ppi, ppiCur;
1607 
1608  ppi = NULL;
1609  if (dwProcessId != ASFW_ANY)
1610  {
1612  {
1614  return FALSE;
1615  }
1617  if (!ppi)
1618  {
1620  return FALSE;
1621  }
1622  }
1624  if (!CanForceFG(ppiCur))
1625  {
1628  return FALSE;
1629  }
1630  if (dwProcessId == ASFW_ANY)
1631  { // All processes will be enabled to set the foreground window.
1632  //ERR("ptiLastInput is CLEARED!!\n");
1633  ptiLastInput = NULL;
1634  }
1635  else
1636  { // Rule #3, last input event in force.
1637  ERR("ptiLastInput is SET!!\n");
1638  //ptiLastInput = ppi->ptiList; // See CORE-6384 & CORE-7030.
1640  }
1641  return TRUE;
1642 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRUE
Definition: types.h:120
PVOID NTAPI PsGetProcessWin32Process(PEPROCESS Process)
Definition: process.c:1193
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
PTHREADINFO ptiLastInput
Definition: focus.c:18
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define ObDereferenceObject
Definition: obfuncs.h:203
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOL FASTCALL CanForceFG(PPROCESSINFO ppi)
Definition: focus.c:749
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28

Referenced by NtUserCallOneParam().

◆ IntCheckFullscreen()

BOOL FASTCALL IntCheckFullscreen ( PWND  Window)

Definition at line 79 of file focus.c.

80 {
81  HWND hWnd;
82 
85 
87  return FALSE;
88 
90  if (ghwndOldFullscreen != hWnd)
91  {
94  }
95  return TRUE;
96 }
#define TRUE
Definition: types.h:120
HWND hWnd
Definition: settings.c:17
HWND ghwndOldFullscreen
Definition: focus.c:19
BOOL FASTCALL IntIsWindowFullscreen(PWND Window)
Definition: focus.c:53
UINT_PTR WPARAM
Definition: windef.h:207
Definition: window.c:28
#define FALSE
Definition: types.h:117
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define ValidateHwndNoErr(hwnd)
Definition: precomp.h:84
#define NULL
Definition: types.h:112
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1692
#define HSHELL_RUDEAPPACTIVATED
Definition: winuser.h:1271

Referenced by co_WinPosSetWindowPos(), and UpdateShellHook().

◆ IntDeactivateWindow()

BOOL FASTCALL IntDeactivateWindow ( PTHREADINFO  pti,
HANDLE  tid 
)

Definition at line 191 of file focus.c.

192 {
194  PTHREADINFO ptiPrev;
195  PWND pwndPrev;
196  BOOL InAAPM = FALSE;
198 
199  if ( !pti->MessageQueue->spwndActive )
200  {
201  TRACE("IDAW E : Nothing to do, Active is NULL! pti 0x%p tid 0x%p\n",pti,tid);
202  return TRUE;
203  }
204 
205  TRACE("IDAW : pti 0x%p tid 0x%p\n",pti,tid);
206 
207  if (ptiCurrent != pti)
208  {
210  IntReferenceThreadInfo(ptiCurrent);
211  }
212 
213  if (!(pti->TIF_flags & TIF_INACTIVATEAPPMSG) )
214  {
216  InAAPM = TRUE;
217  }
218 
219  //
220  // Check for Capture and release it.
221  //
222  if ( pti->MessageQueue->spwndCapture )
223  {
224  MSG msg;
225  PWND pwndCapture = pti->MessageQueue->spwndCapture;
226 
227  UserRefObjectCo(pwndCapture, &Ref);
228  co_IntSendMessage(UserHMGetHandle(pwndCapture), WM_CANCELMODE, 0, 0);
229  UserDerefObjectCo(pwndCapture);
230 
231  /* Generate mouse move message */
232  msg.message = WM_MOUSEMOVE;
233  msg.wParam = UserGetMouseButtonsState();
234  msg.lParam = MAKELPARAM(gpsi->ptCursor.x, gpsi->ptCursor.y);
235  msg.pt = gpsi->ptCursor;
237  }
238 
239  //
240  // Check for Active and release it.
241  //
242  if ( pti->MessageQueue->spwndActive )
243  {
244  pwndPrev = pti->MessageQueue->spwndActive;
245  ptiPrev = pwndPrev->head.pti;
246 
248  {
249  if (InAAPM) pti->TIF_flags &= ~TIF_INACTIVATEAPPMSG;
250  if (ptiCurrent != pti)
251  {
253  IntDereferenceThreadInfo(ptiCurrent);
254  }
255  return FALSE;
256  }
257 
258  if ( pti->MessageQueue->spwndActive == pwndPrev )
259  {
260  pti->MessageQueue->spwndActivePrev = pwndPrev;
261  pti->MessageQueue->spwndActive = NULL;
262  }
263 
264  if (ptiPrev->TIF_flags & TIF_INCLEANUP) ptiPrev = NULL;
265  }
266  else
267  {
268  ptiPrev = pti;
269  pwndPrev = (PWND)-1; // Avoid zero Active window.
270  }
271 
272  if ( ptiPrev )
273  {
274  HANDLE OldTID = PsGetThreadId(ptiPrev->pEThread);
275  PWND cWindow;
276  HWND *List, *phWnd;
277 
279  if ( List )
280  {
281  if ( OldTID )
282  {
283  for (phWnd = List; *phWnd; ++phWnd)
284  {
285  cWindow = ValidateHwndNoErr(*phWnd);
286  if ( cWindow && cWindow->head.pti == ptiPrev )
287  { // FALSE if the window is being deactivated,
288  // ThreadId that owns the window being activated.
289  //ERR("IDW : WM_ACTIVATEAPP(0) hwnd %p tid Old %p New %p\n",UserHMGetHandle(cWindow),OldTID,tid);
290  UserRefObjectCo(cWindow, &Ref);
292  UserDerefObjectCo(cWindow);
293  }
294  }
295  }
297  }
298  }
299 
300  //
301  // Now check for a change (Bounce), if Active same as previous window, release it too.
302  //
303  if ( pti->MessageQueue->spwndActive == pwndPrev )
304  {
306  {
307  if (InAAPM) pti->TIF_flags &= ~TIF_INACTIVATEAPPMSG;
308  if (ptiCurrent != pti)
309  {
311  IntDereferenceThreadInfo(ptiCurrent);
312  }
313  return FALSE;
314  }
315 
316  if ( pti->MessageQueue->spwndActive == pwndPrev )
317  {
318  pti->MessageQueue->spwndActivePrev = pwndPrev;
319  pti->MessageQueue->spwndActive = NULL;
320  }
321  }
322 
323  //
324  // Check for Focus and release it.
325  //
326  if ( pti->MessageQueue->spwndFocus )
327  {
328  PWND pwndFocus = pti->MessageQueue->spwndFocus;
329 
330  //
331  // Fix win.c:test_SetForegroundWindow:SetActiveWindow(0)!
332  //
333  pti->MessageQueue->spwndFocus = NULL; // Null out Focus.
334 
335  UserRefObjectCo(pwndFocus, &Ref);
337  if (IS_IMM_MODE())
338  {
339  IntFocusSetInputContext(pwndFocus, FALSE, FALSE);
340  }
341  UserDerefObjectCo(pwndFocus);
342  }
343 
344  if (InAAPM) pti->TIF_flags &= ~TIF_INACTIVATEAPPMSG;
345  if (ptiCurrent != pti)
346  {
348  IntDereferenceThreadInfo(ptiCurrent);
349  }
350  return TRUE;
351 }
VOID FASTCALL co_MsqInsertMouseMessage(MSG *Msg, DWORD flags, ULONG_PTR dwExtraInfo, BOOL Hook)
Definition: msgqueue.c:580
VOID IntFocusSetInputContext(PWND pWnd, BOOL bActivate, BOOL bCallback)
Definition: focus.c:150
#define TRUE
Definition: types.h:120
#define IS_IMM_MODE()
Definition: ntuser.h:1232
FLONG TIF_flags
Definition: win32.h:95
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define MAKELPARAM(l, h)
Definition: winuser.h:3998
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
PSERVERINFO gpsi
Definition: imm.c:18
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
WORD FASTCALL UserGetMouseButtonsState(VOID)
Definition: mouse.c:22
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
THRDESKHEAD head
Definition: ntuser.h:690
Definition: object.h:3
LONG_PTR LPARAM
Definition: windef.h:208
#define IntReferenceThreadInfo(pti)
Definition: win32.h:166
BOOL FASTCALL co_IntSendDeactivateMessages(HWND hWndPrev, HWND hWnd, BOOL Clear)
Definition: focus.c:118
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define TRACE(s)
Definition: solgame.cpp:4
#define WM_KILLFOCUS
Definition: winuser.h:1604
#define TIF_INACTIVATEAPPMSG
Definition: ntuser.h:271
#define ValidateHwndNoErr(hwnd)
Definition: precomp.h:84
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1386
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define WM_CANCELMODE
Definition: winuser.h:1625
HWND *FASTCALL IntWinListChildren(PWND Window)
Definition: window.c:278
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
struct _WND * PWND
#define WM_ACTIVATEAPP
Definition: winuser.h:1622
#define WM_MOUSEMOVE
Definition: winuser.h:1765
#define NULL
Definition: types.h:112
#define msg(x)
Definition: auth_time.c:54
#define USERTAG_WINDOWLIST
Definition: tags.h:298
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define IntDereferenceThreadInfo(pti)
Definition: win32.h:171
static TfClientId tid
#define TIF_INCLEANUP
Definition: ntuser.h:262

Referenced by co_IntSetForegroundMessageQueue(), and handle_internal_events().

◆ IntFocusSetInputContext()

VOID IntFocusSetInputContext ( PWND  pWnd,
BOOL  bActivate,
BOOL  bCallback 
)

Definition at line 150 of file focus.c.

151 {
152  PTHREADINFO pti;
153  PWND pImeWnd;
155  HWND hImeWnd;
156  WPARAM wParam;
157  LPARAM lParam;
158 
159  if (!pWnd || !pWnd->pcls || IS_WND_IMELIKE(pWnd))
160  return;
161 
162  pti = pWnd->head.pti;
163  if (!pti || (pti->TIF_flags & TIF_INCLEANUP))
164  return;
165 
166  pImeWnd = pti->spwndDefaultIme;
167  if (!pImeWnd)
168  return;
169 
170  UserRefObjectCo(pImeWnd, &Ref);
171 
172  hImeWnd = UserHMGetHandle(pImeWnd);
173  wParam = (bActivate ? IMS_IMEACTIVATE : IMS_IMEDEACTIVATE);
174  lParam = (LPARAM)UserHMGetHandle(pWnd);
175 
176  if (bCallback)
178  else
180 
181  UserDerefObjectCo(pImeWnd);
182 }
#define IMS_IMEACTIVATE
Definition: immdev.h:38
FLONG TIF_flags
Definition: win32.h:95
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
UINT_PTR WPARAM
Definition: windef.h:207
WPARAM wParam
Definition: combotst.c:138
#define IMS_IMEDEACTIVATE
Definition: immdev.h:39
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
THRDESKHEAD head
Definition: ntuser.h:690
Definition: object.h:3
LONG_PTR LPARAM
Definition: windef.h:208
struct _WND * spwndDefaultIme
Definition: win32.h:131
#define WM_IME_SYSTEM
Definition: undocuser.h:60
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
Definition: ntuser.h:688
#define NULL
Definition: types.h:112
#define IS_WND_IMELIKE(pWnd)
Definition: window.h:113
LPARAM lParam
Definition: combotst.c:139
#define TIF_INCLEANUP
Definition: ntuser.h:262
LRESULT FASTCALL co_IntSendMessageWithCallBack(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, SENDASYNCPROC CompletionCallback, ULONG_PTR CompletionCallbackContext, ULONG_PTR *uResult)
Definition: message.c:1732
PCLS pcls
Definition: ntuser.h:715

Referenced by IntDeactivateWindow(), and IntSendFocusMessages().

◆ IntGetCapture()

HWND APIENTRY IntGetCapture ( VOID  )

Definition at line 1440 of file focus.c.

1441 {
1442  PTHREADINFO pti;
1443  PUSER_MESSAGE_QUEUE ThreadQueue;
1445 
1446  TRACE("Enter IntGetCapture\n");
1447 
1449  ThreadQueue = pti->MessageQueue;
1450  RETURN( ThreadQueue ? (ThreadQueue->spwndCapture ? UserHMGetHandle(ThreadQueue->spwndCapture) : 0) : 0);
1451 
1452 CLEANUP:
1453  TRACE("Leave IntGetCapture, ret=%p\n", _ret_);
1454  END_CLEANUP;
1455 }
#define CLEANUP
Definition: ntuser.h:5
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define RETURN(x)
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define TRACE(s)
Definition: solgame.cpp:4
#define DECLARE_RETURN(type)
Definition: ntuser.h:3
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define END_CLEANUP
Definition: ntuser.h:6

Referenced by DefWndDoSizeMove(), MENU_TrackMenu(), NC_HandleNCRButtonDown(), and NtUserGetThreadState().

◆ IntGetCaptureWindow()

HWND FASTCALL IntGetCaptureWindow ( VOID  )

Definition at line 34 of file focus.c.

35 {
36  PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue();
37  return ( ForegroundQueue ? (ForegroundQueue->spwndCapture ? UserHMGetHandle(ForegroundQueue->spwndCapture) : 0) : 0);
38 }
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1307
#define UserHMGetHandle(obj)
Definition: ntuser.h:230

Referenced by co_IntTranslateAccelerator(), co_MsqInsertMouseMessage(), and IntDefWindowProc().

◆ IntGetThreadFocusWindow()

HWND FASTCALL IntGetThreadFocusWindow ( VOID  )

Definition at line 41 of file focus.c.

42 {
43  PTHREADINFO pti;
44  PUSER_MESSAGE_QUEUE ThreadQueue;
45 
47  ThreadQueue = pti->MessageQueue;
48  if (!ThreadQueue)
49  return NULL;
50  return ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : 0;
51 }
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define NULL
Definition: types.h:112

Referenced by IntEnableWindow(), and NtUserGetThreadState().

◆ IntIsWindowFullscreen()

BOOL FASTCALL IntIsWindowFullscreen ( PWND  Window)

Definition at line 53 of file focus.c.

54 {
55  RECTL rclAnd, rclMonitor, rclWindow;
56  PMONITOR pMonitor;
57 
58  if (!Window || !(Window->style & WS_VISIBLE) || (Window->style & WS_CHILD) ||
59  (Window->ExStyle & WS_EX_TOOLWINDOW) || !IntGetWindowRect(Window, &rclWindow))
60  {
61  return FALSE;
62  }
63 
64  pMonitor = UserGetPrimaryMonitor();
65  if (!pMonitor)
66  {
67  RECTL_vSetRect(&rclMonitor, 0, 0,
69  }
70  else
71  {
72  rclMonitor = *(LPRECTL)&pMonitor->rcMonitor;
73  }
74 
75  RECTL_bIntersectRect(&rclAnd, &rclMonitor, &rclWindow);
76  return RtlEqualMemory(&rclAnd, &rclMonitor, sizeof(RECTL));
77 }
#define WS_CHILD
Definition: pedump.c:617
#define WS_EX_TOOLWINDOW
Definition: winuser.h:404
#define SM_CXSCREEN
Definition: winuser.h:953
Definition: window.c:28
#define FALSE
Definition: types.h:117
struct _RECTL * LPRECTL
LONG NTAPI UserGetSystemMetrics(ULONG Index)
Definition: metric.c:208
#define SM_CYSCREEN
Definition: winuser.h:954
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
BOOL FASTCALL RECTL_bIntersectRect(_Out_ RECTL *prclDst, _In_ const RECTL *prcl1, _In_ const RECTL *prcl2)
Definition: rect.c:55
FORCEINLINE VOID RECTL_vSetRect(_Out_ RECTL *prcl, _In_ LONG left, _In_ LONG top, _In_ LONG right, _In_ LONG bottom)
Definition: rect.h:5
PMONITOR NTAPI UserGetPrimaryMonitor(VOID)
Definition: monitor.c:102
RECT rcMonitor
Definition: monitor.h:18
#define WS_VISIBLE
Definition: pedump.c:620
BOOL FASTCALL IntGetWindowRect(PWND Wnd, RECTL *Rect)
Definition: winpos.c:120

Referenced by IntCheckFullscreen().

◆ IntLockSetForegroundWindow()

BOOL FASTCALL IntLockSetForegroundWindow ( UINT  uLockCode)

Definition at line 1572 of file focus.c.

1573 {
1574  ULONG Err = ERROR_ACCESS_DENIED;
1576  switch (uLockCode)
1577  {
1578  case LSFW_LOCK:
1579  if ( CanForceFG(ppi) && !gppiLockSFW )
1580  {
1581  gppiLockSFW = ppi;
1582  return TRUE;
1583  }
1584  break;
1585  case LSFW_UNLOCK:
1586  if ( gppiLockSFW == ppi)
1587  {
1588  gppiLockSFW = NULL;
1589  return TRUE;
1590  }
1591  break;
1592  default:
1594  }
1595  EngSetLastError(Err);
1596  return FALSE;
1597 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRUE
Definition: types.h:120
PPROCESSINFO gppiLockSFW
Definition: focus.c:16
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define NULL
Definition: types.h:112
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
BOOL FASTCALL CanForceFG(PPROCESSINFO ppi)
Definition: focus.c:749
unsigned int ULONG
Definition: retypes.h:1
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28

Referenced by NtUserCallOneParam().

◆ IntReleaseCapture()

BOOL FASTCALL IntReleaseCapture ( VOID  )

Definition at line 1530 of file focus.c.

1531 {
1532  PTHREADINFO pti;
1533  PUSER_MESSAGE_QUEUE ThreadQueue;
1534 
1536  ThreadQueue = pti->MessageQueue;
1537 
1538  // Can not release inside WM_CAPTURECHANGED!!
1539  if (ThreadQueue->QF_flags & QF_CAPTURELOCKED) return FALSE;
1540 
1542 
1543  return TRUE;
1544 }
#define TRUE
Definition: types.h:120
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define FALSE
Definition: types.h:117
#define QF_CAPTURELOCKED
Definition: msgqueue.h:111
HWND FASTCALL co_UserSetCapture(HWND hWnd)
Definition: focus.c:1458
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define NULL
Definition: types.h:112

Referenced by co_UserFreeWindow(), DefWndDoSizeMove(), IntDefWindowProc(), NC_DoButton(), NC_HandleNCRButtonDown(), and NtUserCallNoParam().

◆ IntSendFocusMessages()

VOID FASTCALL IntSendFocusMessages ( PTHREADINFO  pti,
PWND  pWnd 
)

Definition at line 615 of file focus.c.

616 {
617  PWND pWndPrev;
618  PUSER_MESSAGE_QUEUE ThreadQueue = pti->MessageQueue; // Queue can change...
619  HWND hwndPrev;
621 
622  ThreadQueue->QF_flags &= ~QF_FOCUSNULLSINCEACTIVE;
623  if (!pWnd && ThreadQueue->spwndActive)
624  {
625  ThreadQueue->QF_flags |= QF_FOCUSNULLSINCEACTIVE;
626  }
627 
628  pWndPrev = ThreadQueue->spwndFocus;
629  if (pWndPrev)
630  UserRefObjectCo(pWndPrev, &Ref);
631 
632  /* check if the specified window can be set in the input data of a given queue */
633  if (!pWnd || ThreadQueue == pWnd->head.pti->MessageQueue)
634  /* set the current thread focus window */
635  ThreadQueue->spwndFocus = pWnd;
636 
637  if (pWnd)
638  {
639  if (pWndPrev)
640  {
642  if (IS_IMM_MODE())
643  {
644  IntFocusSetInputContext(pWndPrev, FALSE, FALSE);
645  }
646  }
647  if (ThreadQueue->spwndFocus == pWnd)
648  {
649  if (IS_IMM_MODE())
650  {
652  }
653 
654  IntNotifyWinEvent(EVENT_OBJECT_FOCUS, pWnd, OBJID_CLIENT, CHILDID_SELF, 0);
655 
656  hwndPrev = (pWndPrev ? UserHMGetHandle(pWndPrev) : NULL);
657  co_IntSendMessage(UserHMGetHandle(pWnd), WM_SETFOCUS, (WPARAM)hwndPrev, 0);
658  }
659  }
660  else
661  {
662  if (pWndPrev)
663  {
664  IntNotifyWinEvent(EVENT_OBJECT_FOCUS, NULL, OBJID_CLIENT, CHILDID_SELF, 0);
665 
667  if (IS_IMM_MODE())
668  {
669  IntFocusSetInputContext(pWndPrev, FALSE, FALSE);
670  }
671  }
672  }
673 
674  if (pWndPrev)
675  UserDerefObjectCo(pWndPrev);
676 }
VOID IntFocusSetInputContext(PWND pWnd, BOOL bActivate, BOOL bCallback)
Definition: focus.c:150
#define QF_FOCUSNULLSINCEACTIVE
Definition: msgqueue.h:105
#define TRUE
Definition: types.h:120
#define IS_IMM_MODE()
Definition: ntuser.h:1232
VOID FASTCALL IntNotifyWinEvent(DWORD Event, PWND pWnd, LONG idObject, LONG idChild, DWORD flags)
Definition: event.c:179
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
UINT_PTR WPARAM
Definition: windef.h:207
#define FALSE
Definition: types.h:117
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
#define CHILDID_SELF
Definition: winable.h:14
THRDESKHEAD head
Definition: ntuser.h:690
Definition: object.h:3
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define OBJID_CLIENT
Definition: winable.h:19
#define WM_KILLFOCUS
Definition: winuser.h:1604
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1446
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define NULL
Definition: types.h:112
#define WM_SETFOCUS
Definition: winuser.h:1603

Referenced by co_IntSetActiveWindow(), and co_UserSetFocus().

◆ IntUserSetActiveWindow()

BOOL FASTCALL IntUserSetActiveWindow ( _In_ PWND  Wnd,
_In_ BOOL  bMouse,
_In_ BOOL  bFocus,
_In_ BOOL  Async 
)

Definition at line 1170 of file focus.c.

1175 {
1176  PTHREADINFO pti;
1177  PUSER_MESSAGE_QUEUE ThreadQueue;
1178 
1179  //ERR("IntUserSetActiveWindow 1\n");
1180  ASSERT_REFS_CO(Wnd);
1181  if ((Wnd->style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1182  //ERR("IntUserSetActiveWindow 1a hWnd 0x%p\n",UserHMGetHandle(Wnd));
1183 
1184  //ERR("IntUserSetActiveWindow 2\n");
1186  ThreadQueue = pti->MessageQueue;
1187  ASSERT(ThreadQueue != 0);
1188 
1189  while (Wnd)
1190  {
1191  BOOL Ret, DoFG, AllowFG;
1192 
1193  if (ThreadQueue == Wnd->head.pti->MessageQueue)
1194  {
1195  if (IsAllowedFGActive(pti, Wnd))
1196  {
1197  DoFG = TRUE;
1198  }
1199  else
1200  {
1201  //ERR("IntUserSetActiveWindow 3 Go Out!\n");
1202  break;
1203  }
1204  AllowFG = !pti->cVisWindows; // Nothing is visable.
1205  //ERR("IntUserSetActiveWindow 3a DoFG = %d AllowFG = %d\n",DoFG,AllowFG);
1206  }
1207  else //if (ThreadQueue != Wnd->head.pti->MessageQueue)
1208  {
1209  //PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue();
1210  // Rule 1 & 4, We are foreground so set this FG window or NULL foreground....
1211  if (!gpqForeground || gpqForeground == ThreadQueue)
1212  {
1213  DoFG = TRUE;
1214  }
1215  else
1216  DoFG = FALSE;
1217  if (DoFG)
1218  {
1220  AllowFG = TRUE;
1221  else
1222  AllowFG = FALSE;
1223  }
1224  else
1225  AllowFG = FALSE;
1226  //ERR("IntUserSetActiveWindow 3b DoFG = %d AllowFG = %d\n",DoFG,AllowFG);
1227  }
1228  Ret = FALSE;
1229  if (DoFG)
1230  {
1232  //ERR("IntUserSetActiveWindow 3c FG set\n");
1233  Ret = co_IntSetForegroundAndFocusWindow(Wnd, bMouse, TRUE);
1234  if (AllowFG)
1235  {
1237  }
1238  else
1239  {
1241  }
1242  }
1243  return Ret;
1244  }
1245 
1246  return co_IntSetActiveWindow(Wnd, bMouse, bFocus, Async);
1247 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
BOOL FASTCALL co_IntSetActiveWindow(_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
Definition: focus.c:1024
#define TRUE
Definition: types.h:120
#define ASSERT_REFS_CO(_obj_)
Definition: userfuncs.h:14
FLONG TIF_flags
Definition: win32.h:95
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define WS_CHILD
Definition: pedump.c:617
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TIF_ALLOWFOREGROUNDACTIVATE
Definition: ntuser.h:267
static BOOL FASTCALL co_IntSetForegroundAndFocusWindow(_In_opt_ PWND Wnd, _In_ BOOL MouseActivate, _In_ BOOL bFlash)
Definition: focus.c:924
#define ASSERT(a)
Definition: mode.c:44
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define WS_POPUP
Definition: pedump.c:616
UINT cVisWindows
Definition: win32.h:141
BOOL FASTCALL IsAllowedFGActive(PTHREADINFO pti, PWND Wnd)
Definition: focus.c:730

Referenced by co_IntSetForegroundAndFocusWindow(), and UserSetActiveWindow().

◆ IsAllowedFGActive()

BOOL FASTCALL IsAllowedFGActive ( PTHREADINFO  pti,
PWND  Wnd 
)

Definition at line 730 of file focus.c.

731 {
732  // Not allowed if one or more,,
733  if (!ToggleFGActivate(pti) || // bits not set,
734  pti->rpdesk != gpdeskInputDesktop || // not current Desktop,
735  pti->MessageQueue == gpqForeground || // if already the queue foreground,
736  IsFGLocked() || // foreground is locked,
737  (Wnd->ExStyle & WS_EX_NOACTIVATE)) // or, does not become the foreground window when the user clicks it.
738  {
739  return FALSE;
740  }
741  //ERR("IsAllowedFGActive is TRUE\n");
742  return TRUE;
743 }
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
DWORD ExStyle
Definition: ntuser.h:699
PDESKTOP gpdeskInputDesktop
Definition: desktop.c:35
#define TRUE
Definition: types.h:120
BOOL FASTCALL IsFGLocked(VOID)
Definition: focus.c:25
struct _DESKTOP * rpdesk
Definition: win32.h:92
#define FALSE
Definition: types.h:117
#define WS_EX_NOACTIVATE
Definition: winuser.h:395
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
BOOL FASTCALL ToggleFGActivate(PTHREADINFO pti)
Definition: focus.c:710

Referenced by co_UserSetFocus(), and IntUserSetActiveWindow().

◆ IsFGLocked()

BOOL FASTCALL IsFGLocked ( VOID  )

Definition at line 25 of file focus.c.

26 {
27  return (gppiLockSFW || guSFWLockCount);
28 }
PPROCESSINFO gppiLockSFW
Definition: focus.c:16
ULONG guSFWLockCount
Definition: focus.c:17

Referenced by co_IntSetForegroundAndFocusWindow(), and IsAllowedFGActive().

◆ NtUserGetForegroundWindow()

HWND APIENTRY NtUserGetForegroundWindow ( VOID  )

Definition at line 1648 of file focus.c.

1649 {
1651 
1652  TRACE("Enter NtUserGetForegroundWindow\n");
1654 
1656 
1657 CLEANUP:
1658  TRACE("Leave NtUserGetForegroundWindow, ret=%p\n",_ret_);
1659  UserLeave();
1660  END_CLEANUP;
1661 }
#define CLEANUP
Definition: ntuser.h:5
#define RETURN(x)
HWND FASTCALL UserGetForegroundWindow(VOID)
Definition: focus.c:1421
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
#define TRACE(s)
Definition: solgame.cpp:4
#define DECLARE_RETURN(type)
Definition: ntuser.h:3
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:254
#define END_CLEANUP
Definition: ntuser.h:6

Referenced by GetForegroundWindow().

◆ NtUserSetActiveWindow()

HWND APIENTRY NtUserSetActiveWindow ( HWND  hWnd)

Definition at line 1664 of file focus.c.

1665 {
1667  HWND hWndPrev;
1668  PWND Window, pwndPrev;
1670 
1671  TRACE("Enter NtUserSetActiveWindow(%p)\n", hWnd);
1673 
1674  Window = NULL;
1675  if (hWnd)
1676  {
1677  if (!(Window = UserGetWindowObject(hWnd)))
1678  {
1679  ERR("NtUserSetActiveWindow: Invalid handle 0x%p!\n",hWnd);
1680  RETURN( NULL);
1681  }
1682  }
1683 
1684  if (!Window ||
1685  Window->head.pti->MessageQueue == gptiCurrent->MessageQueue)
1686  {
1687  pwndPrev = gptiCurrent->MessageQueue->spwndActive;
1688  hWndPrev = (pwndPrev ? UserHMGetHandle(pwndPrev) : NULL);
1689  if (Window) UserRefObjectCo(Window, &Ref);
1692  RETURN(hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : NULL) : NULL);
1693  }
1694  RETURN( NULL);
1695 
1696 CLEANUP:
1697  TRACE("Leave NtUserSetActiveWindow, ret=%p\n",_ret_);
1698  UserLeave();
1699  END_CLEANUP;
1700 }
#define CLEANUP
Definition: ntuser.h:5
HWND hWnd
Definition: settings.c:17
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
BOOL FASTCALL UserSetActiveWindow(_In_opt_ PWND Wnd)
Definition: focus.c:1260
#define RETURN(x)
Definition: window.c:28
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
Definition: object.h:3
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:126
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define TRACE(s)
Definition: solgame.cpp:4
#define DECLARE_RETURN(type)
Definition: ntuser.h:3
BOOL FASTCALL IntIsWindow(HWND hWnd)
Definition: window.c:180
int Window
Definition: x11stubs.h:26
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:254
#define NULL
Definition: types.h:112
#define END_CLEANUP
Definition: ntuser.h:6

Referenced by SetActiveWindow().

◆ NtUserSetCapture()

HWND APIENTRY NtUserSetCapture ( HWND  hWnd)

Definition at line 1706 of file focus.c.

1707 {
1709 
1710  TRACE("Enter NtUserSetCapture(%p)\n", hWnd);
1712 
1714 
1715 CLEANUP:
1716  TRACE("Leave NtUserSetCapture, ret=%p\n", _ret_);
1717  UserLeave();
1718  END_CLEANUP;
1719 }
#define CLEANUP
Definition: ntuser.h:5
HWND hWnd
Definition: settings.c:17
#define RETURN(x)
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
#define TRACE(s)
Definition: solgame.cpp:4
HWND FASTCALL co_UserSetCapture(HWND hWnd)
Definition: focus.c:1458
#define DECLARE_RETURN(type)
Definition: ntuser.h:3
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:254
#define END_CLEANUP
Definition: ntuser.h:6

Referenced by SetCapture().

◆ NtUserSetFocus()

HWND APIENTRY NtUserSetFocus ( HWND  hWnd)

Definition at line 1725 of file focus.c.

1726 {
1727  PWND Window;
1730  HWND ret;
1731 
1732  TRACE("Enter NtUserSetFocus(%p)\n", hWnd);
1734 
1735  if (hWnd)
1736  {
1737  if (!(Window = UserGetWindowObject(hWnd)))
1738  {
1739  ERR("NtUserSetFocus: Invalid handle 0x%p!\n",hWnd);
1740  RETURN(NULL);
1741  }
1742 
1743  UserRefObjectCo(Window, &Ref);
1746 
1747  RETURN(ret);
1748  }
1749  else
1750  {
1751  RETURN( co_UserSetFocus(0));
1752  }
1753 
1754 CLEANUP:
1755  TRACE("Leave NtUserSetFocus, ret=%p\n",_ret_);
1756  UserLeave();
1757  END_CLEANUP;
1758 }
#define CLEANUP
Definition: ntuser.h:5
HWND FASTCALL co_UserSetFocus(PWND Window)
Definition: focus.c:1314
HWND hWnd
Definition: settings.c:17
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
#define RETURN(x)
Definition: window.c:28
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
Definition: object.h:3
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:126
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
#define TRACE(s)
Definition: solgame.cpp:4
#define DECLARE_RETURN(type)
Definition: ntuser.h:3
int Window
Definition: x11stubs.h:26
int ret
#define ERR(fmt,...)
Definition: debug.h:110
Definition: ntuser.h:688
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:254
#define NULL
Definition: types.h:112
#define END_CLEANUP
Definition: ntuser.h:6

Referenced by SetFocus().

◆ ToggleFGActivate()

BOOL FASTCALL ToggleFGActivate ( PTHREADINFO  pti)

Definition at line 710 of file focus.c.

711 {
712  BOOL Ret;
713  PPROCESSINFO ppi = pti->ppi;
714 
715  Ret = !!(pti->TIF_flags & TIF_ALLOWFOREGROUNDACTIVATE);
716  if (Ret)
717  {
719  }
720  else
721  Ret = !!(ppi->W32PF_flags & W32PF_ALLOWFOREGROUNDACTIVATE);
722 
723  if (Ret)
724  ppi->W32PF_flags &= ~W32PF_ALLOWFOREGROUNDACTIVATE;
725  //ERR("ToggleFGActivate is %d\n",Ret);
726  return Ret;
727 }
FLONG TIF_flags
Definition: win32.h:95
PPROCESSINFO ppi
Definition: win32.h:88
#define W32PF_ALLOWFOREGROUNDACTIVATE
Definition: win32.h:12
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TIF_ALLOWFOREGROUNDACTIVATE
Definition: ntuser.h:267

Referenced by co_IntSetForegroundAndFocusWindow(), and IsAllowedFGActive().

◆ UpdateShellHook()

VOID FASTCALL UpdateShellHook ( PWND  Window)

Definition at line 99 of file focus.c.

100 {
102  return;
103 
104  if ( Window->spwndParent == UserGetDesktopWindow() &&
105  (!(Window->ExStyle & WS_EX_TOOLWINDOW) ||
106  (Window->ExStyle & WS_EX_APPWINDOW)))
107  {
108  // FIXME lParam; The value is TRUE if the window is in full-screen mode, or FALSE otherwise.
109  co_IntShellHookNotify(HSHELL_WINDOWACTIVATED, (WPARAM) UserHMGetHandle(Window), FALSE);
110  }
111  else
112  {
113  co_IntShellHookNotify(HSHELL_WINDOWACTIVATED, 0, FALSE);
114  }
115 }
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_EX_TOOLWINDOW
Definition: winuser.h:404
Definition: window.c:28
#define FALSE
Definition: types.h:117
BOOL FASTCALL IntCheckFullscreen(PWND Window)
Definition: focus.c:79
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1386
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1692
#define WS_EX_APPWINDOW
Definition: winuser.h:383

Referenced by co_IntSendActivateMessages(), co_IntSetForegroundMessageQueue(), co_WinPosSetWindowPos(), and IntActivateWindow().

◆ UserGetActiveWindow()

HWND FASTCALL UserGetActiveWindow ( VOID  )

Definition at line 1429 of file focus.c.

1430 {
1431  PTHREADINFO pti;
1432  PUSER_MESSAGE_QUEUE ThreadQueue;
1433 
1435  ThreadQueue = pti->MessageQueue;
1436  return( ThreadQueue ? (ThreadQueue->spwndActive ? UserHMGetHandle(ThreadQueue->spwndActive) : 0) : 0);
1437 }
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89

Referenced by co_UserCreateWindowEx(), DefWndHandleSysCommand(), IntDefWindowProc(), NC_HandleNCLButtonDown(), and NtUserGetThreadState().

◆ UserGetForegroundWindow()

HWND FASTCALL UserGetForegroundWindow ( VOID  )

Definition at line 1421 of file focus.c.

1422 {
1423  PUSER_MESSAGE_QUEUE ForegroundQueue;
1424 
1425  ForegroundQueue = IntGetFocusMessageQueue();
1426  return( ForegroundQueue ? (ForegroundQueue->spwndActive ? UserHMGetHandle(ForegroundQueue->spwndActive) : 0) : 0);
1427 }
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1307
#define UserHMGetHandle(obj)
Definition: ntuser.h:230

Referenced by co_UserProcessHotKeys(), IntDefWindowProc(), NtUserGetForegroundWindow(), and WinPosFixupFlags().

◆ UserSetActiveWindow()

BOOL FASTCALL UserSetActiveWindow ( _In_opt_ PWND  Wnd)

Definition at line 1260 of file focus.c.

1261 {
1263 
1264  if (Wnd)
1265  {
1266  if ((Wnd->style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1267 
1268  return IntUserSetActiveWindow(Wnd, FALSE, TRUE, FALSE);
1269  }
1270  /*
1271  Yes your eye are not deceiving you~!
1272 
1273  First part of wines Win.c test_SetActiveWindow:
1274 
1275  flush_events( TRUE );
1276  ShowWindow(hwnd, SW_HIDE);
1277  SetFocus(0);
1278  SetActiveWindow(0);
1279  check_wnd_state(0, 0, 0, 0); <-- This should pass if ShowWindow does it's job!!! As of 10/28/2012 it does!
1280 
1281  Now Handle wines Msg.c test_SetActiveWindow( 0 )...
1282  */
1283  TRACE("USAW: Previous active window\n");
1284  if ( gpqForegroundPrev &&
1289  {
1290  TRACE("USAW:PAW hwnd %p\n",Wnd?Wnd->head.h:NULL);
1291  return IntUserSetActiveWindow(Wnd, FALSE, TRUE, FALSE);
1292  }
1293 
1294  // Activate anyone but the active window.
1295  if ( pti->MessageQueue->spwndActive &&
1296  (Wnd = VerifyWnd(pti->MessageQueue->spwndActive)) != NULL )
1297  {
1298  //ERR("USAW:AOWM hwnd %p\n",Wnd?Wnd->head.h:NULL);
1299  if (!ActivateOtherWindowMin(Wnd))
1300  {
1301  // Okay, now go find someone else to play with!
1302  //ERR("USAW: Going to WPAOW\n");
1304  }
1305  return TRUE;
1306  }
1307 
1308  TRACE("USAW: Nothing\n");
1309  return FALSE;
1310 }
#define WS_DISABLED
Definition: pedump.c:621
#define WNDS2_BOTTOMMOST
Definition: ntuser.h:641
BOOL FASTCALL IntUserSetActiveWindow(_In_ PWND Wnd, _In_ BOOL bMouse, _In_ BOOL bFocus, _In_ BOOL Async)
Definition: focus.c:1170
#define TRUE
Definition: types.h:120
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define WS_CHILD
Definition: pedump.c:617
VOID FASTCALL co_WinPosActivateOtherWindow(PWND Wnd)
Definition: winpos.c:396
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
BOOL FASTCALL ActivateOtherWindowMin(PWND Wnd)
Definition: winpos.c:284
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
#define WS_POPUP
Definition: pedump.c:616
#define NULL
Definition: types.h:112
PUSER_MESSAGE_QUEUE gpqForegroundPrev
Definition: focus.c:14
DWORD state2
Definition: ntuser.h:697
PWND FASTCALL VerifyWnd(PWND pWnd)
Definition: window.c:86
#define WS_VISIBLE
Definition: pedump.c:620
DWORD style
Definition: ntuser.h:701

Referenced by co_WinPosActivateOtherWindow(), NtUserCallTwoParam(), and NtUserSetActiveWindow().

Variable Documentation

◆ ghwndOldFullscreen

HWND ghwndOldFullscreen = NULL

Definition at line 19 of file focus.c.

Referenced by IntCheckFullscreen().

◆ gppiLockSFW

PPROCESSINFO gppiLockSFW = NULL

Definition at line 16 of file focus.c.

Referenced by IntLockSetForegroundWindow(), and IsFGLocked().

◆ gpqForeground

◆ gpqForegroundPrev

◆ gptiForeground

◆ guSFWLockCount

ULONG guSFWLockCount = 0

Definition at line 17 of file focus.c.

Referenced by IsFGLocked().

◆ ptiLastInput