static int GetOption(lua_State* L) { DECLARE_SELF(L) MeterWindow* meterWindow = self->GetMeterWindow(); ConfigParser& parser = meterWindow->GetParser(); std::wstring strTmp = LuaManager::ToWide(L, 2); strTmp = parser.ReadString(self->GetName(), strTmp.c_str(), L""); LuaManager::PushWide(L, strTmp); return 1; }
static int GetOption(lua_State* L) { DECLARE_SELF(L) MeterWindow* meterWindow = self->GetMeterWindow(); ConfigParser& parser = meterWindow->GetParser(); const std::wstring section = LuaManager::ToWide(2); const std::wstring defValue = LuaManager::ToWide(3); const std::wstring& value = parser.ReadString(self->GetName(), section.c_str(), defValue.c_str()); LuaManager::PushWide(value); return 1; }
/* ** Retrieves the Rainmeter's meter windows in Z-order. ** */ BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam) { bool logging = GetRainmeter().GetDebug() && DEBUG_VERBOSE; const int classLen = _countof(METERWINDOW_CLASS_NAME) + (DEBUG_VERBOSE ? 32 : 1); WCHAR className[classLen]; MeterWindow* Window; WCHAR flag; if (GetClassName(hwnd, className, classLen) > 0 && wcscmp(className, METERWINDOW_CLASS_NAME) == 0 && (Window = GetRainmeter().GetMeterWindow(hwnd))) { ZPOSITION zPos = Window->GetWindowZPosition(); if (zPos == ZPOSITION_ONDESKTOP || (zPos == ZPOSITION_NORMAL && GetRainmeter().IsNormalStayDesktop()) || zPos == ZPOSITION_ONBOTTOM) { if (lParam) { ((std::vector<MeterWindow*>*)lParam)->push_back(Window); } if (logging) flag = L'+'; } else { if (logging) flag = L'-'; } if (logging) { LogDebugF(L"%c [%c] 0x%p : %s (Name: \"%s\", zPos=%i)", flag, IsWindowVisible(hwnd) ? L'V' : L'H', hwnd, className, Window->GetFolderPath().c_str(), (int)zPos); } } else { if (logging) { flag = (hwnd == System::GetHelperWindow()) ? L'o' : ' '; LogDebugF(L"%c [%c] 0x%p : %s", flag, IsWindowVisible(hwnd) ? L'V' : L'H', hwnd, className); } } return TRUE; }
std::wstring GetSectionSourceString(Section* section) { std::wstring source; if (section) { MeterWindow* meterWindow = section->GetMeterWindow(); if (meterWindow) { source = meterWindow->GetSkinPath(); source += L" - "; } source += L'['; source += section->GetOriginalName(); source += L']'; } return source; }
/* ** Returns the first window whose position is not ZPOSITION_ONDESKTOP, ** ZPOSITION_BOTTOM, or ZPOSITION_NORMAL. ** */ HWND System::GetBackmostTopWindow() { HWND winPos = c_HelperWindow; // Skip all ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV)) { MeterWindow* wnd = GetRainmeter().GetMeterWindow(winPos); if (!wnd || (wnd->GetWindowZPosition() != ZPOSITION_NORMAL && wnd->GetWindowZPosition() != ZPOSITION_ONDESKTOP && wnd->GetWindowZPosition() != ZPOSITION_ONBOTTOM)) { break; } } return winPos; }
void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args) { std::wstring source; if (section) { MeterWindow* meterWindow = section->GetMeterWindow(); if (meterWindow) { source = meterWindow->GetSkinPath(); source += L" - "; } source += L'['; source += section->GetOriginalName(); source += L']'; } GetLogger().LogVF(level, source.c_str(), format, args); }
void* __stdcall RmGet(void* rm, int type) { MeasurePlugin* measure = (MeasurePlugin*)rm; switch (type) { case RMG_MEASURENAME: { return (void*)measure->GetName(); } case RMG_SKIN: { return (void*)measure->GetMeterWindow(); } case RMG_SETTINGSFILE: { return (void*)GetRainmeter().GetDataFile().c_str(); } case RMG_SKINNAME: { MeterWindow* window = measure->GetMeterWindow(); if (!window) break; return (void*)window->GetFolderPath().c_str(); } case RMG_SKINWINDOWHANDLE: { MeterWindow* window = measure->GetMeterWindow(); if (!window) break; return (void*)window->GetWindow(); } } return nullptr; }
/* ** Opens the context menu in given coordinates. */ void ContextMenu::ShowMenu(POINT pos, MeterWindow* meterWindow) { static const MenuTemplate s_Menu[] = { MENU_ITEM(IDM_MANAGE, ID_STR_MANAGE), MENU_ITEM(IDM_ABOUT, ID_STR_ABOUT), MENU_ITEM(IDM_SHOW_HELP, ID_STR_HELP), MENU_SEPARATOR(), MENU_SUBMENU(ID_STR_SKINS, MENU_ITEM_GRAYED(0, ID_STR_NOSKINS), MENU_SEPARATOR(), MENU_ITEM(IDM_OPENSKINSFOLDER, ID_STR_OPENFOLDER), MENU_ITEM(IDM_DISABLEDRAG, ID_STR_DISABLEDRAGGING)), MENU_SUBMENU(ID_STR_THEMES, MENU_ITEM_GRAYED(0, ID_STR_NOTHEMES)), MENU_SEPARATOR(), MENU_ITEM(IDM_EDITCONFIG, ID_STR_EDITSETTINGS), MENU_ITEM(IDM_REFRESH, ID_STR_REFRESHALL), MENU_SEPARATOR(), MENU_SUBMENU(ID_STR_LOGGING, MENU_ITEM(IDM_SHOWLOGFILE, ID_STR_SHOWLOGFILE), MENU_SEPARATOR(), MENU_ITEM(IDM_STARTLOG, ID_STR_STARTLOGGING), MENU_ITEM(IDM_STOPLOG, ID_STR_STOPLOGGING), MENU_SEPARATOR(), MENU_ITEM(IDM_DELETELOGFILE, ID_STR_DELETELOGFILE), MENU_ITEM(IDM_DEBUGLOG, ID_STR_DEBUGMODE)), MENU_SEPARATOR(), MENU_ITEM(IDM_QUIT, ID_STR_EXIT) }; if (m_MenuActive || (meterWindow && meterWindow->IsClosing())) return; // Show context menu, if no actions were executed HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); if (!menu) return; m_MenuActive = true; Rainmeter& rainmeter = GetRainmeter(); SetMenuDefaultItem(menu, IDM_MANAGE, MF_BYCOMMAND); if (_waccess(GetLogger().GetLogFilePath().c_str(), 0) == -1) { EnableMenuItem(menu, IDM_SHOWLOGFILE, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(menu, IDM_DELETELOGFILE, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(menu, IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED); } else { EnableMenuItem( menu, (GetLogger().IsLogToFile()) ? IDM_STARTLOG : IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED); } if (rainmeter.m_Debug) { CheckMenuItem(menu, IDM_DEBUGLOG, MF_BYCOMMAND | MF_CHECKED); } HMENU allSkinsMenu = GetSubMenu(menu, 4); if (allSkinsMenu) { if (!rainmeter.m_SkinRegistry.IsEmpty()) { DeleteMenu(allSkinsMenu, 0, MF_BYPOSITION); // "No skins available" menuitem CreateAllSkinsMenu(allSkinsMenu); } if (rainmeter.m_DisableDragging) { CheckMenuItem(allSkinsMenu, IDM_DISABLEDRAG, MF_BYCOMMAND | MF_CHECKED); } } HMENU layoutMenu = GetSubMenu(menu, 5); if (layoutMenu) { if (!rainmeter.m_Layouts.empty()) { DeleteMenu(layoutMenu, 0, MF_BYPOSITION); // "No layouts available" menuitem CreateLayoutMenu(layoutMenu); } } if (meterWindow) { HMENU rainmeterMenu = menu; menu = CreateSkinMenu(meterWindow, 0, allSkinsMenu); InsertMenu(menu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)rainmeterMenu, L"Rainmeter"); InsertMenu(menu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_SEPARATOR, 0, nullptr); } else { InsertMenu(menu, 12, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr); // Create a menu for all active skins int index = 0; std::map<std::wstring, MeterWindow*>::const_iterator iter = rainmeter.m_MeterWindows.begin(); for (; iter != rainmeter.m_MeterWindows.end(); ++iter) { MeterWindow* mw = ((*iter).second); HMENU skinMenu = CreateSkinMenu(mw, index, allSkinsMenu); InsertMenu(menu, 12, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetFolderPath().c_str()); ++index; } // Add update notification item if (rainmeter.m_NewVersion) { InsertMenu(menu, 0, MF_BYPOSITION, IDM_NEW_VERSION, GetString(ID_STR_UPDATEAVAILABLE)); HiliteMenuItem(rainmeter.GetTrayWindow()->GetWindow(), menu, 0, MF_BYPOSITION | MF_HILITE); InsertMenu(menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr); } } HWND hWnd = WindowFromPoint(pos); if (hWnd != nullptr) { MeterWindow* mw = rainmeter.GetMeterWindow(hWnd); if (mw) { // Cancel the mouse event beforehand mw->SetMouseLeaveEvent(true); } } // Set the window to foreground hWnd = meterWindow ? meterWindow->GetWindow() : rainmeter.m_TrayWindow->GetWindow(); HWND hWndForeground = GetForegroundWindow(); if (hWndForeground != hWnd) { const DWORD foregroundThreadID = GetWindowThreadProcessId(hWndForeground, nullptr); const DWORD currentThreadID = GetCurrentThreadId(); AttachThreadInput(currentThreadID, foregroundThreadID, TRUE); SetForegroundWindow(hWnd); AttachThreadInput(currentThreadID, foregroundThreadID, FALSE); } // Show context menu TrackPopupMenu( menu, TPM_RIGHTBUTTON | TPM_LEFTALIGN | (*GetString(ID_STR_ISRTL) == L'1' ? TPM_LAYOUTRTL : 0), pos.x, pos.y, 0, hWnd, nullptr); DestroyMenu(menu); m_MenuActive = false; }
// Deprecated! LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) { if (command == nullptr || *command == L'\0') { return L"noop"; } NULLCHECK(data); if (_wcsicmp(command, L"GetConfig") == 0) { MeterWindow* meterWindow = GetRainmeter().GetMeterWindowByINI(data); if (meterWindow) { g_Buffer = L"\""; g_Buffer += meterWindow->GetFolderPath(); g_Buffer += L"\""; return g_Buffer.c_str(); } return L""; } else if (_wcsicmp(command, L"GetWindow") == 0) { std::vector<std::wstring> subStrings = CommandHandler::ParseString(data); if (subStrings.size() >= 1) { const std::wstring& config = subStrings[0]; MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config); if (meterWindow) { WCHAR buf1[64]; _snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow())); g_Buffer = buf1; return g_Buffer.c_str(); } } return L"error"; } else if (_wcsicmp(command, L"GetVariable") == 0) { std::vector<std::wstring> subStrings = CommandHandler::ParseString(data); if (subStrings.size() >= 2) { const std::wstring& config = subStrings[0]; MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config); if (meterWindow) { const std::wstring& variable = subStrings[1]; const std::wstring* value = meterWindow->GetParser().GetVariable(variable); if (value) { return (*value).c_str(); } } } return L""; } else if (_wcsicmp(command, L"SetVariable") == 0) { std::vector<std::wstring> subStrings = CommandHandler::ParseString(data); if (subStrings.size() == 3) { MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(subStrings[0]); if (meterWindow) { meterWindow->SetVariable(subStrings[1], subStrings[2]); return L"success"; } } return L"error"; } return L"noop"; }