Changed tray notifications to use 32x32 icon on Vista+

This commit is contained in:
Birunthan Mohanathas 2012-05-05 18:53:33 +03:00
parent a93c02ef84
commit 8d04988c12
6 changed files with 46 additions and 26 deletions

View File

@ -257,7 +257,7 @@ INT_PTR CDialogAbout::OnInitDialog(WPARAM wParam, LPARAM lParam)
HWND item = GetDlgItem(m_Window, IDCLOSE);
SendMessage(m_Window, WM_NEXTDLGCTL, (WPARAM)item, TRUE);
HICON hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
HICON hIcon = GetIcon(IDI_RAINMETER);
SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
if (*GetString(ID_STR_ISRTL) == L'1')
@ -1084,7 +1084,7 @@ void CDialogAbout::CTabVersion::Initialize()
m_Initialized = true;
HWND item = GetDlgItem(m_Window, IDC_ABOUTVERSION_RAINMETER_ICON);
HICON icon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, 32, 32, LR_SHARED);
HICON icon = GetIcon(IDI_RAINMETER, true);
Static_SetIcon(item, icon);
item = GetDlgItem(m_Window, IDC_ABOUTVERSION_VERSION_TEXT);

View File

@ -232,7 +232,7 @@ INT_PTR CDialogManage::OnInitDialog(WPARAM wParam, LPARAM lParam)
HWND item = GetDlgItem(m_Window, IDCLOSE);
SendMessage(m_Window, WM_NEXTDLGCTL, (WPARAM)item, TRUE);
HICON hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
HICON hIcon = GetIcon(IDI_RAINMETER);
SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
if (*GetString(ID_STR_ISRTL) == L'1')

View File

@ -337,6 +337,36 @@ std::wstring GetFormattedString(UINT id, ...)
return tmpSz;
}
HICON GetIcon(UINT id, bool large)
{
typedef HRESULT (WINAPI * FPLOADICONMETRIC)(HINSTANCE hinst, PCWSTR pszName, int lims, HICON* phico);
HINSTANCE hExe = GetModuleHandle(NULL);
HINSTANCE hComctl = GetModuleHandle(L"Comctl32");
if (hComctl)
{
// Try LoadIconMetric for better quality with high DPI
FPLOADICONMETRIC loadIconMetric = (FPLOADICONMETRIC)GetProcAddress(hComctl, "LoadIconMetric");
if (loadIconMetric)
{
HICON icon;
HRESULT hr = loadIconMetric(hExe, MAKEINTRESOURCE(id), large ? LIM_LARGE : LIM_SMALL, &icon);
if (SUCCEEDED(hr))
{
return icon;
}
}
}
return (HICON)LoadImage(
hExe,
MAKEINTRESOURCE(id),
IMAGE_ICON,
GetSystemMetrics(large ? SM_CXICON : SM_CXSMICON),
GetSystemMetrics(large ? SM_CYICON : SM_CYSMICON),
LR_SHARED);
}
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
{
// Do nothing.

View File

@ -54,6 +54,8 @@ void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin = fals
WCHAR* GetString(UINT id);
std::wstring GetFormattedString(UINT id, ...);
HICON GetIcon(UINT id, bool large = false);
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved);
#endif

View File

@ -24,6 +24,7 @@
#include "Rainmeter.h"
#include "DialogAbout.h"
#include "DialogManage.h"
#include "System.h"
#include "Error.h"
#include "RainmeterQuery.h"
#include "resource.h"
@ -86,7 +87,7 @@ void CTrayWindow::Initialize()
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);
wc.hIcon = GetIcon(IDI_RAINMETER);
RegisterClass(&wc);
@ -260,24 +261,7 @@ HICON CTrayWindow::CreateTrayIcon(double value)
}
// Return the default icon if there is no valid measure
HINSTANCE hExe = GetModuleHandle(NULL);
HINSTANCE hComctl = GetModuleHandle(L"Comctl32");
if (hComctl)
{
// Try LoadIconMetric for better quality with high DPI
FPLOADICONMETRIC loadIconMetric = (FPLOADICONMETRIC)GetProcAddress(hComctl, "LoadIconMetric");
if (loadIconMetric)
{
HICON icon;
HRESULT hr = loadIconMetric(hExe, MAKEINTRESOURCE(IDI_TRAY), LIM_SMALL, &icon);
if (SUCCEEDED(hr))
{
return icon;
}
}
}
return (HICON)LoadImage(hExe, MAKEINTRESOURCE(IDI_TRAY), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
return GetIcon(IDI_TRAY);
}
void CTrayWindow::ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text)
@ -290,10 +274,15 @@ void CTrayWindow::ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, con
nid.uFlags = NIF_INFO;
nid.uTimeout = 30000;
nid.dwInfoFlags = NIIF_USER;
nid.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, 32, 32, LR_SHARED);
wcsncpy_s(nid.szInfoTitle, title, _TRUNCATE);
wcsncpy_s(nid.szInfo, text, _TRUNCATE);
if (CSystem::GetOSPlatform() > OSPLATFORM_VISTA)
{
nid.dwInfoFlags |= NIIF_LARGE_ICON;
nid.hBalloonIcon = GetIcon(IDI_RAINMETER, true);
}
if (Shell_NotifyIcon(NIM_MODIFY, &nid))
{
m_Notification = id;

View File

@ -23,8 +23,6 @@
#include <gdiplus.h>
#include <vector>
typedef HRESULT (WINAPI * FPLOADICONMETRIC)(HINSTANCE hinst, PCWSTR pszName, int lims, HICON* phico);
#define WM_TRAY_NOTIFYICON WM_USER + 101
#define TRAYICON_SIZE 16
@ -69,11 +67,12 @@ private:
void ModifyTrayIcon(double value);
HICON CreateTrayIcon(double value);
HICON LoadResourceIcon(LPCWSTR name, bool large = false);
void ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text);
HICON m_Icon;
HWND m_Window;
HINSTANCE m_Instance;
CMeasure* m_Measure;
TRAY_METER_TYPE m_MeterType;