mirror of
https://github.com/reactos/reactos.git
synced 2024-09-29 22:16:01 +00:00
[STOBJECT] Keep the object alive while the thread is running,
Fix shutting down the thread.
This commit is contained in:
parent
f10d40f912
commit
334c7cee35
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
|
#include <regstr.h>
|
||||||
#include <undocshell.h>
|
#include <undocshell.h>
|
||||||
#include <shellutils.h>
|
#include <shellutils.h>
|
||||||
|
|
||||||
|
@ -19,8 +20,14 @@ SysTrayIconHandlers_t g_IconHandlers [] = {
|
||||||
};
|
};
|
||||||
const int g_NumIcons = _countof(g_IconHandlers);
|
const int g_NumIcons = _countof(g_IconHandlers);
|
||||||
|
|
||||||
CSysTray::CSysTray() {}
|
CSysTray::CSysTray() : dwServicesEnabled(0)
|
||||||
CSysTray::~CSysTray() {}
|
{
|
||||||
|
wm_DESTROYWINDOW = RegisterWindowMessageW(L"CSysTray_DESTROY");
|
||||||
|
}
|
||||||
|
|
||||||
|
CSysTray::~CSysTray()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
VOID CSysTray::GetServicesEnabled()
|
VOID CSysTray::GetServicesEnabled()
|
||||||
{
|
{
|
||||||
|
@ -30,8 +37,7 @@ VOID CSysTray::GetServicesEnabled()
|
||||||
/* Enable power, volume and hotplug by default */
|
/* Enable power, volume and hotplug by default */
|
||||||
this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG | HOTPLUG_SERVICE_FLAG;
|
this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG | HOTPLUG_SERVICE_FLAG;
|
||||||
|
|
||||||
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
if (RegCreateKeyExW(HKEY_CURRENT_USER, REGSTR_PATH_SYSTRAY,
|
||||||
L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray",
|
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
REG_OPTION_NON_VOLATILE,
|
REG_OPTION_NON_VOLATILE,
|
||||||
|
@ -132,9 +138,9 @@ HRESULT CSysTray::ShutdownIcons()
|
||||||
{
|
{
|
||||||
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
||||||
{
|
{
|
||||||
|
this->dwServicesEnabled &= ~g_IconHandlers[i].dwServiceFlag;
|
||||||
HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
|
HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
|
||||||
if (FAILED(hr))
|
FAILED_UNEXPECTEDLY(hr);
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,12 +259,14 @@ HRESULT CSysTray::SysTrayThreadProc()
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
||||||
|
Release();
|
||||||
FreeLibraryAndExitThread(hLib, ret);
|
FreeLibraryAndExitThread(hLib, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT CSysTray::CreateSysTrayThread()
|
HRESULT CSysTray::CreateSysTrayThread()
|
||||||
{
|
{
|
||||||
TRACE("CSysTray Init TODO: Initialize tray icon handlers.\n");
|
TRACE("CSysTray Init TODO: Initialize tray icon handlers.\n");
|
||||||
|
AddRef();
|
||||||
|
|
||||||
HANDLE hThread = CreateThread(NULL, 0, s_SysTrayThreadProc, this, 0, NULL);
|
HANDLE hThread = CreateThread(NULL, 0, s_SysTrayThreadProc, this, 0, NULL);
|
||||||
|
|
||||||
|
@ -269,8 +277,11 @@ HRESULT CSysTray::CreateSysTrayThread()
|
||||||
|
|
||||||
HRESULT CSysTray::DestroySysTrayWindow()
|
HRESULT CSysTray::DestroySysTrayWindow()
|
||||||
{
|
{
|
||||||
DestroyWindow();
|
if (!DestroyWindow())
|
||||||
hwndSysTray = NULL;
|
{
|
||||||
|
// Window is from another thread, ask it politely to destroy itself:
|
||||||
|
SendMessage(wm_DESTROYWINDOW);
|
||||||
|
}
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,6 +314,10 @@ BOOL CSysTray::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
if (hWnd != m_hWnd)
|
if (hWnd != m_hWnd)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
if (wm_DESTROYWINDOW && uMsg == wm_DESTROYWINDOW)
|
||||||
|
{
|
||||||
|
return DestroyWindow();
|
||||||
|
}
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
case WM_NCCREATE:
|
case WM_NCCREATE:
|
||||||
|
@ -325,6 +340,7 @@ BOOL CSysTray::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
KillTimer(1);
|
KillTimer(1);
|
||||||
ShutdownIcons();
|
ShutdownIcons();
|
||||||
|
PostQuitMessage(0);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CSysTray :
|
||||||
// TODO: keep icon handlers here
|
// TODO: keep icon handlers here
|
||||||
|
|
||||||
DWORD dwServicesEnabled;
|
DWORD dwServicesEnabled;
|
||||||
HWND hwndSysTray;
|
UINT wm_DESTROYWINDOW;
|
||||||
|
|
||||||
static DWORD WINAPI s_SysTrayThreadProc(PVOID param);
|
static DWORD WINAPI s_SysTrayThreadProc(PVOID param);
|
||||||
HRESULT SysTrayMessageLoop();
|
HRESULT SysTrayMessageLoop();
|
||||||
|
|
Loading…
Reference in a new issue