WindowMessagesUsing Window Messages to interact with Rainmeter from a 3rd-party applicationIt 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 valuesThere are a number of strings associated with Rainmeter that can be requested. These are:
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
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 skinTo 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. |