Skip to content

Commit 307ce1a

Browse files
committed
[SHELL32_APITEST] ShellExecuteEx: Introduce a CleanupNewlyCreatedWindows() helper similar to the one of the ShellExecCmdLine test.
1 parent 55c117c commit 307ce1a

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

modules/rostests/apitests/shell32/ShellExecuteEx.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ TestShellExecuteEx(const WCHAR* Name, BOOL ExpectedResult)
6767
{
6868
SHELLEXECUTEINFOW ShellExecInfo;
6969
BOOL Result;
70+
7071
ZeroMemory(&ShellExecInfo, sizeof(ShellExecInfo));
7172
ShellExecInfo.cbSize = sizeof(ShellExecInfo);
7273
ShellExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
7374
ShellExecInfo.hwnd = NULL;
7475
ShellExecInfo.nShow = SW_SHOWNORMAL;
7576
ShellExecInfo.lpFile = Name;
7677
ShellExecInfo.lpDirectory = NULL;
78+
7779
Result = ShellExecuteExW(&ShellExecInfo);
7880
ok(Result == ExpectedResult, "ShellExecuteEx lpFile %s failed. Error: %lu\n", wine_dbgstr_w(Name), GetLastError());
7981
if (ShellExecInfo.hProcess)
@@ -209,6 +211,27 @@ static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
209211
return TRUE;
210212
}
211213

214+
static void CleanupNewlyCreatedWindows(void)
215+
{
216+
EnumWindows(EnumWindowsProc, (LPARAM)&s_wi1);
217+
for (UINT i1 = 0; i1 < s_wi1.count; ++i1)
218+
{
219+
BOOL bFound = FALSE;
220+
for (UINT i0 = 0; i0 < s_wi0.count; ++i0)
221+
{
222+
if (s_wi1.phwnd[i1] == s_wi0.phwnd[i0])
223+
{
224+
bFound = TRUE;
225+
break;
226+
}
227+
}
228+
if (!bFound)
229+
PostMessageW(s_wi1.phwnd[i1], WM_CLOSE, 0, 0);
230+
}
231+
free(s_wi1.phwnd);
232+
ZeroMemory(&s_wi1, sizeof(s_wi1));
233+
}
234+
212235
static VOID DoTestEntry(const TEST_ENTRY *pEntry)
213236
{
214237
SHELLEXECUTEINFOA info = { sizeof(info) };
@@ -238,24 +261,7 @@ static VOID DoTestEntry(const TEST_ENTRY *pEntry)
238261

239262
WaitForInputIdle(info.hProcess, INFINITE);
240263

241-
// close newly opened windows
242-
EnumWindows(EnumWindowsProc, (LPARAM)&s_wi1);
243-
for (UINT i1 = 0; i1 < s_wi1.count; ++i1)
244-
{
245-
BOOL bFound = FALSE;
246-
for (UINT i0 = 0; i0 < s_wi0.count; ++i0)
247-
{
248-
if (s_wi1.phwnd[i1] == s_wi0.phwnd[i0])
249-
{
250-
bFound = TRUE;
251-
break;
252-
}
253-
}
254-
if (!bFound)
255-
PostMessageW(s_wi1.phwnd[i1], WM_CLOSE, 0, 0);
256-
}
257-
free(s_wi1.phwnd);
258-
ZeroMemory(&s_wi1, sizeof(s_wi1));
264+
CleanupNewlyCreatedWindows();
259265

260266
if (WaitForSingleObject(info.hProcess, 10 * 1000) == WAIT_TIMEOUT)
261267
{

0 commit comments

Comments
 (0)