mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Reintegrated 2.3 branch into trunk
This commit is contained in:
@ -67,10 +67,10 @@
|
||||
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)TestBench\x32\$(Configuration)\Plugins\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\x32\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)TestBench\x64\$(Configuration)\Plugins\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\x64\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)TestBench\x32\$(Configuration)\Plugins\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\x32\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
|
@ -17,211 +17,132 @@
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include "../../Library/RawString.h"
|
||||
#include "../../Library/Export.h" // Rainmeter's exported functions
|
||||
|
||||
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
|
||||
|
||||
/* The exported functions */
|
||||
extern "C"
|
||||
struct MeasureData
|
||||
{
|
||||
__declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
|
||||
__declspec( dllexport ) void Finalize(HMODULE instance, UINT id);
|
||||
__declspec( dllexport ) double Update2(UINT id);
|
||||
__declspec( dllexport ) LPCTSTR GetString(UINT id, UINT flags);
|
||||
__declspec( dllexport ) UINT GetPluginVersion();
|
||||
__declspec( dllexport ) LPCTSTR GetPluginAuthor();
|
||||
__declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id);
|
||||
}
|
||||
|
||||
struct windowData
|
||||
{
|
||||
std::wstring windowName;
|
||||
std::wstring windowClass;
|
||||
CRawString windowName;
|
||||
CRawString windowClass;
|
||||
CRawString value;
|
||||
WPARAM wParam;
|
||||
LPARAM lParam;
|
||||
DWORD uMsg;
|
||||
std::wstring value;
|
||||
DWORD result;
|
||||
|
||||
MeasureData() : wParam(), lParam(), uMsg() {}
|
||||
};
|
||||
|
||||
static std::map<UINT, windowData> g_Values;
|
||||
|
||||
/*
|
||||
This function is called when the measure is initialized.
|
||||
The function must return the maximum value that can be measured.
|
||||
The return value can also be 0, which means that Rainmeter will
|
||||
track the maximum value automatically. The parameters for this
|
||||
function are:
|
||||
|
||||
instance The instance of this DLL
|
||||
iniFile The name of the ini-file (usually Rainmeter.ini)
|
||||
section The name of the section in the ini-file for this measure
|
||||
id The identifier for the measure. This is used to identify the measures that use the same plugin.
|
||||
*/
|
||||
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
|
||||
PLUGIN_EXPORT void Initialize(void** data)
|
||||
{
|
||||
windowData wData;
|
||||
wData.uMsg = 0;
|
||||
wData.wParam = 0;
|
||||
wData.lParam = 0;
|
||||
wData.result = 0;
|
||||
|
||||
/* Read our own settings from the ini-file */
|
||||
LPCTSTR data = ReadConfigString(section, L"WindowName", NULL);
|
||||
if (data)
|
||||
{
|
||||
wData.windowName = data;
|
||||
}
|
||||
|
||||
data = ReadConfigString(section, L"WindowClass", NULL);
|
||||
if (data)
|
||||
{
|
||||
wData.windowClass = data;
|
||||
}
|
||||
|
||||
data = ReadConfigString(section, L"WindowMessage", NULL);
|
||||
if (data)
|
||||
{
|
||||
DWORD uMsg, wParam, lParam;
|
||||
if (3 == swscanf(data, L"%u %u %u", &uMsg, &wParam, &lParam))
|
||||
{
|
||||
wData.uMsg = uMsg;
|
||||
wData.wParam = wParam;
|
||||
wData.lParam = lParam;
|
||||
}
|
||||
}
|
||||
|
||||
g_Values[id] = wData;
|
||||
|
||||
return 0;
|
||||
MeasureData* measure = new MeasureData;
|
||||
*data = measure;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is called when new value should be measured.
|
||||
The function returns the new value.
|
||||
*/
|
||||
double Update2(UINT id)
|
||||
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
std::map<UINT, windowData>::iterator i = g_Values.find(id);
|
||||
if (i != g_Values.end())
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
measure->windowName = RmReadString(rm, L"WindowName", L"");
|
||||
measure->windowClass = RmReadString(rm, L"WindowClass", L"");
|
||||
|
||||
DWORD uMsg, wParam, lParam;
|
||||
LPCWSTR message = RmReadString(rm, L"WindowMessage", L"");
|
||||
if (3 == swscanf(message, L"%u %u %u", &uMsg, &wParam, &lParam))
|
||||
{
|
||||
const std::wstring& winName = (*i).second.windowName;
|
||||
const std::wstring& winClass = (*i).second.windowClass;
|
||||
HWND hwnd = FindWindow(winClass.empty() ? NULL : winClass.c_str(), winName.empty() ? NULL : winName.c_str());
|
||||
if (hwnd)
|
||||
{
|
||||
if ((*i).second.uMsg == 0)
|
||||
{
|
||||
// Get window text
|
||||
WCHAR buffer[1024];
|
||||
buffer[0] = 0;
|
||||
GetWindowText(hwnd, buffer, 1024);
|
||||
(*i).second.value = buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*i).second.result = (DWORD)SendMessage(hwnd, (*i).second.uMsg, (*i).second.wParam, (*i).second.lParam);
|
||||
return (int)((*i).second.result);
|
||||
}
|
||||
}
|
||||
measure->uMsg = uMsg;
|
||||
measure->wParam = wParam;
|
||||
measure->lParam = lParam;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LPCTSTR GetString(UINT id, UINT flags)
|
||||
PLUGIN_EXPORT double Update(void* data)
|
||||
{
|
||||
static WCHAR buffer[64];
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
std::map<UINT, windowData>::iterator i = g_Values.find(id);
|
||||
if (i != g_Values.end())
|
||||
HWND hwnd = FindWindow(
|
||||
measure->windowClass.empty() ? NULL : measure->windowClass.c_str(),
|
||||
measure->windowName.empty() ? NULL : measure->windowName.c_str());
|
||||
|
||||
if (hwnd)
|
||||
{
|
||||
if (((*i).second).value.empty())
|
||||
if (measure->uMsg == 0)
|
||||
{
|
||||
_itow(((*i).second).result, buffer, 10);
|
||||
return buffer;
|
||||
// Get window text
|
||||
WCHAR buffer[256];
|
||||
GetWindowText(hwnd, buffer, 256);
|
||||
measure->value = buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((*i).second).value.c_str();
|
||||
return (double)SendMessage(hwnd, measure->uMsg, measure->wParam, measure->lParam);
|
||||
}
|
||||
}
|
||||
else if (measure->uMsg == 0)
|
||||
{
|
||||
measure->value.clear();
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT LPCWSTR GetString(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
if (measure->uMsg == 0)
|
||||
{
|
||||
return measure->value.c_str();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
If the measure needs to free resources before quitting.
|
||||
The plugin can export Finalize function, which is called
|
||||
when Rainmeter quits (or refreshes).
|
||||
*/
|
||||
void Finalize(HMODULE instance, UINT id)
|
||||
PLUGIN_EXPORT void Finalize(void* data)
|
||||
{
|
||||
std::map<UINT, windowData>::iterator i1 = g_Values.find(id);
|
||||
if (i1 != g_Values.end())
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
delete measure;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
const WCHAR* pos = wcschr(args, L' ');
|
||||
if (pos)
|
||||
{
|
||||
g_Values.erase(i1);
|
||||
}
|
||||
}
|
||||
|
||||
UINT GetPluginVersion()
|
||||
{
|
||||
return 1001;
|
||||
}
|
||||
|
||||
LPCTSTR GetPluginAuthor()
|
||||
{
|
||||
return L"Rainy (rainy@iki.fi)";
|
||||
}
|
||||
|
||||
void ExecuteBang(LPCTSTR args, UINT id)
|
||||
{
|
||||
std::wstring wholeBang = args;
|
||||
|
||||
size_t pos = wholeBang.find(L' ');
|
||||
if (pos != -1)
|
||||
{
|
||||
std::wstring bang = wholeBang.substr(0, pos);
|
||||
wholeBang.erase(0, pos + 1);
|
||||
|
||||
if (_wcsicmp(bang.c_str(), L"SendMessage") == 0)
|
||||
size_t len = pos - args;
|
||||
if (_wcsnicmp(args, L"SendMessage", len) == 0)
|
||||
{
|
||||
++pos;
|
||||
|
||||
// Parse parameters
|
||||
DWORD uMsg, wParam, lParam;
|
||||
if (3 == swscanf(wholeBang.c_str(), L"%u %u %u", &uMsg, &wParam, &lParam))
|
||||
if (3 == swscanf(pos, L"%u %u %u", &uMsg, &wParam, &lParam))
|
||||
{
|
||||
std::map<UINT, windowData>::iterator i = g_Values.find(id);
|
||||
if (i != g_Values.end())
|
||||
|
||||
HWND hwnd = FindWindow(
|
||||
measure->windowClass.empty() ? NULL : measure->windowClass.c_str(),
|
||||
measure->windowName.empty() ? NULL : measure->windowName.c_str());
|
||||
|
||||
if (hwnd)
|
||||
{
|
||||
std::wstring& winName = (*i).second.windowName;
|
||||
std::wstring& winClass = (*i).second.windowClass;
|
||||
HWND hwnd = FindWindow(winClass.empty() ? NULL : winClass.c_str(), winName.empty() ? NULL : winName.c_str());
|
||||
if (hwnd)
|
||||
{
|
||||
PostMessage(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
LSLog(LOG_ERROR, NULL, L"WindowMessagePlugin.dll: Unable to find window");
|
||||
}
|
||||
PostMessage(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
LSLog(LOG_ERROR, NULL, L"WindowMessagePlugin.dll: Unable to find window data");
|
||||
RmLog(LOG_ERROR, L"WindowMessagePlugin.dll: Unable to find window");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LSLog(LOG_WARNING, NULL, L"WindowMessagePlugin.dll: Incorrect number of arguments for bang");
|
||||
RmLog(LOG_WARNING, L"WindowMessagePlugin.dll: Incorrect number of arguments for bang");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LSLog(LOG_WARNING, NULL, L"WindowMessagePlugin.dll: Unknown bang");
|
||||
RmLog(LOG_WARNING, L"WindowMessagePlugin.dll: Unknown bang");
|
||||
}
|
||||
|
Reference in New Issue
Block a user