ReactOS 0.4.16-dev-1781-g8fabb29
closewnd.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Close windows after tests
5 * COPYRIGHT: Copyright 2024-2025 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#pragma once
9
10#define WaitForWindow(hWnd, Func, Seconds) \
11 for (UINT waited = 0; !Func(hWnd) && waited < (Seconds) * 1000; waited += 250) Sleep(250);
12
13typedef struct WINDOW_LIST
14{
18
19
21{
22 free(pList->m_phWnds);
23 pList->m_phWnds = NULL;
24 pList->m_chWnds = 0;
25}
26
28{
30 return TRUE;
31
33 SIZE_T cb = (pList->m_chWnds + 1) * sizeof(HWND);
34 HWND *phWnds = (HWND *)realloc(pList->m_phWnds, cb);
35 if (!phWnds)
36 return FALSE;
37 phWnds[pList->m_chWnds++] = hwnd;
38 pList->m_phWnds = phWnds;
39 return TRUE;
40}
41
43{
44 pList->m_phWnds = NULL;
45 pList->m_chWnds = 0;
47}
48
50{
52 pList->m_phWnds = NULL;
53 pList->m_chWnds = 0;
54 for (SIZE_T tries = 5, count; tries--;)
55 {
56 if (tries)
59 Sleep(250);
61 count = list.m_chWnds;
63 if (count == pList->m_chWnds)
64 break;
65 }
66}
67
69{
70 for (SIZE_T i = 0; i < list.m_chWnds; ++i)
71 {
72 if (list.m_phWnds[i] == hWnd)
73 return hWnd;
74 }
75 return NULL;
76}
77
78static inline VOID CloseNewWindows(PWINDOW_LIST pExisting, PWINDOW_LIST pNew)
79{
80 for (SIZE_T i = 0; i < pNew->m_chWnds; ++i)
81 {
82 HWND hWnd = pNew->m_phWnds[i];
83 if (!IsWindowVisible(hWnd) || FindInWindowList(*pExisting, hWnd))
84 continue;
85
88 /* If this window is still open, you'll need TerminateProcess(). */
89 }
90}
91
92#ifdef __cplusplus
93static inline VOID CloseNewWindows(PWINDOW_LIST InitialList)
94{
95 WINDOW_LIST newwindows;
96 GetWindowListForClose(&newwindows);
97 CloseNewWindows(InitialList, &newwindows);
98 FreeWindowList(&newwindows);
99}
100#endif
101
102static inline HWND FindNewWindow(PWINDOW_LIST List1, PWINDOW_LIST List2)
103{
104 for (SIZE_T i2 = 0; i2 < List2->m_chWnds; ++i2)
105 {
106 HWND hWnd = List2->m_phWnds[i2];
108 continue;
109
110 BOOL bFoundInList1 = FALSE;
111 for (SIZE_T i1 = 0; i1 < List1->m_chWnds; ++i1)
112 {
113 if (hWnd == List1->m_phWnds[i1])
114 {
115 bFoundInList1 = TRUE;
116 break;
117 }
118 }
119
120 if (!bFoundInList1)
121 return hWnd;
122 }
123 return NULL;
124}
125
127{
128 if (!IsWindowVisible(hwnd))
129 return TRUE;
130
131 *(PINT)lParam += 1;
132 return TRUE;
133}
134
135static inline INT GetWindowCount(VOID)
136{
137 INT nCount = 0;
139 return nCount;
140}
HWND hWnd
Definition: settings.c:17
Definition: list.h:37
static HWND FindNewWindow(PWINDOW_LIST List1, PWINDOW_LIST List2)
Definition: closewnd.h:102
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
Definition: closewnd.h:27
static VOID GetWindowListForClose(PWINDOW_LIST pList)
Definition: closewnd.h:49
static VOID FreeWindowList(PWINDOW_LIST pList)
Definition: closewnd.h:20
static BOOL CALLBACK CountVisibleWindowsProc(HWND hwnd, LPARAM lParam)
Definition: closewnd.h:126
static INT GetWindowCount(VOID)
Definition: closewnd.h:135
static HWND FindInWindowList(const WINDOW_LIST &list, HWND hWnd)
Definition: closewnd.h:68
struct WINDOW_LIST * PWINDOW_LIST
static VOID CloseNewWindows(PWINDOW_LIST pExisting, PWINDOW_LIST pNew)
Definition: closewnd.h:78
static VOID GetWindowList(PWINDOW_LIST pList)
Definition: closewnd.h:42
LPARAM lParam
Definition: combotst.c:139
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
unsigned int BOOL
Definition: ntddk_ex.h:94
FxChildList * pList
GLuint GLuint GLsizei count
Definition: gl.h:1545
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
LONG_PTR LPARAM
Definition: minwindef.h:175
int * PINT
Definition: minwindef.h:150
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
#define list
Definition: rosglue.h:35
SIZE_T m_chWnds
Definition: closewnd.h:15
HWND * m_phWnds
Definition: closewnd.h:16
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WM_CLOSE
Definition: winuser.h:1649
#define WM_SYSCOMMAND
Definition: winuser.h:1769
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define SMTO_BLOCK
Definition: winuser.h:1235
LRESULT WINAPI SendMessageTimeoutW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)
#define SC_CLOSE
Definition: winuser.h:2628
BOOL WINAPI IsWindowEnabled(_In_ HWND)
#define SMTO_ABORTIFHUNG
Definition: winuser.h:1234
BOOL WINAPI IsWindowVisible(_In_ HWND)