From 4ddea205205f8172cef709752fa723db743b4316 Mon Sep 17 00:00:00 2001
From: George Hazan <ghazan@miranda.im>
Date: Thu, 10 Jun 2021 19:13:40 +0300
Subject: =?UTF-8?q?fixes=20#2886=20(=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B8?=
 =?UTF-8?q?=D0=B5=20=D0=B8=D0=BA=D0=BE=D0=BD=D0=BA=D0=B8=20=D0=B4=D0=BB?=
 =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B3=D0=BE=D0=B4=D1=8B=20=D0=B2=D0=BE=20?=
 =?UTF-8?q?=D0=B2=D1=81=D0=BF=D0=BE=D0=BC=D0=BE=D0=B3=D0=B0=D1=82=D0=B5?=
 =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BE=D0=BA=D0=BD=D0=B0=D1=85?=
 =?UTF-8?q?)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 protocols/Weather/src/stdafx.h             |  1 +
 protocols/Weather/src/weather.cpp          |  4 +++-
 protocols/Weather/src/weather_svcs.cpp     | 14 ++++++++++++++
 protocols/Weather/src/weather_userinfo.cpp | 15 ++++++++++-----
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h
index a734e91a14..10b851e826 100644
--- a/protocols/Weather/src/stdafx.h
+++ b/protocols/Weather/src/stdafx.h
@@ -394,6 +394,7 @@ void GetElev(wchar_t *tempchar, wchar_t *unit, wchar_t *str);
 void ClearStatusIcons();
 int MapCondToStatus(MCONTACT hContact);
 HICON GetStatusIcon(MCONTACT hContact);
+HICON GetStatusIconBig(MCONTACT hContact);
 
 WORD GetIcon(const wchar_t* cond, WIDATA *Data);
 void CaseConv(wchar_t *str);
diff --git a/protocols/Weather/src/weather.cpp b/protocols/Weather/src/weather.cpp
index bb2a7cbbd0..259426957b 100644
--- a/protocols/Weather/src/weather.cpp
+++ b/protocols/Weather/src/weather.cpp
@@ -55,6 +55,8 @@ BOOL ThreadRunning;
 // variable to determine if module loaded
 BOOL ModuleLoaded = FALSE;
 
+VARSW g_pwszIconsName(L"%miranda_path%\\Icons\\proto_Weather.dll");
+
 HANDLE hTBButton = nullptr;
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -159,7 +161,7 @@ int CMPlugin::Load()
 	g_plugin.registerIcon(MODULENAME, iconList, MODULENAME);
 
 	// load dll with icons
-	hIconsDll = LoadLibraryW(VARSW(L"%miranda_path%\\Icons\\proto_Weather.dll"));
+	hIconsDll = LoadLibraryW(g_pwszIconsName);
 
 	// load options and set defaults
 	LoadOptions();
diff --git a/protocols/Weather/src/weather_svcs.cpp b/protocols/Weather/src/weather_svcs.cpp
index 7fa2b40000..2d143d5172 100644
--- a/protocols/Weather/src/weather_svcs.cpp
+++ b/protocols/Weather/src/weather_svcs.cpp
@@ -29,6 +29,8 @@ building/changing the weather menu items.
 static HGENMENU hEnableDisablePopupMenu;
 static HGENMENU hEnableDisableMenu;
 
+extern VARSW g_pwszIconsName;
+
 //============  MIRANDA PROTOCOL SERVICES  ============
 
 // protocol service function for setting weather protocol status
@@ -230,6 +232,18 @@ HICON GetStatusIcon(MCONTACT hContact)
 	return ImageList_GetIcon(Clist_GetImageList(), pIcon.clistIconId, ILD_NORMAL);
 }
 
+HICON GetStatusIconBig(MCONTACT hContact)
+{
+	int iCond = g_plugin.getWord(hContact, "StatusIcon", -1);
+	if (iCond < 0 || iCond >= MAX_COND)
+		return nullptr;
+
+	HICON hIcon;
+	auto &pIcon = statusIcons[iCond];
+	ExtractIconExW(g_pwszIconsName, -pIcon.iconIdx, &hIcon, 0, 1);
+	return hIcon;
+}
+
 static INT_PTR WeatherAdvancedStatusIcon(WPARAM hContact, LPARAM)
 {
 	if (!hContact || !g_plugin.hIconsDll)
diff --git a/protocols/Weather/src/weather_userinfo.cpp b/protocols/Weather/src/weather_userinfo.cpp
index 0f69dfa42c..e0420d48bf 100644
--- a/protocols/Weather/src/weather_userinfo.cpp
+++ b/protocols/Weather/src/weather_userinfo.cpp
@@ -130,8 +130,11 @@ static INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, L
 		DBDataManage(hContact, WDBM_DETAILDISPLAY, (WPARAM)hwndDlg, 0);
 
 		// set icons
-		Window_FreeIcon_IcoLib(hwndDlg);
-		Window_SetProtoIcon_IcoLib(hwndDlg, MODULENAME, MapCondToStatus(hContact));
+		{
+			HICON hIcon = GetStatusIconBig(hContact);
+			DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, LPARAM(hIcon)));
+			DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, LPARAM(hIcon)));
+		}
 
 		RedrawWindow(GetDlgItem(hwndDlg, IDC_HEADERBAR), nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
 		break;
@@ -225,7 +228,9 @@ static INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, L
 		break;
 
 	case WM_DESTROY:
-		Window_FreeIcon_IcoLib(hwndDlg);
+		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
+		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
+
 		Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "BriefInfo_");
 		WindowList_Remove(hDataWindowList, hwndDlg);
 		break;
@@ -253,7 +258,7 @@ static INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
 		w = LoadWeatherInfo(lParam);
 		SetDlgItemText(hwndDlg, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str));
 
-		SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, (WPARAM)Skin_LoadProtoIcon(MODULENAME, MapCondToStatus(hContact)), 0);
+		SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, (WPARAM)GetStatusIconBig(hContact), 0);
 		{
 			// bold and enlarge the current condition
 			LOGFONT lf;
@@ -283,7 +288,7 @@ static INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
 		break;
 
 	case WM_DESTROY:
-		IcoLib_ReleaseIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, 0, 0));
+		DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, 0, 0));
 		DeleteObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0));
 		break;
 
-- 
cgit v1.2.3