ReactOS 0.4.16-dev-1520-gb558596
closewnd.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  WINDOW_LIST
 

Macros

#define WaitForWindow(hWnd, Func, Seconds)    for (UINT waited = 0; !Func(hWnd) && waited < (Seconds) * 1000; waited += 250) Sleep(250);
 

Typedefs

typedef struct WINDOW_LIST WINDOW_LIST
 
typedef struct WINDOW_LISTPWINDOW_LIST
 

Functions

static BOOL WaitForForegroundWindow (HWND hWnd, UINT wait=500)
 
static VOID FreeWindowList (PWINDOW_LIST pList)
 
static BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
 
static VOID GetWindowList (PWINDOW_LIST pList)
 
static VOID GetWindowListForClose (PWINDOW_LIST pList)
 
static HWND FindInWindowList (const WINDOW_LIST &list, HWND hWnd)
 
static BOOL SendAltF4Input ()
 
static VOID CloseNewWindows (PWINDOW_LIST pExisting, PWINDOW_LIST pNew)
 
static HWND FindNewWindow (PWINDOW_LIST List1, PWINDOW_LIST List2)
 
static BOOL CALLBACK CountVisibleWindowsProc (HWND hwnd, LPARAM lParam)
 
static INT GetWindowCount (VOID)
 

Macro Definition Documentation

◆ WaitForWindow

#define WaitForWindow (   hWnd,
  Func,
  Seconds 
)     for (UINT waited = 0; !Func(hWnd) && waited < (Seconds) * 1000; waited += 250) Sleep(250);

Definition at line 10 of file closewnd.h.

Typedef Documentation

◆ PWINDOW_LIST

◆ WINDOW_LIST

Function Documentation

◆ CloseNewWindows()

static VOID CloseNewWindows ( PWINDOW_LIST  pExisting,
PWINDOW_LIST  pNew 
)
inlinestatic

Definition at line 101 of file closewnd.h.

102{
103 for (SIZE_T i = 0; i < pNew->m_chWnds; ++i)
104 {
105 HWND hWnd = pNew->m_phWnds[i];
106 if (!IsWindowVisible(hWnd) || FindInWindowList(*pExisting, hWnd))
107 continue;
108
110 WaitForForegroundWindow(hWnd); // SetForegroundWindow may take some time
114 {
115 if (WaitForForegroundWindow(hWnd)) // We can't fake keyboard input if the target is not foreground
116 {
118 WaitForWindow(hWnd, IsWindowVisible, 1); // Closing a window may take some time
119 }
120
122 {
123 CHAR szClass[64];
124 GetClassNameA(hWnd, szClass, _countof(szClass));
125 trace("Unable to close window %p (%s)\n", hWnd, szClass);
126 }
127 }
128 }
129}
#define trace
Definition: atltest.h:70
HWND hWnd
Definition: settings.c:17
static BOOL SendAltF4Input()
Definition: closewnd.h:90
#define WaitForWindow(hWnd, Func, Seconds)
Definition: closewnd.h:10
static BOOL WaitForForegroundWindow(HWND hWnd, UINT wait=500)
Definition: closewnd.h:13
static HWND FindInWindowList(const WINDOW_LIST &list, HWND hWnd)
Definition: closewnd.h:80
#define TRUE
Definition: types.h:120
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _countof(array)
Definition: sndvol32.h:70
SIZE_T m_chWnds
Definition: closewnd.h:27
HWND * m_phWnds
Definition: closewnd.h:28
uint32_t DWORD_PTR
Definition: typedefs.h:65
ULONG_PTR SIZE_T
Definition: typedefs.h:80
VOID WINAPI SwitchToThisWindow(HWND hwnd, BOOL fAltTab)
Definition: window.c:82
#define WM_SYSCOMMAND
Definition: winuser.h:1769
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
int WINAPI GetClassNameA(_In_ HWND hWnd, _Out_writes_to_(nMaxCount, return) LPSTR lpClassName, _In_ int nMaxCount)
LRESULT WINAPI SendMessageTimeoutW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
#define SC_CLOSE
Definition: winuser.h:2628
#define SMTO_ABORTIFHUNG
Definition: winuser.h:1234
BOOL WINAPI IsWindowVisible(_In_ HWND)
char CHAR
Definition: xmlstorage.h:175

Referenced by CloseNotepad(), CloseWindow(), START_TEST(), TEST_DoTestEntry(), TEST_End(), and TEST_ShellExecCmdLine().

◆ CountVisibleWindowsProc()

static BOOL CALLBACK CountVisibleWindowsProc ( HWND  hwnd,
LPARAM  lParam 
)
inlinestatic

Definition at line 165 of file closewnd.h.

166{
167 if (!IsWindowVisible(hwnd))
168 return TRUE;
169
170 *(PINT)lParam += 1;
171 return TRUE;
172}
LPARAM lParam
Definition: combotst.c:139
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
int * PINT
Definition: windef.h:177

Referenced by GetWindowCount().

◆ EnumWindowsProc()

static BOOL CALLBACK EnumWindowsProc ( HWND  hwnd,
LPARAM  lParam 
)
inlinestatic

Definition at line 39 of file closewnd.h.

40{
42 return TRUE;
43
45 SIZE_T cb = (pList->m_chWnds + 1) * sizeof(HWND);
46 HWND *phWnds = (HWND *)realloc(pList->m_phWnds, cb);
47 if (!phWnds)
48 return FALSE;
49 phWnds[pList->m_chWnds++] = hwnd;
50 pList->m_phWnds = phWnds;
51 return TRUE;
52}
struct WINDOW_LIST * PWINDOW_LIST
#define realloc
Definition: debug_ros.c:6
#define FALSE
Definition: types.h:117
FxChildList * pList
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33

Referenced by GetWindowList().

◆ FindInWindowList()

static HWND FindInWindowList ( const WINDOW_LIST list,
HWND  hWnd 
)
inlinestatic

Definition at line 80 of file closewnd.h.

81{
82 for (SIZE_T i = 0; i < list.m_chWnds; ++i)
83 {
84 if (list.m_phWnds[i] == hWnd)
85 return hWnd;
86 }
87 return NULL;
88}
Definition: list.h:37
#define NULL
Definition: types.h:112

Referenced by CloseNewWindows(), and CloseWindow().

◆ FindNewWindow()

static HWND FindNewWindow ( PWINDOW_LIST  List1,
PWINDOW_LIST  List2 
)
inlinestatic

Definition at line 141 of file closewnd.h.

142{
143 for (SIZE_T i2 = 0; i2 < List2->m_chWnds; ++i2)
144 {
145 HWND hWnd = List2->m_phWnds[i2];
147 continue;
148
149 BOOL bFoundInList1 = FALSE;
150 for (SIZE_T i1 = 0; i1 < List1->m_chWnds; ++i1)
151 {
152 if (hWnd == List1->m_phWnds[i1])
153 {
154 bFoundInList1 = TRUE;
155 break;
156 }
157 }
158
159 if (!bFoundInList1)
160 return hWnd;
161 }
162 return NULL;
163}
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI IsWindowEnabled(_In_ HWND)

Referenced by CloseNotepad().

◆ FreeWindowList()

static VOID FreeWindowList ( PWINDOW_LIST  pList)
inlinestatic

Definition at line 32 of file closewnd.h.

33{
34 free(pList->m_phWnds);
35 pList->m_phWnds = NULL;
36 pList->m_chWnds = 0;
37}
#define free
Definition: debug_ros.c:5

Referenced by CloseNotepad(), GetWindowListForClose(), START_TEST(), TEST_DoTestEntry(), TEST_End(), and TEST_ShellExecCmdLine().

◆ GetWindowCount()

static INT GetWindowCount ( VOID  )
inlinestatic

Definition at line 174 of file closewnd.h.

175{
176 INT nCount = 0;
178 return nCount;
179}
static BOOL CALLBACK CountVisibleWindowsProc(HWND hwnd, LPARAM lParam)
Definition: closewnd.h:165
int32_t INT
Definition: typedefs.h:58
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)

Referenced by TEST_End().

◆ GetWindowList()

static VOID GetWindowList ( PWINDOW_LIST  pList)
inlinestatic

Definition at line 54 of file closewnd.h.

55{
56 pList->m_phWnds = NULL;
57 pList->m_chWnds = 0;
59}
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
Definition: closewnd.h:39

Referenced by CloseNotepad(), GetWindowListForClose(), START_TEST(), TEST_DoTestEntry(), TEST_End(), TEST_ShellExecCmdLine(), and TEST_Start().

◆ GetWindowListForClose()

static VOID GetWindowListForClose ( PWINDOW_LIST  pList)
inlinestatic

Definition at line 61 of file closewnd.h.

62{
64 pList->m_phWnds = NULL;
65 pList->m_chWnds = 0;
66 for (SIZE_T tries = 5, count; tries--;)
67 {
68 if (tries)
71 Sleep(250);
73 count = list.m_chWnds;
75 if (count == pList->m_chWnds)
76 break;
77 }
78}
static VOID FreeWindowList(PWINDOW_LIST pList)
Definition: closewnd.h:32
static VOID GetWindowList(PWINDOW_LIST pList)
Definition: closewnd.h:54
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define list
Definition: rosglue.h:35
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

◆ SendAltF4Input()

static BOOL SendAltF4Input ( )
inlinestatic

Definition at line 90 of file closewnd.h.

91{
92 INPUT inputs[4];
93 ZeroMemory(&inputs, sizeof(inputs));
94 inputs[0].type = inputs[1].type = inputs[2].type = inputs[3].type = INPUT_KEYBOARD;
95 inputs[0].ki.wVk = inputs[3].ki.wVk = VK_LMENU;
96 inputs[1].ki.wVk = inputs[2].ki.wVk = VK_F4;
97 inputs[2].ki.dwFlags = inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
98 return SendInput(_countof(inputs), inputs, sizeof(INPUT)) == _countof(inputs);
99}
KEYBDINPUT ki
Definition: winable.h:62
DWORD type
Definition: winable.h:59
DWORD dwFlags
Definition: winable.h:49
WORD wVk
Definition: winable.h:47
UINT WINAPI SendInput(UINT, LPINPUT, int)
Definition: ntwrapper.h:344
#define INPUT_KEYBOARD
Definition: winable.h:10
#define ZeroMemory
Definition: winbase.h:1753
#define VK_F4
Definition: winuser.h:2294
#define KEYEVENTF_KEYUP
Definition: winuser.h:1113
#define VK_LMENU
Definition: winuser.h:2322

Referenced by CloseNewWindows().

◆ WaitForForegroundWindow()

static BOOL WaitForForegroundWindow ( HWND  hWnd,
UINT  wait = 500 
)
static

Definition at line 13 of file closewnd.h.

14{
15 for (UINT waited = 0, interval = 50; waited < wait; waited += interval)
16 {
18 return TRUE;
21 }
22 return FALSE;
23}
unsigned int UINT
Definition: ndis.h:50
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392

Referenced by CloseNewWindows().