mirror of https://github.com/OpenVPN/openvpn-gui
Merge pull request #107 from selvanair/use-metric
Load icons at sizes given by DPI-dependent system metricpull/110/head
commit
9dd45d9ab6
|
@ -236,12 +236,22 @@ ShowLocalizedMsg(const UINT stringId, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
HICON
|
||||
LoadLocalizedIcon(const UINT iconId)
|
||||
static HICON
|
||||
LoadLocalizedIconEx(const UINT iconId, int cxDesired, int cyDesired)
|
||||
{
|
||||
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 */
|
||||
HRSRC res = FindResourceLang(RT_GROUP_ICON, MAKEINTRESOURCE(iconId), langId);
|
||||
if (res == NULL)
|
||||
|
@ -268,9 +278,29 @@ LoadLocalizedIcon(const UINT iconId)
|
|||
if (resSize == 0)
|
||||
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
|
||||
LocalizedDialogResource(const UINT dialogId)
|
||||
|
|
|
@ -28,6 +28,7 @@ int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...);
|
|||
void ShowLocalizedMsg(const UINT, ...);
|
||||
int ShowLocalizedMsgEx(const UINT, LPCTSTR, const UINT, ...);
|
||||
HICON LoadLocalizedIcon(const UINT);
|
||||
HICON LoadLocalizedSmallIcon(const UINT);
|
||||
LPCDLGTEMPLATE LocalizedDialogResource(const UINT);
|
||||
INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM);
|
||||
HWND CreateLocalizedDialogParam(const UINT, DLGPROC, const LPARAM);
|
||||
|
|
|
@ -1712,12 +1712,14 @@ SuspendOpenVPN(int config)
|
|||
void
|
||||
SetStatusWinIcon(HWND hwndDlg, int iconId)
|
||||
{
|
||||
HICON hIcon = LoadLocalizedIcon(iconId);
|
||||
HICON hIcon = LoadLocalizedSmallIcon(iconId);
|
||||
if (!hIcon)
|
||||
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_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.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
||||
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));
|
||||
|
||||
Shell_NotifyIcon(NIM_ADD, &ni);
|
||||
|
@ -291,7 +291,7 @@ SetTrayIcon(conn_state_t state)
|
|||
ni.cbSize = sizeof(ni);
|
||||
ni.uID = 0;
|
||||
ni.hWnd = o.hWnd;
|
||||
ni.hIcon = LoadLocalizedIcon(icon_id);
|
||||
ni.hIcon = LoadLocalizedSmallIcon(icon_id);
|
||||
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
||||
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
||||
_tcsncpy(ni.szTip, msg, _countof(ni.szTip));
|
||||
|
|
Loading…
Reference in New Issue