It is currently October 24th, 2021, 9:23 am

Getting window handle of skin

Help with creating, editing & fixing problems with skins
User avatar
death.crafter
Posts: 1064
Joined: April 24th, 2021, 8:13 pm

Re: Getting window handle of skin

Post by death.crafter »

jsmorley wrote: July 23rd, 2021, 1:30 pm 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?

Code: Select all

HWND GetSkinWindow(const wchar_t* configName)
{
	HWND trayWnd = FindWindow(L"RainmeterTrayClass", NULL);
	if (trayWnd)
	{
		COPYDATASTRUCT cds;
		cds.dwData = 5101;
		cds.cbData = (DWORD)(wcslen(configName) + 1) * sizeof(wchar_t);
		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;
	if (args != L"Focus") {
		HWND hwnd = GetSkinWindow(args);
		if (hwnd == NULL) {
				RmLog(LOG_ERROR, args);
				RmLog(LOG_ERROR, L"Focus.dll: Please provide valid config!");
				return 0.0;
		}
		else {
				SetActiveWindow(hwnd);
				return 1.0;
		}
	}
	else if (args == L"Focus") {
		SetActiveWindow(measure->windowHandle);
		return 1.0;
	}
}
I changed it but still it logs errors.
Screenshot 2021-07-23 192206.png
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
My Current Desktop
User avatar
death.crafter
Posts: 1064
Joined: April 24th, 2021, 8:13 pm

Re: Getting window handle of skin

Post by death.crafter »

I am dumb lol. So sorry for wasting your time.

I was using the wrong parameters for the whole time.

Instead of using the config name I was using path to config file.

Thank you for your time.
from the Realm of Death
My Current Desktop
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting window handle of skin

Post by jsmorley »

death.crafter wrote: July 23rd, 2021, 2:46 pm I am dumb lol. So sorry for wasting your time.

I was using the wrong parameters for the whole time.

Instead of using the config name I was using path to config file.

Thank you for your time.
So you got it working the way you want?
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting window handle of skin

Post by jsmorley »

I'm betting that this whole thing could be done in Powershell without needing a plugin.
User avatar
death.crafter
Posts: 1064
Joined: April 24th, 2021, 8:13 pm

Re: Getting window handle of skin

Post by death.crafter »

jsmorley wrote: July 23rd, 2021, 3:20 pm So you got it working the way you want?
Yes. Actually what I wanted to do was achieved in the first try(focus on refresh).

I just wanted to make it cross-config compatible.
from the Realm of Death
My Current Desktop
User avatar
death.crafter
Posts: 1064
Joined: April 24th, 2021, 8:13 pm

Re: Getting window handle of skin

Post by death.crafter »

jsmorley wrote: July 23rd, 2021, 3:48 pm I'm betting that this whole thing could be done in Powershell without needing a plugin.
Yes but it takes a while.

I opened a thread here:

https://forum.rainmeter.net/viewtopic.php?f=119&t=37968

But the downside is, if the said skin wasn't in focus right before you execute it, or just refreshed, it wouldn't work because I use MainWindowTitle to get filter the results.

That's why I wanted to get the window handle. I am not sure if I can put the C++ code in powershell tho.
from the Realm of Death
My Current Desktop
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting window handle of skin

Post by jsmorley »

Seems like something like this might work:

$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate('C:\Users\JSMorley\Documents\Rainmeter\Skins\JSMeter\System\System.ini')

The WindowTitle of a skin is the full path to the .ini file.
User avatar
death.crafter
Posts: 1064
Joined: April 24th, 2021, 8:13 pm

Re: Getting window handle of skin

Post by death.crafter »

jsmorley wrote: July 23rd, 2021, 4:01 pm Seems like something like this might work:

$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate('C:\Users\JSMorley\Documents\Rainmeter\Skins\JSMeter\System\System.ini')

The WindowTitle of a skin is the full path to the .ini file.
Hmm looks good.

But this won't be instantaneous and also would be resource consuming if used with RunCommand. Escpecially with mouseoveractions and stuff.

I have an ahk executable but since some av software pick it up as antivirus I don't wanna use that. So a plugin.
My first plugin works. Hmm not bad. :D
from the Realm of Death
My Current Desktop
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting window handle of skin

Post by jsmorley »

death.crafter wrote: July 23rd, 2021, 4:07 pm Hmm looks good.

But this won't be instantaneous and also would be resource consuming if used with RunCommand. Escpecially with mouseoveractions and stuff.

I have an ahk executable but since some av software pick it up as antivirus I don't wanna use that. So a plugin.
My first plugin works. Hmm not bad. :D
Fair enough...
User avatar
Judian81
Posts: 90
Joined: May 6th, 2021, 2:57 pm

Re: Getting window handle of skin

Post by Judian81 »

is it possible to get the handler of a image meter?
windows 10