From 13b3241307eb7b4c87137c0bf4d6f7f763078001 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 9 Dec 2011 08:40:19 +0000 Subject: [PATCH] Minor tweaks and cleanup. --- Library/DialogAbout.cpp | 6 ++---- Library/DialogManage.cpp | 8 +++----- Library/Measure.cpp | 10 ---------- Library/Measure.h | 2 -- Library/MeasureCalc.cpp | 2 -- Library/Meter.cpp | 4 +--- Library/Rainmeter.h | 2 +- Library/System.cpp | 15 ++++++--------- Library/TrayWindow.cpp | 32 +++++++++++++++----------------- 9 files changed, 28 insertions(+), 53 deletions(-) diff --git a/Library/DialogAbout.cpp b/Library/DialogAbout.cpp index a2c12885..3b60a9b5 100644 --- a/Library/DialogAbout.cpp +++ b/Library/DialogAbout.cpp @@ -366,7 +366,7 @@ void CDialogAbout::CTabLog::Initialize() // Set folder/.ini icons for tree list HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR32, 2, 10); - HMODULE hDLL = LoadLibrary(L"user32.dll"); + HMODULE hDLL = GetModuleHandle(L"user32"); HICON hIcon = (HICON)LoadImage(hDLL, MAKEINTRESOURCE(103), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); ImageList_AddIcon(hImageList, hIcon); @@ -380,8 +380,6 @@ void CDialogAbout::CTabLog::Initialize() ImageList_AddIcon(hImageList, hIcon); DeleteObject(hIcon); - FreeLibrary(hDLL); - ListView_SetImageList(item, (WPARAM)hImageList, LVSIL_SMALL); LVCOLUMN lvc; @@ -757,7 +755,7 @@ void CDialogAbout::CTabMeasures::UpdateMeasureList(CMeterWindow* meterWindow) range += buffer; ListView_SetItemText(item, index, 1, (WCHAR*)range.c_str()); - ListView_SetItemText(item, index, 2, (WCHAR*)(*j)->GetStats()); + ListView_SetItemText(item, index, 2, (WCHAR*)(*j)->GetStringValue(AUTOSCALE_OFF, 1, -1, false)); ++index; } diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index c06fd361..ed7be129 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -369,15 +369,13 @@ void CDialogManage::CTabSkins::Initialize() // Load folder/.ini icons from shell32 HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR32, 2, 10); - HMODULE hDLL = LoadLibrary(L"shell32.dll"); + HMODULE hDLL = GetModuleHandle(L"shell32"); HICON hIcon = (HICON)LoadImage(hDLL, MAKEINTRESOURCE(4), IMAGE_ICON, 16, 16, LR_SHARED); ImageList_AddIcon(hImageList, hIcon); hIcon = (HICON)LoadImage(hDLL, MAKEINTRESOURCE(151), IMAGE_ICON, 16, 16, LR_SHARED); ImageList_AddIcon(hImageList, hIcon); - FreeLibrary(hDLL); - // Apply icons and populate tree item = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); TreeView_SetImageList(item, hImageList, TVSIL_NORMAL); @@ -1394,10 +1392,10 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) if (HIWORD(wParam) == EN_CHANGE) { WCHAR buffer[32]; - Edit_GetText((HWND)lParam, buffer, 32); + int len = Edit_GetText((HWND)lParam, buffer, 32); // Disable save button if no text or if name is "Backup" - BOOL state = (wcslen(buffer) != 0 && _wcsicmp(buffer, L"Backup") != 0); + BOOL state = (len > 0 && _wcsicmp(buffer, L"Backup") != 0); EnableWindow(GetDlgItem(m_Window, IDC_MANAGETHEMES_SAVE_BUTTON), state); } break; diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 079d83d2..3d8929ce 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -759,16 +759,6 @@ void CMeasure::RemoveTrailingZero(WCHAR* str, int strLen) } } -/* -** GetStats -** -** Returns the stats as string. The stats are shown in the About dialog. -*/ -const WCHAR* CMeasure::GetStats() -{ - return GetStringValue(AUTOSCALE_OFF, 1, -1, false); -} - /* ** Create ** diff --git a/Library/Measure.h b/Library/Measure.h index 6736ea6c..a37687d3 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -52,8 +52,6 @@ public: virtual void Initialize(); virtual bool Update() = 0; - virtual const WCHAR* GetStats(); - const WCHAR* GetName() { return m_Name.c_str(); } const std::wstring& GetOriginalName() { return m_Name; } const char* GetAsciiName() { return m_AsciiName.c_str(); } diff --git a/Library/MeasureCalc.cpp b/Library/MeasureCalc.cpp index bce60ffb..939070fa 100644 --- a/Library/MeasureCalc.cpp +++ b/Library/MeasureCalc.cpp @@ -20,8 +20,6 @@ #include "MeasureCalc.h" #include "Rainmeter.h" -using namespace std; - hqStrMap* CMeasureCalc::c_VarMap = NULL; bool CMeasureCalc::c_RandSeeded = false; diff --git a/Library/Meter.cpp b/Library/Meter.cpp index a41ef5d1..ad0e1cff 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -635,9 +635,7 @@ bool CMeter::ReplaceMeasures(const std::vector& stringValues, std: // Create the actual text (i.e. replace %1, %2, .. with the measure texts) for (size_t i = stringValues.size(); i > 0; --i) { - _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i); - - size_t len = wcslen(buffer); + size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i); size_t start = 0, pos; do { diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index f31d9b03..14d93365 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -276,7 +276,7 @@ private: bool m_DisableVersionCheck; bool m_NewVersion; - + bool m_DesktopWorkAreaChanged; bool m_DesktopWorkAreaType; // If true, DesktopWorkArea is treated as "margin" std::map m_DesktopWorkAreas; diff --git a/Library/System.cpp b/Library/System.cpp index 0c740e1f..160b69c8 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -1157,16 +1157,13 @@ void CSystem::SetClipboardText(const std::wstring& text) if (hMem) { LPVOID data = GlobalLock(hMem); - if (data) - { - memcpy(data, text.c_str(), len * sizeof(WCHAR)); - GlobalUnlock(hMem); + memcpy(data, text.c_str(), len * sizeof(WCHAR)); + GlobalUnlock(hMem); - EmptyClipboard(); - if (!SetClipboardData(CF_UNICODETEXT, hMem)) - { - GlobalFree(hMem); - } + EmptyClipboard(); + if (!SetClipboardData(CF_UNICODETEXT, hMem)) + { + GlobalFree(hMem); } } diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index aded1c5f..cdc056da 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -410,20 +410,7 @@ void CTrayWindow::ReadConfig(CConfigParser& parser) LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - static CTrayWindow* tray = NULL; - - if (uMsg == WM_CREATE) - { - tray=(CTrayWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams; - } - else if (uMsg == WM_TASKBARCREATED) - { - if (tray && tray->IsTrayIconEnabled()) - { - tray->RemoveTrayIcon(); - tray->AddTrayIcon(); - } - } + CTrayWindow* tray = Rainmeter->GetTrayWindow(); switch (uMsg) { @@ -778,15 +765,15 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA case WM_COPYDATA: { - COPYDATASTRUCT *cds = (COPYDATASTRUCT*) lParam; + COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam; if (cds->dwData == RAINMETER_QUERY_ID_SKIN_WINDOWHANDLE) { - std::wstring SkinName((LPTSTR) cds->lpData); + std::wstring SkinName((LPTSTR)cds->lpData); std::map MeterWindows = Rainmeter->GetAllMeterWindows(); std::map::const_iterator iter = MeterWindows.find(SkinName); if (iter != MeterWindows.end()) { - return (LRESULT) iter->second->GetWindow(); + return (LRESULT)iter->second->GetWindow(); } return NULL; } @@ -818,6 +805,17 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA case WM_DESTROY: PostQuitMessage(0); break; + + default: + if (uMsg == WM_TASKBARCREATED) + { + if (tray && tray->IsTrayIconEnabled()) + { + tray->RemoveTrayIcon(); + tray->AddTrayIcon(); + } + } + break; } return DefWindowProc(hWnd, uMsg, wParam, lParam);