C# API Overview
This is an overview of the functions available in the C# Rainmeter API. All the functions are behind a Rainmeter.API wrapper which is created using the rm IntPtr.
ReadStringstring ReadString(string option, string defValue, bool replaceMeasures = true)-
Returns a string representation of an option.
option: Option name to be read from the measure.defValue: Default value for the option if it is not found or invalid.replaceMeasures: If true, replaces section variables in the returned string.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
// The following will replace regular variables and
// section variables in the 'Value' option.
string value = rm.ReadString("Value", "DefaultValue");
// The following will only replace regular variables,
// but NOT section variables like [MeasureNames].
string action = rm.ReadString("Action", "", false);
} ReadStringFromSectionstring ReadStringFromSection(string section, string option, string defValue, bool replace = true)-
Returns a string representation of an option from a section.
section: Section name to read the option from.option: Option name to be read from the measure/meter.defValue: Default value for the option if it is not found or invalid.replace: If true, replaces section variables in the returned string.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
// The following will replace regular variables and
// section variables in the 'Value' option.
string value = rm.ReadStringFromSection("Section","Option", "DefaultValue");
// The following will only replace regular variables,
// but NOT section variables like [MeasureNames].
string action = rm.ReadStringFromSection("Section", "Action", "", false);
} ReadIntint ReadInt(string option, int defValue)-
Retrieves the option defined in the skin file and converts it to an integer.
option: Option name to be read from the measure.defValue: Default value for the option if it is not found, invalid, or a formula could not be parsed.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
int value = rm.ReadInt("Value", 20);
} ReadIntFromSectionint ReadIntFromSection(string section, string option, int defValue)-
Retrieves the option defined in a section and converts it to an integer.
section: Section name to read the option from.option: Option name to be read from the measure/meter.defValue: Default value for the option if it is not found, invalid, or a formula could not be parsed.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
int value = rm.ReadIntFromSection("Section", "Option", 20);
} ReadDoubledouble ReadDouble(string option, double defValue)-
Retrieves the option defined in the plugin measure in the skin file and converts it to a double type.
option: Option name to be read from the plugin measure.defValue: Default value for the option if it is not found, invalid, or a formula could not be parsed.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
double value = rm.ReadDouble("Value", 20.0);
} ReadDoubleFromSectiondouble ReadDoubleFromSection(string section, string option, double defValue)-
Retrieves the option defined in any section and converts it to a double type.
section: Section name to read the option from.option: Option name to be read from the measure/meter.defValue: Default value for the option if it is not found, invalid, or a formula could not be parsed.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
double value = rm.ReadDoubleFromSection("Section", "Option", 20.0);
} ReadPathstring ReadPath(string option, string defValue)-
Retrieves the option defined in the skin file and converts a relative path to a absolute path.
option: Option name to be read from the measure.defValue: Default value for the option if it is not found or invalid.
Example:
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
string path = rm.ReadPath("MyPath", "C:\\");
} Executevoid Execute(IntPtr skin, string command)-
Executes an action.
skin: Pointer to current skin (see GetSkin).command: Action to execute.
Example:
internal double Update(IntPtr data)
{
Measure measure = (Measure)data;
// 'mySkin' stored previously in the Initialize function
API.Execute(mySkin, L"[!SetVariable SomeVar 10]");
return 0.0;
} ReplaceVariablesstring ReplaceVariables(string str)-
Returns a string, replacing any variables (or section variables) within the inputted string.
str: String with unresolved variables.
Example:
internal double Update()
{
string myVar = ReplaceVariables("#MyVar#").ToUpperInvariant();
if (myVar == "SOMETHING") { return 1.0; }
return 0.0;
} GetMeasureNamestring GetMeasureName()-
Retrieves the name of the measure.
Example:
internal void Initialize(Rainmeter.API rm)
{
myName = GetMeasureName(); // declare 'myName' as a string in class scope
} GetSkinIntPtr GetSkin()-
Retrieves an internal pointer to the current skin.
Example:
internal void Initialize(Rainmeter.API rm)
{
mySkin = GetSkin(); // declare 'mySkin' as a IntPtr in class scope
} GetSkinNamestring GetSkinName()-
Retrieves full path and name of the skin.
Example:
internal void Initialize(Rainmeter.API rm)
{
// declare 'skinName' as a string in class scope
skinName = GetSkinName();
} GetSkinWindowIntPtr GetSkinWindow()-
Returns a pointer to the handle (HWND) of the skin window.
Example:
internal void Initialize(Rainmeter.API rm)
{
// declare 'skinWindow' as a IntPtr in class scope
skinWindow = GetSkinWindow();
} GetSettingsFilestring GetSettingsFile()-
Retrieves a path to the Rainmeter data file (Rainmeter.data).
internal void Initialize(Rainmeter.API rm)
{
// declare 'rmDataFile' as a string in global scope
if (rmDataFile == null) { rmDataFile = GetSettingsFile(); }
} Logvoid Log(LogType type, string message)-
Sends a message to the Rainmeter log.
type: Log level (API.LogType.Error, API.LogType.Warning, API.LogType.Notice, or API.LogType.Debug)message: Message to be logged.
Example:
API.Log(API.LogType.Notice, "I am a 'notice' log message with a source");
LogFvoid LogF(LogType type, string format, params string[] args)-
Sends a formatted message to the Rainmeter log.
type: Log level (API.LogType.Error, API.LogType.Warning, API.LogType.Notice, or API.LogType.Debug)format: Formatted message to be logged, follows composite formatting.args: Comma separated list of arguments referenced in the formatted message.
Example:
string notice = "notice";
API.LogF(API.LogType.Notice, "I am a '{0}' log message with a source", notice);