mirror of https://github.com/OpenVPN/openvpn-gui
Load icons at sizes given by DPI-dependent system metric
- Check system metric for large and small icon sizes and try to load the correct size instaed of scaling from one size. Scaling will still happen if the required size is not available in the icon resource. As we add more icon sizes they will get automatically used as needed. LoadImage scales up from next smallest size available. Revisit this when LoadIconWithScaleDown (Vista+) becomes available in mingw. Resolves Trac: #772 (icon scaling issue) Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/107/head
parent
270ea5f160
commit
2f2ddbf3a8
|
@ -236,12 +236,22 @@ ShowLocalizedMsg(const UINT stringId, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HICON
|
||||||
HICON
|
LoadLocalizedIconEx(const UINT iconId, int cxDesired, int cyDesired)
|
||||||
LoadLocalizedIcon(const UINT iconId)
|
|
||||||
{
|
{
|
||||||
LANGID langId = GetGUILanguage();
|
LANGID langId = GetGUILanguage();
|
||||||
|
|
||||||
|
HICON hIcon =
|
||||||
|
(HICON) LoadImage (o.hInstance, MAKEINTRESOURCE(iconId),
|
||||||
|
IMAGE_ICON, cxDesired, cyDesired, LR_DEFAULTSIZE|LR_SHARED);
|
||||||
|
if (hIcon)
|
||||||
|
return hIcon;
|
||||||
|
else
|
||||||
|
PrintDebug (L"Loading icon using LoadImage failed.");
|
||||||
|
|
||||||
|
/* Fallback to CreateIconFromResource which always scales
|
||||||
|
* from the first image in the resource
|
||||||
|
*/
|
||||||
/* find group icon resource */
|
/* find group icon resource */
|
||||||
HRSRC res = FindResourceLang(RT_GROUP_ICON, MAKEINTRESOURCE(iconId), langId);
|
HRSRC res = FindResourceLang(RT_GROUP_ICON, MAKEINTRESOURCE(iconId), langId);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
|
@ -268,9 +278,29 @@ LoadLocalizedIcon(const UINT iconId)
|
||||||
if (resSize == 0)
|
if (resSize == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return CreateIconFromResource(resInfo, resSize, TRUE, 0x30000);
|
/* Note: this uses the first icon in the resource and scales it */
|
||||||
|
hIcon = CreateIconFromResourceEx(resInfo, resSize, TRUE, 0x30000,
|
||||||
|
cxDesired, cyDesired, LR_DEFAULTSIZE|LR_SHARED);
|
||||||
|
return hIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HICON
|
||||||
|
LoadLocalizedIcon(const UINT iconId)
|
||||||
|
{
|
||||||
|
/* get the required normal icon size (e.g., taskbar icon) */
|
||||||
|
int cx = GetSystemMetrics(SM_CXICON);
|
||||||
|
int cy = GetSystemMetrics(SM_CYICON);
|
||||||
|
return LoadLocalizedIconEx(iconId, cx, cy);
|
||||||
|
}
|
||||||
|
|
||||||
|
HICON
|
||||||
|
LoadLocalizedSmallIcon(const UINT iconId)
|
||||||
|
{
|
||||||
|
/* get the required small icon size (e.g., tray icon) */
|
||||||
|
int cx = GetSystemMetrics(SM_CXSMICON);
|
||||||
|
int cy = GetSystemMetrics(SM_CYSMICON);
|
||||||
|
return LoadLocalizedIconEx(iconId, cx, cy);
|
||||||
|
}
|
||||||
|
|
||||||
LPCDLGTEMPLATE
|
LPCDLGTEMPLATE
|
||||||
LocalizedDialogResource(const UINT dialogId)
|
LocalizedDialogResource(const UINT dialogId)
|
||||||
|
|
|
@ -28,6 +28,7 @@ int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...);
|
||||||
void ShowLocalizedMsg(const UINT, ...);
|
void ShowLocalizedMsg(const UINT, ...);
|
||||||
int ShowLocalizedMsgEx(const UINT, LPCTSTR, const UINT, ...);
|
int ShowLocalizedMsgEx(const UINT, LPCTSTR, const UINT, ...);
|
||||||
HICON LoadLocalizedIcon(const UINT);
|
HICON LoadLocalizedIcon(const UINT);
|
||||||
|
HICON LoadLocalizedSmallIcon(const UINT);
|
||||||
LPCDLGTEMPLATE LocalizedDialogResource(const UINT);
|
LPCDLGTEMPLATE LocalizedDialogResource(const UINT);
|
||||||
INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM);
|
INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM);
|
||||||
HWND CreateLocalizedDialogParam(const UINT, DLGPROC, const LPARAM);
|
HWND CreateLocalizedDialogParam(const UINT, DLGPROC, const LPARAM);
|
||||||
|
|
|
@ -1712,12 +1712,14 @@ SuspendOpenVPN(int config)
|
||||||
void
|
void
|
||||||
SetStatusWinIcon(HWND hwndDlg, int iconId)
|
SetStatusWinIcon(HWND hwndDlg, int iconId)
|
||||||
{
|
{
|
||||||
HICON hIcon = LoadLocalizedIcon(iconId);
|
HICON hIcon = LoadLocalizedSmallIcon(iconId);
|
||||||
if (!hIcon)
|
if (!hIcon)
|
||||||
return;
|
return;
|
||||||
|
HICON hIconBig = LoadLocalizedIcon(ID_ICO_APP);
|
||||||
|
if (!hIconBig)
|
||||||
|
hIconBig = hIcon;
|
||||||
SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_SMALL, (LPARAM) hIcon);
|
SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_SMALL, (LPARAM) hIcon);
|
||||||
SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) hIcon);
|
SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) hIconBig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
4
tray.c
4
tray.c
|
@ -227,7 +227,7 @@ ShowTrayIcon()
|
||||||
ni.hWnd = o.hWnd;
|
ni.hWnd = o.hWnd;
|
||||||
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
||||||
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
||||||
ni.hIcon = LoadLocalizedIcon(ID_ICO_DISCONNECTED);
|
ni.hIcon = LoadLocalizedSmallIcon(ID_ICO_DISCONNECTED);
|
||||||
_tcsncpy(ni.szTip, LoadLocalizedString(IDS_TIP_DEFAULT), _countof(ni.szTip));
|
_tcsncpy(ni.szTip, LoadLocalizedString(IDS_TIP_DEFAULT), _countof(ni.szTip));
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_ADD, &ni);
|
Shell_NotifyIcon(NIM_ADD, &ni);
|
||||||
|
@ -291,7 +291,7 @@ SetTrayIcon(conn_state_t state)
|
||||||
ni.cbSize = sizeof(ni);
|
ni.cbSize = sizeof(ni);
|
||||||
ni.uID = 0;
|
ni.uID = 0;
|
||||||
ni.hWnd = o.hWnd;
|
ni.hWnd = o.hWnd;
|
||||||
ni.hIcon = LoadLocalizedIcon(icon_id);
|
ni.hIcon = LoadLocalizedSmallIcon(icon_id);
|
||||||
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
||||||
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
||||||
_tcsncpy(ni.szTip, msg, _countof(ni.szTip));
|
_tcsncpy(ni.szTip, msg, _countof(ni.szTip));
|
||||||
|
|
Loading…
Reference in New Issue