It is currently June 24th, 2024, 1:10 am

Unable to use FindWindow on Rainmeter

Share and get help with Plugins and Addons
Shimadacat
Posts: 1
Joined: April 30th, 2024, 8:04 pm

Unable to use FindWindow on Rainmeter

Post by Shimadacat »

Currently attempting to make a small .exe that will enable and disable Fountain of Colors when Spotify is open, since I only really want it open when Spotify is open. I'm trying to send Bangs using C++, and I have a near identical copy of the code provided in the "Developers" documentation section of the Rainmeter website, but it doesn't seem to work.

Code: Select all

void SendBang(const WCHAR* bang) {
	HWND rmWnd = FindWindow(L"DummyRainWClass", NULL);
	if (rmWnd)
	{
		COPYDATASTRUCT cds;
		cds.dwData = 1;
		cds.cbData = (DWORD)(wcslen(bang) + 1) * sizeof(WCHAR);
		cds.lpData = (void*)bang;

		// Send bang to the Rainmeter window
		SendMessage(rmWnd, WM_COPYDATA, 0, (LPARAM)&cds);
	}
    else {
        std::cout << "Rainmeter window not found." << std::endl;
    }
}
Every time I invoke this function it prints the error Rainmeter window not found. The else statement is, quite literally, the only modification I've made to the version of the function available on the website. What am I doing incorrectly?
Last edited by balala on April 30th, 2024, 8:48 pm, edited 1 time in total.
Reason: Please use <code> tags whenever are you posting codes. It's the </> button.
User avatar
balala
Rainmeter Sage
Posts: 16325
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Unable to use FindWindow on Rainmeter

Post by balala »

Shimadacat wrote: April 30th, 2024, 8:12 pm Currently attempting to make a small .exe that will enable and disable Fountain of Colors when Spotify is open, since I only really want it open when Spotify is open. I'm trying to send Bangs using C++, and I have a near identical copy of the code provided in the "Developers" documentation section of the Rainmeter website, but it doesn't seem to work.
I can't answer your question, but have another: why do you want to write a .exe for such a task? .exe files are extremely undesirable (exprecially if you'll want distributing yor skin). I assume a (simple) Rainmeter skin could do the job. The skin has to check if Spotify runs and act accordingly. You don't even need to much things, just:
  • A Process measure, which checks if Spotify runs:

    Code: Select all

    [MeasureSpotify]
    Measure=Process
    ProcessName=Spotify.exe
    I'm not using Spotify, but what you have to take care about the above code is to use the proper process name in the ProcessName option. I just assumed this name should be Spotify.exe, but if you're using Spotify, you are the one who has to find the proper name.
  • A set of IfCondition, to let the skin activating Fountain of Colors when Spotify runs and deactivate it otherwise. Try for instance the following options:

    Code: Select all

    [MeasureSpotify]
    Measure=Process
    ProcessName=Spotify.exe
    IfCondition=(#CURRENTSECTION#>0)
    IfTrueAction=[!ActivateConfig "Fountain of Colors" "Fountain of Colors.ini"]
    IfFalseAction=[!DeactivateConfig "Fountain of Colors"]
    
Can't try out this code, because as said I'm not using Spotify, but tried it with another process and worked. If you can find the name of the process of Spotify, it should work for you as well. Does it?
User avatar
Brian
Developer
Posts: 2699
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Unable to use FindWindow on Rainmeter

Post by Brian »

balala's answer is probably the easier way to go if this is the only task your .exe is doing.

As far as why FindWindow is failing, I have no idea. You could try one of the following to see if they work.
  1. Also use the window's title: HWND rmWnd = FindWindow(L"DummyRainWClass", L"Rainmeter control window");
  2. Try using FindWindowEx (with and without the window's title): HWND rmWnd = FindWindowEx(NULL, NULL, L"DummyRainWClass", NULL); or HWND rmWnd = FindWindowEx(NULL, NULL, L"DummyRainWClass", L"Rainmeter control window");

-Brian
User avatar
Yincognito
Rainmeter Sage
Posts: 7492
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Unable to use FindWindow on Rainmeter

Post by Yincognito »

Besides balala's and Brian's suggestions, if you really want an .exe doing that, you could try AutoIt or AutoHotKey, as the process is roughly similar to C++ (using another window class though, not sure if the example from the manual is up to date in that regard - you could try that in C++ too and see if it changes things for the better), see this related example:
https://forum.rainmeter.net/viewtopic.php?t=42450&start=20#p215590
In AutoHotKey I could only do an equivalent v1 code, since there are a few changes in v2 that I either don't know how to implement or I do it incorrectly (nobody on their forum answered me on that issue yet).

In any case, these things are possible in these programs too, since I basically made an almost complete "window spy" skin working with the rarely used WindowMessage plugin for Rainmeter.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth