WindowMessages

Using Window Messages to interact with Rainmeter from a 3rd-party application

It is possible to access key data about a Rainmeter instance through basic Windows Messaging API calls. The majority of the queries return data via a COPYDATASTRUCT, but some operate slightly differently depending on the content that needs to be communicated. Note: These instructions assume you are using C++ in your program. The method is applicable in other languages but the format will be different.

Querying Rainmeter for string values

There are a number of strings associated with Rainmeter that can be requested. These are:

  • RAINMETER_QUERY_ID_SKINS_PATH
    QueryID: 4101
    Returns the skins path as defined in Rainmeter.ini
  • RAINMETER_QUERY_ID_SETTINGS_PATH
    QueryID: 4102
    Returns the path to the Rainmeter.ini file
  • RAINMETER_QUERY_ID_PLUGINS_PATH
    QueryID: 4103
    Returns the path to the Rainmeter plugins directory
  • RAINMETER_QUERY_ID_PROGRAM_PATH
    QueryID: 4104
    Returns the path to the Rainmeter program directory
  • RAINMETER_QUERY_ID_LOG_PATH
    QueryID: 4105
    Returns the path to the Rainmeter.log file
  • RAINMETER_QUERY_ID_CONFIG_EDITOR
    QueryID: 4106
    Returns the path specified as the ConfigEditor= setting in Rainmeter.ini
  • RAINMETER_QUERY_ID_COMMAND_LINE
    QueryID: 4107
    Returns the command line parameters used to launch Rainmeter
  • RAINMETER_QUERY_ID_STATS_DATE
    QueryID: 4108
    Returns the date on which the Net measures stats were started
  • RAINMETER_QUERY_ID_TRAY_EX_L
    QueryID: 4109
    Returns the TrayExecuteL (Left Mouse) string from Rainmeter.ini
  • RAINMETER_QUERY_ID_TRAY_EX_R
    QueryID: 4110
    Returns the TrayExecuteR (Right Mouse) string from Rainmeter.ini
  • RAINMETER_QUERY_ID_TRAY_EX_M
    QueryID: 4111
    Returns the TrayExecuteM (Middle Mouse) string from Rainmeter.ini
  • RAINMETER_QUERY_ID_TRAY_EX_DL
    QueryID: 4112
    Returns the TrayExecuteDL (Double Click Left Mouse) string from Rainmeter.ini
  • RAINMETER_QUERY_ID_TRAY_EX_DR
    QueryID: 4113
    Returns the TrayExecuteDR (Double Click Right Mouse) string from Rainmeter.ini
  • RAINMETER_QUERY_ID_TRAY_EX_DM
    QueryID: 4114
    Returns the TrayExecuteDM (Double Click Middle Mouse) string from Rainmeter.ini

Note: All these options are defined within RainmeterQuery.h available at http://rainmeter.googlecode.com/svn/trunk/Library/RainmeterQuery.h This file also includes code examples. If you do not wish to include this file or its definitions in your project then you can use the numbers in brackets as the msg parameter.

Using these functions in C++

void QueryRainmeterSkinsPath(HWND hWndSelf) { HWND hWndRainmeter = FindWindow(RAINMETER_QUERY_CLASS_NAME, RAINMETER_QUERY_WINDOW_NAME); if (hWndRainmeter) { PostMessage(hWndRainmeter, WM_QUERY_RAINMETER, RAINMETER_QUERY_ID_SKINS_PATH, (LPARAM)hWndSelf); } }

The first parameter should be the HWND of Rainmeter, the second should be WM_QUERY_RAINMETER, defined as WM_APP + 1000. The third is the Query ID as listed above. Finally, the fourth parameter needs to be the HWND of the calling app. This allows Rainmeter to send the requested information back.

RAINMETER_QUERY_CLASS_NAME is defined as RainmeterTrayClass and RAINMETER_QUERY_WINDOW_NAME is NULL.

Rainmeter will then send a WM_COPYDATA message to the window specified in hWndSelf. The lParam of the message will contain a COPYDATASTRUCT with the requested string, the Query ID and the size of the requested string. To access the data you will need to add something like this to your WndProc:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COPYDATA: { COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam; // Copy ID and string to local DWORD id = cds->dwData; // contains QUERY ID (RAINMETER_QUERY_ID_XXXXX) std::wstring string = (WCHAR*)cds->lpData; // contains requested string in wide char // ... } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }

Querying Rainmeter for numeric values

  • RAINMETER_QUERY_ID_VERSION_CHECK
    QueryID: 4115
    Returns 0 if version checking is disabled, 1 if it is enabled, and 2 if a new version is available
  • RAINMETER_QUERY_ID_IS_DEBUGGING
    QueryID: 4116
    Returns 1 if Debug=1 is set in Rainmeter.ini
  • RAINMETER_QUERY_ID_IS_LITESTEP
    QueryID: 4117
    Returns 1 if Rainmeter is running as a Litestep plugin

To get this information you should send a message in the same way as the strings above. Rainmeter will then send a message to your window with the requested data stored directly in the lParam. The msg will contain WM_QUERY_RAINMETER_RETURN, defined as WM_APP + 1001.

Querying Rainmeter for the Window Handle of an active skin

To do this, send a COPYDATASTRUCT to the Rainmeter window in this form:

COPYDATASTRUCT cds; LPWSTR SkinName = L"Gnometer\\Clock"; cds.dwData = 5101; // RAINMETER_QUERY_ID_SKIN_WINDOWHANDLE cds.lpData = SkinName; cds.cbData = (wcslen(SkinName) + 1) * 2; HWND hWndMeter = (HWND) SendMessage(hWndRainmeter, WM_COPYDATA, (WPARAM) hWndYourWindow, (LPARAM) &cds);

This will assign hWndMeter with the Handle of the requested skin if it is loaded, or NULL otherwise.
The SkinName element is actually the ConfigName as shown in Rainmeter.ini, and is Case-Sensitive.