C# 使用 WINDOWS API 指定外部程式 縮小視窗到工具列(全螢幕顯示)
C# 使用 WINDOWS API 指定外部程式 縮小視窗到工具列(全螢幕顯示)
資料來源: copilot
Code
using System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private const int SW_MINIMIZE = 6;
static void Main(string[] args)
{
// 找到目標窗口的句柄
IntPtr hWnd = FindWindow(null, "目標視窗名稱");
// 縮小視窗到工具列
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, SW_MINIMIZE);
}
else
{
Console.WriteLine("找不到目標視窗。");
}
}
}