Hello! Thank you for this plugin!
I also needed the feature of detecting maximized and windowed windows, so I decided to alter your plugin to handle those cases as well. It was fairly easy.
CPP code
Code: Select all
#include <Windows.h>
#include <WinUser.h>
#include <Psapi.h>
#include <string>
#include "../../API/RainmeterAPI.h"
struct Measure
{
std::wstring processName;
Measure() {}
};
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
Measure* measure = (Measure*)data;
}
PLUGIN_EXPORT double Update(void* data)
{
Measure* measure = (Measure*)data;
measure->processName.clear();
// 1.0 = fullscreen
// 2.0 = maximized
// 3.0 = windowed
double foundResult= 0.0;
RECT appBounds = { 0 };
RECT screenBounds = { 0 };
HWND foregroundHandle = GetForegroundWindow();
GetWindowRect(GetDesktopWindow(), &screenBounds);
if (foregroundHandle != GetDesktopWindow() && foregroundHandle != GetShellWindow())
{
DWORD processPID;
GetWindowThreadProcessId(foregroundHandle, &processPID);
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processPID);
if (processHandle)
{
WCHAR processName[MAX_PATH];
if (0 != GetModuleBaseName(processHandle, NULL, processName, MAX_PATH))
{
measure->processName = processName;
}
CloseHandle(processHandle);
}
// Fullscreen
GetWindowRect(foregroundHandle, &appBounds);
if (EqualRect(&appBounds, &screenBounds))
{
foundResult = 1.0;
}
// Maximized
else if (IsZoomed(foregroundHandle)) {
foundResult = 2.0;
}
// Windowed
// Probably could've used only else, but this is here for a sanity check
else if (IsWindowVisible(foregroundHandle)) {
foundResult = 3.0;
}
}
return foundResult;
}
PLUGIN_EXPORT LPCWSTR GetString(void* data)
{
Measure* measure = (Measure*)data;
return measure->processName.c_str();
}
//PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
//{
// Measure* measure = (Measure*)data;
//}
PLUGIN_EXPORT void Finalize(void* data)
{
Measure* measure = (Measure*)data;
delete measure;
}
skin code
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Metadata]
Name=ForegroundWindowState
Author=JSMorley (updated 2/2020)
Version=4.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Information=Demonstrates ForegroundWindowState Plugin.
; This plugin will check to see if the "foreground" window, the window that currently has
; "focus", is full screen, maximized, or windowed.
; Values returned:
; 1 if full screen,
; 2 if maximized
; 3 if windowed
; 0 none of these (probably an unhandled condition)
; empty string: Desktop has focus
; The name of the process for the currently focused window will
; be returned as the string value. An empty string will be returned if the Desktop has focus.
; Note that this applies to windows on the "primary" monitor only.
; Note that this will be unable to detect any process run "As administrator" unless Rainmeter itself is run "As administrator".
[MeasureForegroundWindowState]
Measure=Plugin
Plugin=ForegroundWindowState
IfCondition=MeasureForegroundWindowState=1
IfTrueAction=[!SetOption MeterForegroundWindowState Text "Full screen and has focus"][!UpdateMeter *][!Redraw]
IfCondition2=MeasureForegroundWindowState=2
IfTrueAction2=[!SetOption MeterForegroundWindowState Text "Maximized and has focus"][!UpdateMeter *][!Redraw]
IfCondition3=MeasureForegroundWindowState=3
IfTrueAction3=[!SetOption MeterForegroundWindowState Text "Windowed and has focus"][!UpdateMeter *][!Redraw]
IfCondition4=MeasureForegroundWindowState=0
IfTrueAction4=[!SetOption MeterForegroundWindowState Text "Unhandled condition. You should report this"][!UpdateMeter *][!Redraw]
IfMatch=^$
IfMatchAction=[!SetOption MeterProcessName Text "Desktop"][!HideMeter MeterForegroundWindowState][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterProcessName Text ""][!ShowMeter MeterForegroundWindowState][!UpdateMeter *][!Redraw]
[MeterProcessName]
Meter=String
MeasureName=MeasureForegroundWindowState
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
[MeterForegroundWindowState]
Meter=String
Y=30
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
I also compiled the dll's already into a rmskin.
I renamed the plugin as it includes more features. I consider it the 4th version of your plugin. Thanks for your plugin again.
P.S. Forgive me if I got anything wrong. This is literally my FIRST foray into rainmeter. It seems the first thing I did was edit a dll plugin instead of making a skin.
Should I make this a new topic instead?
Also note: This was built in the latest version of Windows 10. I don't guarantee support for any older Windows OS versions.
ForegroundWindowState_4.0.rmskin
You do not have the required permissions to view the files attached to this post.