This commit is contained in:
Birunthan Mohanathas 2012-05-05 15:59:35 +03:00
parent b33d59e9de
commit a93c02ef84
3 changed files with 118 additions and 114 deletions

View File

@ -1033,7 +1033,8 @@ int CRainmeter::Initialize(LPCWSTR szPath)
} }
// Tray must exist before configs are read // Tray must exist before configs are read
m_TrayWindow = new CTrayWindow(m_Instance); m_TrayWindow = new CTrayWindow();
m_TrayWindow->Initialize();
ReloadSettings(); ReloadSettings();

View File

@ -49,7 +49,7 @@ extern CRainmeter* Rainmeter;
using namespace Gdiplus; using namespace Gdiplus;
CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance), CTrayWindow::CTrayWindow() :
m_Icon(), m_Icon(),
m_Measure(), m_Measure(),
m_MeterType(TRAY_METER_TYPE_HISTOGRAM), m_MeterType(TRAY_METER_TYPE_HISTOGRAM),
@ -61,29 +61,6 @@ CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance),
m_Notification(TRAY_NOTIFICATION_NONE), m_Notification(TRAY_NOTIFICATION_NONE),
m_IconEnabled(true) m_IconEnabled(true)
{ {
WNDCLASS wc = {0};
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hInstance = instance;
wc.lpszClassName = L"RainmeterTrayClass";
wc.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_SHARED);
RegisterClass(&wc);
m_Window = CreateWindowEx(
WS_EX_TOOLWINDOW,
L"RainmeterTrayClass",
NULL,
WS_POPUP | WS_DISABLED,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
instance,
this);
SetWindowPos(m_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
} }
CTrayWindow::~CTrayWindow() CTrayWindow::~CTrayWindow()
@ -103,6 +80,33 @@ CTrayWindow::~CTrayWindow()
if (m_Window) DestroyWindow(m_Window); if (m_Window) DestroyWindow(m_Window);
} }
void CTrayWindow::Initialize()
{
WNDCLASS wc = {0};
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hInstance = Rainmeter->GetInstance();
wc.lpszClassName = L"RainmeterTrayClass";
wc.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_SHARED);
RegisterClass(&wc);
m_Window = CreateWindowEx(
WS_EX_TOOLWINDOW,
L"RainmeterTrayClass",
NULL,
WS_POPUP | WS_DISABLED,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
wc.hInstance,
this);
SetWindowPos(m_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
}
void CTrayWindow::AddTrayIcon() void CTrayWindow::AddTrayIcon()
{ {
if (m_Icon) if (m_Icon)
@ -437,100 +441,97 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
switch (uMsg) switch (uMsg)
{ {
case WM_COMMAND: case WM_COMMAND:
if (tray) if (wParam == IDM_MANAGE)
{ {
if (wParam == IDM_MANAGE) CDialogManage::Open();
{ }
CDialogManage::Open(); else if (wParam == IDM_ABOUT)
} {
else if (wParam == IDM_ABOUT) CDialogAbout::Open();
{ }
CDialogAbout::Open(); else if (wParam == IDM_SHOW_HELP)
} {
else if (wParam == IDM_SHOW_HELP) RunCommand(NULL, RAINMETER_HELP, SW_SHOWNORMAL);
{ }
RunCommand(NULL, RAINMETER_HELP, SW_SHOWNORMAL); else if (wParam == IDM_NEW_VERSION)
} {
else if (wParam == IDM_NEW_VERSION) RunCommand(NULL, RAINMETER_OFFICIAL, SW_SHOWNORMAL);
{ }
RunCommand(NULL, RAINMETER_OFFICIAL, SW_SHOWNORMAL); else if (wParam == IDM_REFRESH)
} {
else if (wParam == IDM_REFRESH) PostMessage(Rainmeter->GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
{ }
PostMessage(Rainmeter->GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL); else if (wParam == IDM_SHOWLOGFILE)
} {
else if (wParam == IDM_SHOWLOGFILE) Rainmeter->ShowLogFile();
{ }
Rainmeter->ShowLogFile(); else if (wParam == IDM_STARTLOG)
} {
else if (wParam == IDM_STARTLOG) Rainmeter->StartLogging();
{ }
Rainmeter->StartLogging(); else if (wParam == IDM_STOPLOG)
} {
else if (wParam == IDM_STOPLOG) Rainmeter->StopLogging();
{ }
Rainmeter->StopLogging(); else if (wParam == IDM_DELETELOGFILE)
} {
else if (wParam == IDM_DELETELOGFILE) Rainmeter->DeleteLogFile();
{ }
Rainmeter->DeleteLogFile(); else if (wParam == IDM_DEBUGLOG)
} {
else if (wParam == IDM_DEBUGLOG) Rainmeter->SetDebug(!Rainmeter->GetDebug());
{ }
Rainmeter->SetDebug(!Rainmeter->GetDebug()); else if (wParam == IDM_DISABLEDRAG)
} {
else if (wParam == IDM_DISABLEDRAG) Rainmeter->SetDisableDragging(!Rainmeter->GetDisableDragging());
{ }
Rainmeter->SetDisableDragging(!Rainmeter->GetDisableDragging()); else if (wParam == IDM_EDITCONFIG)
} {
else if (wParam == IDM_EDITCONFIG) Rainmeter->EditSettings();
{ }
Rainmeter->EditSettings(); else if (wParam == IDM_QUIT)
} {
else if (wParam == IDM_QUIT) PostQuitMessage(0);
{ }
PostQuitMessage(0); else if (wParam == IDM_OPENSKINSFOLDER)
} {
else if (wParam == IDM_OPENSKINSFOLDER) Rainmeter->OpenSkinFolder();
{ }
Rainmeter->OpenSkinFolder(); else if ((wParam & 0x0ffff) >= ID_THEME_FIRST && (wParam & 0x0ffff) <= ID_THEME_LAST)
} {
else if ((wParam & 0x0ffff) >= ID_THEME_FIRST && (wParam & 0x0ffff) <= ID_THEME_LAST) int pos = (wParam & 0x0ffff) - ID_THEME_FIRST;
{
int pos = (wParam & 0x0ffff) - ID_THEME_FIRST;
const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes(); const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes();
if (pos >= 0 && pos < (int)themes.size()) if (pos >= 0 && pos < (int)themes.size())
{
Rainmeter->LoadTheme(themes[pos]);
}
}
else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST)
{ {
std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex((UINT)(wParam & 0x0ffff)); Rainmeter->LoadTheme(themes[pos]);
if (indexes.first != -1 && indexes.second != -1)
{
Rainmeter->ToggleConfig(indexes.first, indexes.second);
}
} }
else }
else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST)
{
std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex((UINT)(wParam & 0x0ffff));
if (indexes.first != -1 && indexes.second != -1)
{ {
// Forward the message to correct window Rainmeter->ToggleConfig(indexes.first, indexes.second);
int index = (int)(wParam >> 16); }
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows(); }
else
{
// Forward the message to correct window
int index = (int)(wParam >> 16);
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
if (index < (int)windows.size()) if (index < (int)windows.size())
{
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for ( ; iter != windows.end(); ++iter)
{ {
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin(); --index;
for ( ; iter != windows.end(); ++iter) if (index < 0)
{ {
--index; CMeterWindow* meterWindow = (*iter).second;
if (index < 0) SendMessage(meterWindow->GetWindow(), WM_COMMAND, wParam & 0x0FFFF, NULL);
{ break;
CMeterWindow* meterWindow = (*iter).second;
SendMessage(meterWindow->GetWindow(), WM_COMMAND, wParam & 0x0FFFF, NULL);
break;
}
} }
} }
} }
@ -660,7 +661,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
return 1; return 1;
case WM_TIMER: case WM_TIMER:
if (tray && tray->m_Measure) if (tray->m_Measure)
{ {
tray->m_Measure->Update(); tray->m_Measure->Update();
tray->ModifyTrayIcon(tray->m_Measure->GetRelativeValue()); tray->ModifyTrayIcon(tray->m_Measure->GetRelativeValue());
@ -674,7 +675,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
default: default:
if (uMsg == WM_TASKBARCREATED) if (uMsg == WM_TASKBARCREATED)
{ {
if (tray && tray->IsTrayIconEnabled()) if (tray->IsTrayIconEnabled())
{ {
tray->RemoveTrayIcon(); tray->RemoveTrayIcon();
tray->AddTrayIcon(); tray->AddTrayIcon();

View File

@ -41,9 +41,11 @@ class CMeasure;
class CTrayWindow class CTrayWindow
{ {
public: public:
CTrayWindow(HINSTANCE instance); CTrayWindow();
~CTrayWindow(); ~CTrayWindow();
void Initialize();
void ReadConfig(CConfigParser& parser); void ReadConfig(CConfigParser& parser);
HWND GetWindow() { return m_Window; } HWND GetWindow() { return m_Window; }
bool IsTrayIconEnabled() { return m_IconEnabled; } bool IsTrayIconEnabled() { return m_IconEnabled; }