mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-12 02:18:12 +00:00
[idd] helper: correctly pump message and destroy window
This commit is contained in:
@@ -60,6 +60,9 @@ LRESULT CWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
onCreate();
|
onCreate();
|
||||||
return 0;
|
return 0;
|
||||||
|
case WM_NCDESTROY:
|
||||||
|
PostQuitMessage(0);
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
if (s_taskbarCreated && uMsg == s_taskbarCreated)
|
if (s_taskbarCreated && uMsg == s_taskbarCreated)
|
||||||
{
|
{
|
||||||
@@ -89,8 +92,18 @@ void CWindow::registerIcon()
|
|||||||
DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_ADD)");
|
DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_ADD)");
|
||||||
}
|
}
|
||||||
|
|
||||||
CWindow::~CWindow()
|
|
||||||
|
void CWindow::destroy()
|
||||||
{
|
{
|
||||||
if (m_hwnd)
|
if (m_hwnd)
|
||||||
|
{
|
||||||
DestroyWindow(m_hwnd);
|
DestroyWindow(m_hwnd);
|
||||||
|
m_hwnd = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CWindow::~CWindow()
|
||||||
|
{
|
||||||
|
destroy();
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ public:
|
|||||||
static bool registerClass();
|
static bool registerClass();
|
||||||
CWindow();
|
CWindow();
|
||||||
~CWindow();
|
~CWindow();
|
||||||
|
void destroy();
|
||||||
|
|
||||||
HWND hwnd() { return m_hwnd; }
|
HWND hwnd() { return m_hwnd; }
|
||||||
};
|
};
|
||||||
|
@@ -84,21 +84,31 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
|||||||
|
|
||||||
CWindow window;
|
CWindow window;
|
||||||
|
|
||||||
bool running = g_pipe.Init();
|
if (!g_pipe.Init())
|
||||||
while (running)
|
|
||||||
{
|
{
|
||||||
switch (MsgWaitForMultipleObjects(1, l_exitEvent.GetAddressOf(),
|
window.destroy();
|
||||||
|
l_exitEvent.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
switch (MsgWaitForMultipleObjects(
|
||||||
|
l_exitEvent.IsValid() ? 1 : 0,
|
||||||
|
l_exitEvent.GetAddressOf(),
|
||||||
FALSE, INFINITE, QS_ALLINPUT))
|
FALSE, INFINITE, QS_ALLINPUT))
|
||||||
{
|
{
|
||||||
case WAIT_OBJECT_0:
|
case WAIT_OBJECT_0:
|
||||||
running = false;
|
window.destroy();
|
||||||
|
l_exitEvent.Close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WAIT_OBJECT_0 + 1:
|
case WAIT_OBJECT_0 + 1:
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
if (GetMessage(&msg, NULL, 0, 0))
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
{
|
{
|
||||||
|
if (msg.message == WM_QUIT)
|
||||||
|
goto exit;
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
@@ -107,10 +117,11 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
|||||||
|
|
||||||
case WAIT_FAILED:
|
case WAIT_FAILED:
|
||||||
DEBUG_ERROR_HR(GetLastError(), "MsgWaitForMultipleObjects Failed");
|
DEBUG_ERROR_HR(GetLastError(), "MsgWaitForMultipleObjects Failed");
|
||||||
running = false;
|
goto exit;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
g_pipe.DeInit();
|
g_pipe.DeInit();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Reference in New Issue
Block a user