Code cleanup.

This commit is contained in:
spx 2010-12-21 04:49:01 +00:00
parent f4bfe8f4fc
commit 9c75cf3423
4 changed files with 48 additions and 34 deletions

View File

@ -567,8 +567,8 @@ void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
{
if (CSystem::GetShowDesktop())
{
// Insert after the tray window temporarily to keep order
winPos = m_Rainmeter->GetTrayWindow()->GetWindow();
// Insert after the system window temporarily to keep order
winPos = CSystem::GetWindow();
}
else
{
@ -588,28 +588,28 @@ void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
// Set WS_EX_TOPMOST flag
SetWindowPos(m_Window, HWND_TOPMOST, 0, 0, 0, 0, ZPOS_FLAGS);
winPos = CSystem::GetHelperWindow();
if (all)
{
// Insert after the helper window
SetWindowPos(m_Window, CSystem::GetHelperWindow(), 0, 0, 0, 0, ZPOS_FLAGS);
}
else
{
// Find the "backmost" topmost window
HWND hwnd = CSystem::GetHelperWindow();
while (hwnd = ::GetNextWindow(hwnd, GW_HWNDPREV))
while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV))
{
if (GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
if (GetWindowLong(winPos, GWL_EXSTYLE) & WS_EX_TOPMOST)
{
// Insert after the found window
if (0 != SetWindowPos(m_Window, hwnd, 0, 0, 0, 0, ZPOS_FLAGS))
if (0 != SetWindowPos(m_Window, winPos, 0, 0, 0, 0, ZPOS_FLAGS))
{
break;
}
}
}
return;
}
return;
}
else
{

View File

@ -243,7 +243,7 @@ LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
if (subStrings.size() >= 1)
{
std::wstring config = subStrings[0];
const std::wstring& config = subStrings[0];
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
if (meterWindow)
@ -266,12 +266,12 @@ LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
if (subStrings.size() >= 2)
{
std::wstring config = subStrings[0];
const std::wstring& config = subStrings[0];
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
if (meterWindow)
{
std::wstring variable = subStrings[1];
const std::wstring& variable = subStrings[1];
std::wstring result_from_parser;
if (meterWindow->GetParser().GetVariable(variable, result_from_parser))
@ -295,7 +295,7 @@ LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
if (subStrings.size() >= 2)
{
std::wstring config = subStrings[0];
const std::wstring& config = subStrings[0];
std::wstring arguments;
for (size_t i = 1; i < subStrings.size(); ++i)
@ -334,7 +334,7 @@ LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
if (subStrings.size() >= 1)
{
std::wstring config = subStrings[0];
const std::wstring& config = subStrings[0];
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
if (meterWindow)
@ -1581,21 +1581,21 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
}
m_Instance = Instance;
WCHAR tmpName[MAX_LINE_LENGTH];
GetModuleFileName(m_Instance, tmpName, MAX_LINE_LENGTH);
WCHAR tmpSz[MAX_LINE_LENGTH];
GetModuleFileName(m_Instance, tmpSz, MAX_LINE_LENGTH);
// Remove the module's name from the path
WCHAR* pos = wcsrchr(tmpName, L'\\');
WCHAR* pos = wcsrchr(tmpSz, L'\\');
if(pos)
{
*(pos + 1) = L'\0';
}
else
{
tmpName[0] = L'\0';
tmpSz[0] = L'\0';
}
m_Path = tmpName;
m_Path = tmpSz;
if(!c_DummyLitestep) InitalizeLitestep();
@ -1690,21 +1690,30 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
m_SkinPath += L"Skins\\";
// Read the skin folder from the ini file
WCHAR tmpSz[MAX_LINE_LENGTH];
tmpSz[0] = L'\0';
if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", tmpSz, MAX_LINE_LENGTH, m_IniFile.c_str()) > 0)
{
m_SkinPath = tmpSz;
ExpandEnvironmentVariables(m_SkinPath);
if (!m_SkinPath.empty())
{
WCHAR ch = m_SkinPath[m_SkinPath.size() - 1];
if (ch != L'\\' && ch != L'/')
{
m_SkinPath += L"\\";
}
}
}
else if (bDefaultIniLocation)
{
// If the skin path is not defined in the Rainmeter.ini file use My Documents/Rainmeter/Skins
TCHAR szPath[MAX_PATH] = {0};
HRESULT hr = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, szPath);
tmpSz[0] = L'\0';
HRESULT hr = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, tmpSz);
if (SUCCEEDED(hr))
{
// Make the folders if they don't exist yet
m_SkinPath = szPath;
m_SkinPath = tmpSz;
m_SkinPath += L"\\Rainmeter";
CreateDirectory(m_SkinPath.c_str(), NULL);
m_SkinPath += L"\\Skins\\";
@ -3070,6 +3079,8 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
*/
void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
{
WCHAR buffer[MAX_PATH];
// Clear old settings
m_DesktopWorkAreas.clear();
@ -3100,8 +3111,8 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
if (m_ConfigEditor.empty())
{
// Get the program path associated with .ini files
WCHAR buffer[MAX_PATH] = {0};
DWORD cchOut = MAX_PATH;
buffer[0] = L'\0';
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut);
if (SUCCEEDED(hr) && cchOut > 0)
@ -3123,8 +3134,8 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
if (m_LogViewer.empty())
{
// Get the program path associated with .log files
WCHAR buffer[MAX_PATH] = {0};
DWORD cchOut = MAX_PATH;
buffer[0] = L'\0';
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".log", L"open", buffer, &cchOut);
if (SUCCEEDED(hr) && cchOut > 0)
@ -3916,11 +3927,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU con
for (int i = 0; i < itemCount; ++i)
{
WCHAR buffer[MAX_PATH] = {0};
MENUITEMINFO itemInfo = {sizeof(MENUITEMINFO)};
itemInfo.fMask = MIIM_STRING;
itemInfo.dwTypeData = buffer;
itemInfo.cch = MAX_PATH;
if (GetMenuItemInfo(configMenu, (UINT)i, TRUE, &itemInfo))
if (GetMenuString(configMenu, i, buffer, MAX_PATH, MF_BYPOSITION))
{
if (_wcsicmp(root.c_str(), buffer) == 0)
{

View File

@ -37,7 +37,7 @@ enum INTERVAL
{
INTERVAL_SHOWDESKTOP = 250,
INTERVAL_COMPOSITION = 250,
INTERVAL_NETSTATS = 10000,
INTERVAL_NETSTATS = 60000,
INTERVAL_DELETELATER = 1000
};
@ -106,6 +106,7 @@ void CSystem::Initialize(HINSTANCE instance)
SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
SetWindowPos(c_HelperWindow, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
c_Monitors.monitors.reserve(8);
SetMultiMonitorInfo();
c_DwmCompositionEnabled = (DwmIsCompositionEnabled() == TRUE);
@ -256,8 +257,6 @@ void CSystem::SetMultiMonitorInfo()
std::vector<MONITOR_INFO>& monitors = c_Monitors.monitors;
bool logging = CRainmeter::GetDebug();
if (monitors.capacity() < 16) { monitors.reserve(16); }
c_Monitors.vsT = GetSystemMetrics(SM_YVIRTUALSCREEN);
c_Monitors.vsL = GetSystemMetrics(SM_XVIRTUALSCREEN);
c_Monitors.vsH = GetSystemMetrics(SM_CYVIRTUALSCREEN);
@ -765,6 +764,8 @@ void CSystem::PrepareHelperWindow(HWND WorkerW)
{
bool logging = CRainmeter::GetDebug() && DEBUG_VERBOSE;
SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING); // always on bottom
if (c_ShowDesktop && WorkerW)
{
// Set WS_EX_TOPMOST flag
@ -886,7 +887,7 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
static int DesktopCompositionCheckCount = 0;
if (uMsg == WM_CREATE || hWnd != c_Window)
if (hWnd != c_Window)
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

View File

@ -272,6 +272,8 @@ HICON CTrayWindow::CreateTrayIcon(double value)
void CTrayWindow::ReadConfig(CConfigParser& parser)
{
KillTimer(m_Window, TRAYTIMER);
delete m_Measure;
m_Measure = NULL;
@ -371,7 +373,11 @@ void CTrayWindow::ReadConfig(CConfigParser& parser)
if (trayIcon != 0)
{
AddTrayIcon();
SetTimer(m_Window, TRAYTIMER, 1000, NULL); // Update the tray once per sec
if (m_Measure)
{
SetTimer(m_Window, TRAYTIMER, 1000, NULL); // Update the tray once per sec
}
}
}