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.
ReadString
string 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);
} ReadInt
int 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);
} ReadDouble
double ReadDouble(string option, double defValue)
-
Retrieves the option defined in the skin file and converts it to a double type.
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)
{
double value = rm.ReadDouble("Value", 20.0);
} ReadPath
string 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:\\");
} Execute
void 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;
} ReplaceVariables
string 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;
} GetMeasureName
string GetMeasureName()
-
Retrieves the name of the measure.
Example:
internal void Initialize(Rainmeter.API rm)
{
myName = GetMeasureName(); // declare 'myName' as a string in class scope
} GetSkin
IntPtr 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
} GetSkinName
string 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();
} GetSkinWindow
IntPtr 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();
} GetSettingsFile
string 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(); }
} Log
void 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");
LogF
void 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);