1 #ifndef NEO_WINDOWMODAL_H
2 #define NEO_WINDOWMODAL_H
24 int DoModal(
bool blockEntireThread =
true);
31 bool IsModal() {
return modalLoopRunning; }
37 virtual void ProcessMessage(MSG* msg);
39 static BOOL CALLBACK CountEnabledWindows(HWND hwnd, LPARAM pBuffer);
40 static BOOL CALLBACK ListEnabledWindows(HWND hwnd, LPARAM pBuffer);
46 HwndBuffer(HWND pMyWindow)
58 void EnableWindows(BOOL enable)
60 for(
int i = 0; i < count; ++i)
61 EnableWindow(hwnds[i], enable);
70 bool modalLoopRunning;
78 modalLoopRunning =
false;
85 assert(!modalLoopRunning && GetHandle());
86 if(modalLoopRunning || GetHandle() == 0)
89 HWND parent =
reinterpret_cast<HWND
>(GetWindowLongPtr(GetHandle(), GWLP_HWNDPARENT));
92 HwndBuffer windowsToDisable(GetHandle());
96 EnumThreadWindows(GetCurrentThreadId(), CountEnabledWindows, (LPARAM)&windowsToDisable);
97 windowsToDisable.hwnds =
new HWND[windowsToDisable.count];
98 EnumThreadWindows(GetCurrentThreadId(), ListEnabledWindows, (LPARAM)&windowsToDisable);
99 windowsToDisable.EnableWindows(FALSE);
102 EnableWindow(parent, FALSE);
104 ShowWindow(GetHandle(), SW_SHOW);
107 modalLoopRunning =
true;
108 while(modalLoopRunning)
112 while(modalLoopRunning && PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
114 if(msg.message == WM_QUIT)
117 PostQuitMessage((
int)msg.wParam);
121 ProcessMessage(&msg);
126 if(blockEntireThread)
127 windowsToDisable.EnableWindows(TRUE);
129 EnableWindow(parent, TRUE);
131 BringWindowToTop(parent);
133 ShowWindow(GetHandle(), SW_HIDE);
140 modalLoopRunning =
false;
141 modalResult = result;
144 inline void WindowModal::ProcessMessage(MSG* msg)
147 if(!IsDialogMessage(GetHandle(), msg))
149 TranslateMessage(msg);
150 DispatchMessage(msg);
154 inline BOOL CALLBACK WindowModal::CountEnabledWindows(HWND hwnd, LPARAM pBuffer)
156 HwndBuffer* buffer = (HwndBuffer*)pBuffer;
157 if(buffer && buffer->myWindow != hwnd && (GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD) == 0 && IsWindowEnabled(hwnd))
162 inline BOOL CALLBACK WindowModal::ListEnabledWindows(HWND hwnd, LPARAM pBuffer)
164 HwndBuffer* buffer = (HwndBuffer*)pBuffer;
165 if(buffer && buffer->myWindow != hwnd && (GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD) == 0 && IsWindowEnabled(hwnd))
166 buffer->hwnds[buffer->filled++] = hwnd;
bool IsModal()
Definition: WindowModal.h:31
General purpose window.
Definition: Window.h:12
This window can enter a modal message loop.
Definition: WindowModal.h:13
static const int MODAL_ERROR
Definition: WindowModal.h:34
void EndModal(int result)
Definition: WindowModal.h:138
WindowModal()
Definition: WindowModal.h:76
int DoModal(bool blockEntireThread=true)
Definition: WindowModal.h:82