跳到正文

个人记录

摸鱼工具

The_Novelist约 43 分钟
原文

这是 2026年4月28日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年8月19日
收录
2026年4月28日
更新
2026年11月13日
篇幅
约 43 分钟

版本

  1. v2当前
  2. v1

透明窗口:

C++
#include<iostream>//输入1 透明度,然后在两秒内点击要变透明的页 0最低,255最高
#include<cmath>
#include<queue>
#include<stack>
#include<windows.h>
#include<windowsx.h>
#include <commctrl.h>
#include<tlhelp32.h>
#include<cstring>
#define NT_SUCCESS(Status)              (((NTSTATUS)(Status)) >= 0)
#define NT_INFORMATION(Status)          ((((ULONG)(Status)) >> 30) == 1)
#define NT_WARNING(Status)              ((((ULONG)(Status)) >> 30) == 2)
#define NT_ERROR(Status)                ((((ULONG)(Status)) >> 30) == 3)
#define MB_TERMINTE 10001
#define MB_TERMINTEIDEDIT 10002
#define MB_TERMINTEBTN 10003
#define WM_SHOWMSG 20001
#define HK_START 30001
using namespace std;
/*BOOL WndShow = TRUE;
BOOL HaveGotChild = FALSE;
HWND HwndTerminateID;
HWND hwndBtnTerminate;
HWND Hwnds[1001];
UINT msg_count = 0;
HMODULE ntdll;
typedef NTSTATUS (*PNTTERMINATEPROCESS)(HANDLE ProcessHandle,NTSTATUS ExitStatus);
PNTTERMINATEPROCESS NtTerminateProcess;
LRESULT MainWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
LRESULT TerminateWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
LRESULT DesktopWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
BOOL RegClass(LPCWSTR WndClassName, WNDPROC WndProc){
	WNDCLASSW wcs;
	wcs.style = CS_HREDRAW | CS_VREDRAW;
	wcs.lpfnWndProc = WndProc;
	wcs.cbClsExtra = 0;
	wcs.cbWndExtra = 0;
	wcs.hInstance = GetModuleHandleW(NULL);
	wcs.hIcon = LoadIconA(NULL, MAKEINTRESOURCE(32518));
	wcs.hCursor = LoadCursorA(NULL, MAKEINTRESOURCE(32512));
	wcs.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
	wcs.lpszMenuName = NULL;
	wcs.lpszClassName = WndClassName;
	if(!RegisterClassW(&wcs)){
		return FALSE;
	}
	return TRUE;
}
HWND CreateWnd(LPCWSTR WndClassName, LPCWSTR WndName, UINT Width, UINT Height, DWORD Style){
	UINT ScrX = GetSystemMetrics(SM_CXSCREEN);
	UINT ScrY = GetSystemMetrics(SM_CYSCREEN);	
	HWND hwnd = CreateWindowExW(WS_EX_LAYERED, WndClassName, WndName, Style, (ScrX - Width) / 2 + 1, (ScrY - Height) / 2 + 1, Width, Height, NULL, NULL, GetModuleHandle(NULL), NULL);
	ShowWindow(hwnd, SW_SHOW);
	UpdateWindow(hwnd);
	return hwnd;
}
VOID WndLoop(){
	MSG msg;
	while(GetMessageW(&msg, NULL, 0, 0)){
		TranslateMessage(&msg);
		DispatchMessageW(&msg);
	}
}*/
int main(){
	int op;
	int a;
	HWND hwnd;
	while(true){
		cin>>op;
		if(op==1){
			cin>>a;
			Sleep(2000);
			hwnd=GetForegroundWindow();
			SetWindowLongPtr(hwnd,GWL_EXSTYLE,WS_EX_LAYERED);
			SetLayeredWindowAttributes(hwnd,RGB(0,0,1),a,LWA_ALPHA);
			SendMessage(hwnd,WM_PAINT,0,0);	
		}
		if(op==2){
			cin>>a;
			Sleep(2000);
			hwnd=GetForegroundWindow();
			if(a==0){
				SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
			}
			else if(a==1){
				SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
			}
			SendMessage(hwnd,WM_PAINT,0,0);	
		}	
		if(op==3){
			Sleep(2000);
			hwnd=GetForegroundWindow();	
			SetForegroundWindow(hwnd);
			keybd_event(18,0,0,0);
			Sleep(30);
			keybd_event(115,0,0,0);
			Sleep(30);
			keybd_event(115,0,KEYEVENTF_KEYUP,0);
			Sleep(30);
			keybd_event(18,0,KEYEVENTF_KEYUP,0);
			SendMessage(hwnd,WM_CLOSE,0,0);	
			SendMessage(hwnd,WM_DESTROY,0,0);	
			SendMessage(hwnd,WM_QUIT,0,0);	
			DestroyWindow(hwnd);
		}		
	}
/*	RegClass(L"DesktopWnd", DesktopWndProc);
	HWND MainWnd = CreateWnd(L"DesktopWnd", L"DrawDesktop", 600, 500, WS_OVERLAPPEDWINDOW );
	//qmsg.push(MSG_SUCCESS, 2000, L"Success");
	if(MainWnd == NULL){
		MessageBoxW(NULL, L"Failed to CreateWindow", L"Error", MB_OK|MB_ICONERROR|MB_TASKMODAL);
		return -3;
	}
	SetLayeredWindowAttributes(MainWnd,RGB(0,0,1),125,LWA_ALPHA);
	//Sleep(1000);
	WndLoop();*/
}
/*LRESULT DesktopWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	return DefWindowProcW(hwnd, msg, wparam, lparam);
}*/

第2版:

C++
//再执行时的前五秒选择窗口,以后就一直作用于该窗口
//4 0 让该窗口不在任务栏上显示
//4 1 让该窗口在任务栏上显示
//5 0 显示该窗口
//5 1 隐藏该窗口
#include<iostream>
#include<cmath>
#include<queue>
#include<stack>
#include<windows.h>
#include<windowsx.h>
#include <commctrl.h>
#include<tlhelp32.h>
#include<cstring>
#define NT_SUCCESS(Status)              (((NTSTATUS)(Status)) >= 0)
#define NT_INFORMATION(Status)          ((((ULONG)(Status)) >> 30) == 1)
#define NT_ERROR(Status)                ((((ULONG)(Status)) >> 30) == 3)
#define MB_TERMINTE 10001
#define MB_TERMINTEIDEDIT 10002
#define MB_TERMINTEBTN 10003
#define WM_SHOWMSG 20001
#define HK_START 30001
using namespace std;
/*BOOL WndShow = TRUE;
BOOL HaveGotChild = FALSE;
HWND HwndTerminateID;
HWND hwndBtnTerminate;
HWND Hwnds[1001];
UINT msg_count = 0;
HMODULE ntdll;
typedef NTSTATUS (*PNTTERMINATEPROCESS)(HANDLE ProcessHandle,NTSTATUS ExitStatus);
PNTTERMINATEPROCESS NtTerminateProcess;
LRESULT MainWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
LRESULT TerminateWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
LRESULT DesktopWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
BOOL RegClass(LPCWSTR WndClassName, WNDPROC WndProc){
	WNDCLASSW wcs;
	wcs.style = CS_HREDRAW | CS_VREDRAW;
	wcs.lpfnWndProc = WndProc;
	wcs.cbClsExtra = 0;
	wcs.cbWndExtra = 0;
	wcs.hInstance = GetModuleHandleW(NULL);
	wcs.hIcon = LoadIconA(NULL, MAKEINTRESOURCE(32518));
	wcs.hCursor = LoadCursorA(NULL, MAKEINTRESOURCE(32512));
	wcs.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
	wcs.lpszMenuName = NULL;
	wcs.lpszClassName = WndClassName;
	if(!RegisterClassW(&wcs)){
		return FALSE;
	}
	return TRUE;
}
HWND CreateWnd(LPCWSTR WndClassName, LPCWSTR WndName, UINT Width, UINT Height, DWORD Style){
	UINT ScrX = GetSystemMetrics(SM_CXSCREEN);
	UINT ScrY = GetSystemMetrics(SM_CYSCREEN);	
	HWND hwnd = CreateWindowExW(WS_EX_LAYERED, WndClassName, WndName, Style, (ScrX - Width) / 2 + 1, (ScrY - Height) / 2 + 1, Width, Height, NULL, NULL, GetModuleHandle(NULL), NULL);
	ShowWindow(hwnd, SW_SHOW);
	UpdateWindow(hwnd);
	return hwnd;
}
VOID WndLoop(){
	MSG msg;
	while(GetMessageW(&msg, NULL, 0, 0)){
		TranslateMessage(&msg);
		DispatchMessageW(&msg);
	}
}*/
int main(){
	int op;
	int a;
	HWND hwnd;
	Sleep(5000);
	hwnd=GetForegroundWindow();
	cout<<"selete done";
	while(true){
		cin>>op;
		if(op==1){
			cin>>a;
			SetWindowLongPtr(hwnd,GWL_EXSTYLE,WS_EX_LAYERED);
			SetLayeredWindowAttributes(hwnd,RGB(0,0,1),a,LWA_ALPHA);
			SendMessage(hwnd,WM_PAINT,0,0);	
		}
		if(op==2){
			cin>>a;
			if(a==0){
				SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
			}
			else if(a==1){
				SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
			}
			SendMessage(hwnd,WM_PAINT,0,0);	
		}	
		if(op==3){
			SetForegroundWindow(hwnd);
			SendMessage(hwnd,WM_CLOSE,0,0);	
			SendMessage(hwnd,WM_DESTROY,0,0);	
			SendMessage(hwnd,WM_QUIT,0,0);	
			DestroyWindow(hwnd);
		}if (op == 4) { // 控制任务栏显示状态
            cin >> a;
            LONG exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);

            if (a == 0) {
                // 隐藏任务栏图标:添加工具窗口样式,移除应用窗口样式
                exStyle |= WS_EX_TOOLWINDOW;   // 工具窗口不显示在任务栏
                exStyle &= ~WS_EX_APPWINDOW;   // 移除应用窗口样式(避免任务栏显示)
                SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle);
                cout << "已隐藏任务栏中的窗口图标" << endl;
            } 

            // 强制刷新窗口样式(必须调用,否则样式不生效)
            SetWindowPos(hwnd, NULL, 0, 0, 0, 0, 
                       SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
        } 
		if(op==5){
			cin>>a;
			if(a==0)	ShowWindow(hwnd,SW_SHOW);
			else	ShowWindow(hwnd,SW_HIDE);
			SendMessage(hwnd,WM_PAINT,0,0);	
		}
	}
/*	RegClass(L"DesktopWnd", DesktopWndProc);
	HWND MainWnd = CreateWnd(L"DesktopWnd", L"DrawDesktop", 600, 500, WS_OVERLAPPEDWINDOW );
	//qmsg.push(MSG_SUCCESS, 2000, L"Success");
	if(MainWnd == NULL){
		MessageBoxW(NULL, L"Failed to CreateWindow", L"Error", MB_OK|MB_ICONERROR|MB_TASKMODAL);
		return -3;
	}
	SetLayeredWindowAttributes(MainWnd,RGB(0,0,1),125,LWA_ALPHA);
	//Sleep(1000);
	WndLoop();*/
}
/*LRESULT DesktopWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	return DefWindowProcW(hwnd, msg, wparam, lparam);
}*/

窗口图标的没有:

C++
#include <Windows.h>
#include <iostream>

// 简化版本 - 隐藏指定窗口的任务栏图标
int main() {
	//std::cout << "=== 窗口任务栏图标隐藏工具 ===" << std::endl;
	//std::cout << "请先打开目标窗口,然后回到此程序..." << std::endl;
	std::cout << "按回车键继续..." << std::endl;
	std::cin.get();
	//std::cout << "请在5秒内切换到要隐藏的窗口..." << std::endl;
	Sleep(5000); // 等待5秒让用户切换窗口
	// 获取当前前景窗口(用户切换到的窗口)
	HWND targetWindow = GetForegroundWindow();

	if (targetWindow == NULL) {
		std::cout << "无法获取窗口句柄!" << std::endl;
		return -1;
	}

	// 获取窗口标题
	char windowTitle[256];
	GetWindowTextA(targetWindow, windowTitle, sizeof(windowTitle));

	std::cout << "找到窗口: " << windowTitle << std::endl;
	std::cout << "(y/n): ";

	char choice;
	std::cin >> choice;

	if (choice == 'y' || choice == 'Y') {
		// 方法1: 修改窗口样式来隐藏任务栏图标
		LONG_PTR style = GetWindowLongPtr(targetWindow, GWL_EXSTYLE);
		SetWindowLongPtr(targetWindow, GWL_EXSTYLE, style | WS_EX_TOOLWINDOW);

		// 强制刷新窗口
		SetWindowPos(targetWindow, NULL, 0, 0, 0, 0,
		             SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

		std::cout << "X!" << std::endl;
		//std::cout << "注意: 重启程序后图标会恢复显示。" << std::endl;
	} else {
		std::cout << "操作已取消。" << std::endl;
	}

	std::cout << "按回车键退出..." << std::endl;
	std::cin.ignore();
	std::cin.get();

	return 0;
}

隐藏窗口2:

C++
#include <windows.h>
#include <stdio.h>

// 全局变量
HWND g_hTargetWindow = NULL;
BOOL g_bIsHidden = FALSE;

// 隐藏任务栏图标
void HideTaskbarIcon(HWND hwnd) {
    if (hwnd && IsWindow(hwnd)) {
        LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_TOOLWINDOW);
        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, 
                    SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
        g_bIsHidden = TRUE;
        g_hTargetWindow = hwnd;
        printf("窗口已隐藏!\n");
    }
}

// 恢复任务栏图标
void RestoreTaskbarIcon(HWND hwnd) {
    if (hwnd && IsWindow(hwnd)) {
        LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_TOOLWINDOW);
        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, 
                    SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
        g_bIsHidden = FALSE;
        g_hTargetWindow = NULL;
        printf("窗口已恢复!\n");
    }
}

// 获取窗口标题
void GetWindowTitle(HWND hwnd, char* buffer, int bufferSize) {
    GetWindowTextA(hwnd, buffer, bufferSize);
}

int main() {
    printf("=== 简单窗口隐藏工具 ===\n");
    printf("请先打开要隐藏的窗口,然后按回车键...\n");
    getchar();
    
    printf("请在3秒内切换到目标窗口...\n");
    Sleep(3000);
    
    // 获取当前活动窗口
    HWND hForeground = GetForegroundWindow();
    
    if (hForeground == NULL) {
        printf("无法获取窗口!\n");
        return 1;
    }
    
    char szTitle[256];
    GetWindowTitle(hForeground, szTitle, sizeof(szTitle));
    
    printf("当前窗口: %s\n", szTitle);
    printf("是否隐藏此窗口?(Y/N): ");
    
    char chChoice;
    scanf("%c", &chChoice);
    
    if (chChoice == 'Y' || chChoice == 'y') {
        HideTaskbarIcon(hForeground);
        printf("\n隐藏成功!按R恢复,按其他键退出: ");
        
        getchar(); // 清除缓冲区的回车
        chChoice = getchar();
        
        if (chChoice == 'R' || chChoice == 'r') {
            RestoreTaskbarIcon(hForeground);
        }
    } else {
        printf("操作取消。\n");
    }
    
    printf("按回车退出...\n");
    getchar();
    getchar(); // 等待按键
    
    return 0;
}

最终版!!!

C++
#include <windows.h>
#include <stdio.h>

// 全局变量
HWND g_hTargetWindow = NULL;
BOOL g_bIsHidden = FALSE;

// 隐藏任务栏图标
void HideTaskbarIcon(HWND hwnd) {
    if (hwnd && IsWindow(hwnd)) {
        LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, style | 0x80); // WS_EX_TOOLWINDOW
        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, 
                    0x0002 | 0x0001 | 0x0004 | 0x0020); // SWP flags
        g_bIsHidden = TRUE;
        g_hTargetWindow = hwnd;
        
        char title[256];
        GetWindowTextA(hwnd, title, sizeof(title));
        printf("已隐藏窗口: %s\n", title);
    }
}

// 恢复任务栏图标
void RestoreTaskbarIcon(HWND hwnd) {
    if (hwnd && IsWindow(hwnd)) {
        LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, style & ~0x80); // 移除WS_EX_TOOLWINDOW
        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, 
                    0x0002 | 0x0001 | 0x0004 | 0x0020); // SWP flags
        g_bIsHidden = FALSE;
        g_hTargetWindow = NULL;
        printf("已恢复窗口\n");
    }
}

// 隐藏控制台窗口
void HideConsole() {
    HWND hwnd = GetConsoleWindow();
    if (hwnd) {
        ShowWindow(hwnd, SW_HIDE);
    }
}

// 显示控制台窗口
void ShowConsole() {
    HWND hwnd = GetConsoleWindow();
    if (hwnd) {
        ShowWindow(hwnd, SW_SHOW);
    }
}

// 处理热键消息
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch (msg) {
        case WM_HOTKEY:
            switch (wParam) {
                case 1: // Ctrl+Alt+H - 隐藏当前窗口
                    {
                        HWND foreground = GetForegroundWindow();
                        if (foreground && foreground != GetConsoleWindow()) {
                            HideTaskbarIcon(foreground);
                            
                            // 显示提示然后隐藏
                            ShowConsole();
                            printf("窗口已隐藏!3秒后自动隐藏...\n");
                            Sleep(3000);
                            HideConsole();
                        }
                    }
                    break;
                    
                case 2: // Ctrl+Alt+S - 恢复窗口
                    if (g_bIsHidden && g_hTargetWindow) {
                        RestoreTaskbarIcon(g_hTargetWindow);
                        
                        // 显示提示然后隐藏
                        ShowConsole();
                        printf("窗口已恢复!3秒后自动隐藏...\n");
                        Sleep(3000);
                        HideConsole();
                    }
                    break;
                    
                case 3: // Ctrl+Alt+Q - 退出
                    PostQuitMessage(0);
                    break;
            }
            break;
            
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
            
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    // 注册窗口类(用于接收消息)
    WNDCLASS wc = {0};
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = "HotkeyHider";
    
    if (!RegisterClass(&wc)) {
        return 1;
    }
    
    // 创建隐藏的消息窗口
    HWND hwnd = CreateWindow("HotkeyHider", NULL, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
    if (!hwnd) {
        return 1;
    }
    
    // 注册热键
    if (!RegisterHotKey(hwnd, 1, MOD_CONTROL | MOD_ALT, 'H') ||
        !RegisterHotKey(hwnd, 2, MOD_CONTROL | MOD_ALT, 'S') ||
        !RegisterHotKey(hwnd, 3, MOD_CONTROL | MOD_ALT, 'Q')) {
        MessageBox(NULL, "热键注册失败!可能已被其他程序占用。", "错误", MB_ICONERROR);
        return 1;
    }
    
    // 显示初始提示
    ShowConsole();
    printf("=== 隐蔽窗口隐藏器 ===\n");
    printf("热键说明:\n");
    printf("Ctrl+Alt+H - 隐藏当前窗口\n");
    printf("Ctrl+Alt+S - 恢复隐藏的窗口\n");
    printf("Ctrl+Alt+Q - 退出程序\n");
    printf("程序将在5秒后隐藏到后台...\n");
    Sleep(5000);
    HideConsole();
    
    // 消息循环
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    
    // 清理
    if (g_bIsHidden && g_hTargetWindow) {
        RestoreTaskbarIcon(g_hTargetWindow);
    }
    
    UnregisterHotKey(hwnd, 1);
    UnregisterHotKey(hwnd, 2);
    UnregisterHotKey(hwnd, 3);
    DestroyWindow(hwnd);
    
    return 0;
}

版2(XX.ps1)(双击后点”使用PowerShell运行”):

Python
# 窗口隐藏工具 - PowerShell热键版
# 双击运行,无需编译

Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class HotkeyHider {
    [DllImport("user32.dll")]
    public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
    
    [DllImport("user32.dll")]
    public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
    
    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();
    
    [DllImport("user32.dll")]
    public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
    
    [DllImport("user32.dll")]
    public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
    [DllImport("user32.dll")]
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    
    [DllImport("user32.dll")]
    public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
    public const int GWL_EXSTYLE = -20;
    public const int WS_EX_TOOLWINDOW = 0x00000080;
    public const uint SWP_NOMOVE = 0x0002;
    public const uint SWP_NOSIZE = 0x0001;
    public const uint SWP_NOZORDER = 0x0004;
    public const uint SWP_FRAMECHANGED = 0x0020;
    
    public const uint MOD_CONTROL = 0x0002;
    public const uint MOD_ALT = 0x0001;
}
"@

# 创建窗体来接收热键消息
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Visible = $false
$form.ShowInTaskbar = $false

# 注册热键
[HotkeyHider]::RegisterHotKey($form.Handle, 1, [HotkeyHider]::MOD_CONTROL -bor [HotkeyHider]::MOD_ALT, [System.Windows.Forms.Keys]::H)
[HotkeyHider]::RegisterHotKey($form.Handle, 2, [HotkeyHider]::MOD_CONTROL -bor [HotkeyHider]::MOD_ALT, [System.Windows.Forms.Keys]::S)
[HotkeyHider]::RegisterHotKey($form.Handle, 3, [HotkeyHider]::MOD_CONTROL -bor [HotkeyHider]::MOD_ALT, [System.Windows.Forms.Keys]::Q)

# 显示提示
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show(
"隐蔽窗口隐藏器已启动!

热键说明:
Ctrl + Alt + H = 隐藏当前窗口
Ctrl + Alt + S = 恢复最近隐藏的窗口  
Ctrl + Alt + Q = 退出程序

程序将在后台运行,通过热键操作。",
"窗口隐藏工具", 
"OK", 
"Information")

# 热键处理
$form.Add_Load({
    $form.WindowState = 'Minimized'
})

$hiddenWindow = $null

$form.Add_WndProc({
    param($sender, $e)
    
    if ($e.Msg -eq 0x0312) { # WM_HOTKEY
        switch ($e.WParam) {
            1 { # Ctrl+Alt+H
                $hwnd = [HotkeyHider]::GetForegroundWindow()
                if ($hwnd -ne [IntPtr]::Zero) {
                    $style = [HotkeyHider]::GetWindowLong($hwnd, [HotkeyHider]::GWL_EXSTYLE)
                    [HotkeyHider]::SetWindowLong($hwnd, [HotkeyHider]::GWL_EXSTYLE, $style -bor [HotkeyHider]::WS_EX_TOOLWINDOW)
                    [HotkeyHider]::SetWindowPos($hwnd, [IntPtr]::Zero, 0, 0, 0, 0, 
                                              [HotkeyHider]::SWP_NOMOVE -bor [HotkeyHider]::SWP_NOSIZE -bor 
                                              [HotkeyHider]::SWP_NOZORDER -bor [HotkeyHider]::SWP_FRAMECHANGED)
                    $hiddenWindow = $hwnd
                    
                    $sb = New-Object System.Text.StringBuilder(256)
                    [HotkeyHider]::GetWindowText($hwnd, $sb, $sb.Capacity)
                    $title = $sb.ToString()
                    
                    # 显示短暂提示
                    $notify = New-Object System.Windows.Forms.NotifyIcon
                    $notify.Icon = [System.Drawing.SystemIcons]::Information
                    $notify.Visible = $true
                    $notify.ShowBalloonTip(2000, "隐藏成功", "已隐藏窗口: $title", [System.Windows.Forms.ToolTipIcon]::Info)
                    Start-Sleep -Seconds 2
                    $notify.Dispose()
                }
            }
            2 { # Ctrl+Alt+S
                if ($hiddenWindow -ne $null) {
                    $style = [HotkeyHider]::GetWindowLong($hiddenWindow, [HotkeyHider]::GWL_EXSTYLE)
                    [HotkeyHider]::SetWindowLong($hiddenWindow, [HotkeyHider]::GWL_EXSTYLE, $style -band (-bnot [HotkeyHider]::WS_EX_TOOLWINDOW))
                    [HotkeyHider]::SetWindowPos($hiddenWindow, [IntPtr]::Zero, 0, 0, 0, 0, 
                                              [HotkeyHider]::SWP_NOMOVE -bor [HotkeyHider]::SWP_NOSIZE -bor 
                                              [HotkeyHider]::SWP_NOZORDER -bor [HotkeyHider]::SWP_FRAMECHANGED)
                    $hiddenWindow = $null
                    
                    # 显示短暂提示
                    $notify = New-Object System.Windows.Forms.NotifyIcon
                    $notify.Icon = [System.Drawing.SystemIcons]::Information
                    $notify.Visible = $true
                    $notify.ShowBalloonTip(2000, "恢复成功", "已恢复隐藏的窗口", [System.Windows.Forms.ToolTipIcon]::Info)
                    Start-Sleep -Seconds 2
                    $notify.Dispose()
                }
            }
            3 { # Ctrl+Alt+Q
                # 退出前恢复窗口
                if ($hiddenWindow -ne $null) {
                    $style = [HotkeyHider]::GetWindowLong($hiddenWindow, [HotkeyHider]::GWL_EXSTYLE)
                    [HotkeyHider]::SetWindowLong($hiddenWindow, [HotkeyHider]::GWL_EXSTYLE, $style -band (-bnot [HotkeyHider]::WS_EX_TOOLWINDOW))
                    [HotkeyHider]::SetWindowPos($hiddenWindow, [IntPtr]::Zero, 0, 0, 0, 0, 
                                              [HotkeyHider]::SWP_NOMOVE -bor [HotkeyHider]::SWP_NOSIZE -bor 
                                              [HotkeyHider]::SWP_NOZORDER -bor [HotkeyHider]::SWP_FRAMECHANGED)
                }
                $form.Close()
            }
        }
    }
})

# 运行程序
[System.Windows.Forms.Application]::Run($form)

# 清理热键
[HotkeyHider]::UnregisterHotKey($form.Handle, 1)
[HotkeyHider]::UnregisterHotKey($form.Handle, 2)
[HotkeyHider]::UnregisterHotKey($form.Handle, 3)