From 9fb8fc3300b71abc543774f08f9150aac1670eb5 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Sat, 29 May 2010 04:27:26 +0000 Subject: Reduced resource usage git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@520 4f64403b-2f21-0410-a795-97e2b3489a10 --- worldtime/plugwin.cpp | 100 +++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 58 deletions(-) (limited to 'worldtime/plugwin.cpp') diff --git a/worldtime/plugwin.cpp b/worldtime/plugwin.cpp index 690cefe..e20030d 100644 --- a/worldtime/plugwin.cpp +++ b/worldtime/plugwin.cpp @@ -8,8 +8,6 @@ COLORREF ContactFontColour; FontID font_id; // for use with FontService plugin -HANDLE mainThread; - HBRUSH tbrush = 0; HANDLE mainMenuItem, hIconsChangedEvent, hDBChange, hIcoLibIconsChanged; @@ -758,59 +756,49 @@ static INT_PTR PlugShowWindow(WPARAM wParam, LPARAM lParam) { return 0; } -int InitIcons(WPARAM wParam, LPARAM lParam) { - if(ServiceExists(MS_SKIN2_ADDICON)) { - SKINICONDESC sid = {0}; - - sid.cbSize = sizeof(SKINICONDESC); - sid.pszSection = "WorldTime"; - - sid.pszDescription = Translate("Day"); - sid.pszName = "WorldTime_day"; - sid.pszDefaultFile = "WorldTime.dll"; - sid.iDefaultIndex = IDI_ICON_SUN; - sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUN), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); - - sid.pszDescription = Translate("Night"); - sid.pszName = "WorldTime_night"; - sid.pszDefaultFile = "WorldTime.dll"; - sid.iDefaultIndex = IDI_ICON_MOON; - sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_MOON), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); - - sid.pszDescription = Translate("Sunrise"); - sid.pszName = "WorldTime_sunrise"; - sid.pszDefaultFile = "WorldTime.dll"; - sid.iDefaultIndex = IDI_ICON_SUNRISE; - sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUNRISE), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); - - sid.pszDescription = Translate("Sunset"); - sid.pszName = "WorldTime_sunset"; - sid.pszDefaultFile = "WorldTime.dll"; - sid.iDefaultIndex = IDI_ICON_SUNSET; - sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUNSET), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); - - upIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_day"); - downIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_night"); - riseIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunrise"); - setIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunset"); - } else { - upIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUN), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - downIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_MOON), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - riseIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUN), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - setIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_MOON), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); - } - return 0; -} - -int ReloadIcons(WPARAM wParam, LPARAM lParam) { +int ReloadIcons(WPARAM wParam, LPARAM lParam) +{ upIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_day"); downIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_night"); riseIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunrise"); setIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunset"); + + return 0; +} + +int InitIcons(WPARAM wParam, LPARAM lParam) +{ + SKINICONDESC sid = {0}; + + TCHAR szFile[MAX_PATH]; + GetModuleFileName(hInst, szFile, SIZEOF(szFile)); + + sid.cbSize = sizeof(SKINICONDESC); + sid.pszSection = "WorldTime"; + sid.ptszDefaultFile = szFile; + sid.flags = SIDF_PATH_TCHAR; + + sid.pszDescription = "Day"; + sid.pszName = "WorldTime_day"; + sid.iDefaultIndex = -IDI_ICON_SUN; + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + sid.pszDescription = "Night"; + sid.pszName = "WorldTime_night"; + sid.iDefaultIndex = -IDI_ICON_MOON; + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + sid.pszDescription = "Sunrise"; + sid.pszName = "WorldTime_sunrise"; + sid.iDefaultIndex = -IDI_ICON_SUNRISE; + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + sid.pszDescription = "Sunset"; + sid.pszName = "WorldTime_sunset"; + sid.iDefaultIndex = -IDI_ICON_SUNSET; + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + ReloadIcons(0, 0); return 0; } @@ -1070,9 +1058,9 @@ LRESULT CALLBACK NullWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM return DefWindowProc(hWnd, message, wParam, lParam); } -void CALLBACK sttMainThreadCallback( ULONG_PTR dwParam ) +void CALLBACK sttMainThreadCallback(void* pParam) { - POPUPDATAT* ppd = ( POPUPDATAT* )dwParam; + POPUPDATAT* ppd = (POPUPDATAT*)pParam; CallService( MS_POPUP_ADDPOPUPT, ( WPARAM )ppd, 0 ); free( ppd ); @@ -1099,7 +1087,7 @@ void __stdcall ShowPopup( const TCHAR* line1, const TCHAR* line2, int flags ) ppd->PluginWindowProc = ( WNDPROC )NullWindowProc; ppd->PluginData = NULL; - QueueUserAPC( sttMainThreadCallback , mainThread, ( ULONG_PTR )ppd ); + CallFunctionAsync(sttMainThreadCallback, ppd); } void plugwin_cleanup() { @@ -1114,8 +1102,4 @@ void plugwin_cleanup() { DeleteCriticalSection(&cs2); DeleteObject(ContactFont); - DestroyIcon((HICON)upIcon); - DestroyIcon((HICON)upIcon); - DestroyIcon((HICON)riseIcon); - DestroyIcon((HICON)setIcon); } \ No newline at end of file -- cgit v1.2.3