Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Toggle hide/show window of Chrome browser

Description
This script will hide and show Chrome browser windows.
Language
C#.net
Minimum Version
Created By
KarolPiechoczek
Contributors
-
Date Created
12d ago
Date Last Modified
12d ago

Scripted Function (Macro) Code

using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
	public static int SW_SHOW = 5;
	public static int SW_HIDE = 0;

	[DllImport("user32.dll")]
	private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

	public static void Run()
	{
		if (!File.Exists($@"{Path.GetTempPath()}\hwnd.txt"))
		{
			HideChrome();
		}
		else
		{
			ShowChrome();
		}
	}

	private static void HideChrome()
	{
		Process[] processes = Process.GetProcessesByName("chrome");

		foreach (Process process in processes)
		{
			IntPtr HWND = process.MainWindowHandle;
			if (HWND != IntPtr.Zero)
			{
				File.AppendAllText($@"{Path.GetTempPath()}\hwnd.txt", HWND.ToString());
				ShowWindow(HWND, SW_HIDE);
			}
		}
	}

	private static void ShowChrome()
	{
		IntPtr HWND = (IntPtr) Convert.ToInt32(File.ReadAllText($@"{Path.GetTempPath()}\hwnd.txt"));
		Thread.Sleep(500);
		ShowWindow(HWND, SW_SHOW);
		Thread.Sleep(1000);
		File.Delete($@"{Path.GetTempPath()}\hwnd.txt");
	}
}