So is it possible to get the window handle of a skin natively?
Thanks in advance.
Code: Select all
//all #includes have lots to offer. but sometime needed for just one thing
//used for the function findwindowa
//#include "winuser.h"
//this is to make use of the console. you can send text to it and lots of more things
#include <iostream>
//using string without this will not work
#include <string>
//now we could use handle's
#include "windows.h"
//this is so you do not need to write std::cout and so you can just write cout
using namespace std;
// HWND FindWindow(LPCSTR lpClassName, LPCSTR lpWindowName);
int main()
{
//send hello world! to the console window, here you see how std:: is used. but do not need it anymore because of the namespace.
std::cout << "Hello World!\n";
//make a string in memory that can posses 100 chars max
char buff[100];
//give this string the name you want
string name = "stackoverflow";
//save to buff, add text and %s to set name
sprintf_s(buff, "name is: %s", name.c_str());
//write the buff to the console
cout << "\n";
cout << "\n";
cout << buff;
//get the handle of the console
HANDLE hwnd = GetConsoleWindow();
cout << "\n";
cout << "\n";
cout << "The handle for the console: ";
cout << hwnd;
cout << "\n";
cout << "\n";
HWND hWnds = FindWindow(NULL, TEXT("Calculator"));
cout << "The handle for Calculator application: ";
cout << hWnds;
cout << "\n";
cout << "if handle is 00000000 then startup calc.exe and try again.";
cout << "\n";
cout << "program ended.";
cout << "\n";
cout << "\n";
}
Thanks a lot. This is what I was talking about. But I have no experience, or knowledge in building dll files. I am new to C++ and all I have done is simple console applications.jsmorley wrote: ↑July 23rd, 2021, 2:16 am death.crafter,
At the bottom of this page are examples of how to do just that in both C++ and AutoIt.
https://docs.rainmeter.net/developers/
I think I have some time tomorrow, I'll try to knock out a quick plugin for you...
You will pass it a full config name, and it will return the window handle.
I made a plugin to bring a skin to the focus. Now I need help with:jsmorley wrote: ↑July 23rd, 2021, 2:16 am death.crafter,
At the bottom of this page are examples of how to do just that in both C++ and AutoIt.
https://docs.rainmeter.net/developers/
I think I have some time tomorrow, I'll try to knock out a quick plugin for you...
You will pass it a full config name, and it will return the window handle.
Code: Select all
SomeAction=[!CommandMeasure Focus "Focus" "config\path"]
Code: Select all
[Spoiler]#include <Windows.h>
#include <stdio.h>
#include "../../API/RainmeterAPI.h"
struct Measure
{
HWND windowHandle;
Measure() : windowHandle(NULL)
{
};
};
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;
measure->windowHandle = RmGetSkinWindow(rm);
SetActiveWindow(measure->windowHandle);
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
Measure* measure = (Measure*)data;
}
PLUGIN_EXPORT double Update(void* data)
{
Measure* measure = (Measure*)data;
HWND isActive = GetActiveWindow();
if (measure->windowHandle != isActive) {
return 0.0;
} else {
return 1.0;
}
}
PLUGIN_EXPORT void Finalize(void* data)
{
Measure* measure = (Measure*)data;
delete measure;
}[/Spoiler]
Code: Select all
HWND GetSkinWindow(const WCHAR* configName)
{
HWND trayWnd = FindWindow(L"RainmeterTrayClass", NULL);
if (trayWnd)
{
COPYDATASTRUCT cds;
cds.dwData = 5101;
cds.cbData = (DWORD)(wcslen(configName) + 1) * sizeof(WCHAR);
cds.lpData = (void*)configName;
return (HWND)SendMessage(trayWnd, WM_COPYDATA, 0, (LPARAM)&cds);
}
return NULL;
}
PLUGIN_EXPORT double ExecuteBang(void* data, LPCWSTR args)
{
Measure* measure = (Measure*)data;
std::wstring wholeBang = args;
size_t pos = wholeBang.find(' ');
if (pos != -1) {
std::wstring bang = wholeBang.substr(0, pos);
wholeBang.erase(0, pos + 1);
if (bang == L"Focus") {
HWND hwnd = GetSkinWindow(wholeBang.c_str());
if (hwnd == NULL) {
RmLog(LOG_ERROR, wholeBang.c_str());
RmLog(LOG_ERROR, L"Focus.dll: Please provide valid config!");
return 0.0;
}
else {
SetActiveWindow(hwnd);
return 1.0;
}
}
else {
RmLog(LOG_ERROR, L"Focus.dll: Command invalid!");
return 0.0;
}
}
else if (wholeBang == L"Focus") {
SetActiveWindow(measure->windowHandle);
return 1.0;
}
else {
RmLog(LOG_ERROR, L"Focus.dll: Command invalid!");
return 0.0;
}
}
In this code, you need to break up "Focus" and "ConfigName" into two separate arguments. Although I'm not sure I see the need for the "Focus" argument. Isn't giving focus to a skin based on ConfigName the entire point of the plugin?death.crafter wrote: ↑July 23rd, 2021, 12:21 pm Okay so I figured out how to use !CommandMeasure. I need help with another thing:
So [!CommandMeasure Focus "Focus"] works.Code: Select all
HWND GetSkinWindow(const WCHAR* configName) { HWND trayWnd = FindWindow(L"RainmeterTrayClass", NULL); if (trayWnd) { COPYDATASTRUCT cds; cds.dwData = 5101; cds.cbData = (DWORD)(wcslen(configName) + 1) * sizeof(WCHAR); cds.lpData = (void*)configName; return (HWND)SendMessage(trayWnd, WM_COPYDATA, 0, (LPARAM)&cds); } return NULL; } PLUGIN_EXPORT double ExecuteBang(void* data, LPCWSTR args) { Measure* measure = (Measure*)data; std::wstring wholeBang = args; size_t pos = wholeBang.find(' '); if (pos != -1) { std::wstring bang = wholeBang.substr(0, pos); wholeBang.erase(0, pos + 1); if (bang == L"Focus") { HWND hwnd = GetSkinWindow(wholeBang.c_str()); if (hwnd == NULL) { RmLog(LOG_ERROR, wholeBang.c_str()); RmLog(LOG_ERROR, L"Focus.dll: Please provide valid config!"); return 0.0; } else { SetActiveWindow(hwnd); return 1.0; } } else { RmLog(LOG_ERROR, L"Focus.dll: Command invalid!"); return 0.0; } } else if (wholeBang == L"Focus") { SetActiveWindow(measure->windowHandle); return 1.0; } else { RmLog(LOG_ERROR, L"Focus.dll: Command invalid!"); return 0.0; } }
But when [!CommandMeasure Focus "Focus configName"] is used, GetSkinWindow() function returns null no matter the config.
I also tried to take LPCWSTR configName, as the parameter of GetSkinWindow but same results.
I didn't think of this. Thanks for pointing out. Lemme try that out.