59728b4fabd5728eeb5d0784b2fbd81b8522714b
[reactos.git] / rostests / rosautotest / CDialogSurpass.cpp
1 /*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Class for managing all the configuration parameters
5 * COPYRIGHT: Copyright 2011
6 */
7
8 #include "precomp.h"
9
10 BOOL CALLBACK PrintWindow(HWND hwnd, LPARAM lParam)
11 {
12 CHAR WindowTitle[100];
13 int lenght;
14
15 lenght = GetWindowTextA(hwnd, WindowTitle, 100);
16 if(lenght == 0)
17 return TRUE;
18
19 StringOut( string(WindowTitle) + "\n" );
20
21 return TRUE;
22 }
23
24
25 void CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook,
26 DWORD event,
27 HWND hwnd,
28 LONG idObject,
29 LONG idChild,
30 DWORD dwEventThread,
31 DWORD dwmsEventTime)
32 {
33 /* make sure we got the correct event */
34 if(event == EVENT_SYSTEM_DIALOGSTART)
35 {
36 /* wait for some time to make sure that the dialog is hung */
37 Sleep(30 * 1000);
38
39 /* Check if it is still open */
40 if(IsWindow(hwnd))
41 {
42 /* Print an error message */
43 StringOut("Closing following dialog box:\n");
44 PrintWindow(hwnd, NULL);
45 EnumChildWindows(hwnd, PrintWindow, NULL);
46
47 /* Close the dialog */
48 SendMessage(hwnd, WM_CLOSE, 0, 0);
49 }
50 }
51 }
52
53
54 DWORD WINAPI DialogSurpassThread(LPVOID lpThreadParameter)
55 {
56 MSG dummy;
57
58 /* Install event notifications */
59 SetWinEventHook(EVENT_SYSTEM_DIALOGSTART,
60 EVENT_SYSTEM_DIALOGSTART,
61 NULL,
62 WinEventProc,
63 0,
64 0,
65 WINEVENT_OUTOFCONTEXT);
66
67 while(GetMessage(&dummy, 0,0,0))
68 {
69 /* There is no need to dispatch messages here */
70 /* Actually this block will never be executed */
71 }
72
73 return 0;
74 }
75
76 CDialogSurpass::CDialogSurpass()
77 {
78 /* Creat the trhead that will receive notifications */
79 hThread = CreateThread(NULL,
80 0,
81 DialogSurpassThread,
82 NULL,
83 0,
84 &ThreadID);
85 }
86
87 CDialogSurpass::~CDialogSurpass()
88 {
89 /* Notify the thread to close */
90 PostThreadMessage(ThreadID, WM_QUIT, 0, 0);
91
92 /* Wait for it close */
93 WaitForSingleObject(hThread, INFINITE);
94
95 /* Now close its handle*/
96 CloseHandle(hThread);
97 }