标题
增加 1 行删除 1 行
1改良版窗口透明器,摸鱼绝佳助手!1辅助摸鱼的一个小玩具——窗口透明器
正文
增加 195 行删除 91 行
1234567891011121314101 行未改动全部展开116117118119120121122123124315 行未改动全部展开440441442443444445446447448376 行未改动全部展开82582682782882983083183223 行未改动85685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890939 行未改动94995095195295395495595695795895996096196296396496596696796896997097197212 行未改动9859869879889899909919929939943 行未改动998999100010011002100310041005100610077 行未改动1015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111829 行未改动11921193119411951196119711981199120012011202120312041205120612071208120927 行未改动123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712686 行未改动1275127612771278127912801281128212831284128512861287128812891290129112921293129421 行未改动13161317131813191320132113221323132413251326# 窗口透明器退役 Oier,并非专业干工程的,做得不够优秀的地方请多指教。由 C++ 编写,用于 Windows。公布源代码,需要在自己电脑上编译一下。编译须知见后文,使用说明程序里有。发现 BUG 可找作者私信反馈,最多大概两天会看到。:::info[源代码]```cpp// 禁用Windows宏冲突#ifdef _WIN32#ifndef NOMINMAX#define NOMINMAX101 行未改动全部展开if (GetKeyNameText(lParam, keyName, sizeof(keyName))) {result += keyName;} else {char buffer[32];sprintf_s(buffer, "0x%02X", mainKey);result += buffer;}}return result;315 行未改动全部展开return string(mbBuffer);}// 返回虚拟键码char buffer[32];sprintf_s(buffer, "Key 0x%02X", vkCode);return string(buffer);}}}376 行未改动全部展开const int COLOR_LIGHTPURPLE = 13;const int COLOR_LIGHTYELLOW = 14;const int COLOR_LIGHTWHITE = 15;//更改颜色 文字+背景void SetColorAndBackground(int ForgC, int BackC) {WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);23 行未改动CONSOLE_CURSOR_INFO cursor_info = {1, x}; // 第二个值为 0 表示隐藏光标SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);}//按钮class Button {public:int x, y;string name;int len;// 构造函数Button(int _x, int _y, string _name, int _len, bool isPrint = true): x(_x), y(_y), name(_name), len(_len) {if (isPrint) {SetCursorPosition(x, y);cout << name;}}// 输出内容void printText() {SetCursorPosition(x, y);cout << name;}// 点击监听bool isClicked() {// SetCursorPosition(x,y);POINT pt;GetCursorPosition(pt);if (KEY_DOWN(MOUSE_MOVED)) {// cout << pt.x << " " << pt.y << endl;if (pt.y == y && (pt.x >= x && pt.x <= x + len)) {return 1;}}return 0;}};string WStringToUTF8(const wstring& wstr) {if (wstr.empty()) return string();int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);string strTo(size_needed, 0);WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);return strTo;}// IsWindow 检查窗口句柄是否存在bool isHandleValid(HWND hwnd) {return ::IsWindow(hwnd);}39 行未改动// 设置透明度return SetLayeredWindowAttributes(hwnd, 0, (BYTE)alpha, LWA_ALPHA);}// 获取标题string GetWindowTitle(HWND hwnd) {wchar_t windowTitle[1024];GetWindowTextW(hwnd, windowTitle, 1024);return WStringToUTF8(windowTitle);}//查询指定窗口是否隐藏bool isWindowHidden(HWND hwnd) {if (hwnd == NULL) {return 0;}LONG style = GetWindowLong(hwnd, GWL_STYLE);return (style & WS_VISIBLE) == 0;}int deltaAlpha = 20;vector<HWND> hiddenWindow;12 行未改动}}}, 1);// Ctrl+VK_ADD 不透明listener.RegisterComboKey(VK_ADD, 1, 0, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();int nowA = GetWindowTransparency(nowH);if (nowA > 255 - deltaAlpha) {3 行未改动}}}, 1);// Ctrl+VK_SUBTRACT 透明listener.RegisterComboKey(VK_SUBTRACT, 1, 0, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();int nowA = GetWindowTransparency(nowH);if (nowA < 2 * deltaAlpha) {7 行未改动// Ctrl+Space 隐藏listener.RegisterComboKey(VK_SPACE, 1, 0, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();if (SetWindowVisibility(nowH, 0)) {if (nowH == myWindow) {isMyWinVisible = false;} else {hiddenWindow.push_back(nowH);}}}}, 1);}int main() {// 设置控制台编码为UTF-8system("chcp 65001");// 设置标题system("title 窗口透明器");// 设置长宽 70 列,18 行,最好别改system("mode con cols=70 lines=18");system("cls");// 尝试获取本程序的窗口句柄try {myWindow = GetConsoleWindow();if (myWindow == NULL) {// 无法获取,抛异常throw runtime_error("无法获取窗口句柄");}} catch (const runtime_error& e) {// 报错,退出程序SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);cerr << "ERROR:";SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);cerr << e.what() << endl;system("pause");exit(0);} catch (...) {system("cls");SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);cerr << "UNKNOWN ERROR";system("pause");exit(0);}hiddenWindow.clear();// 隐藏光标SetCursorVisibility(0);system("cls");// IDE 内编译警告:SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTRED, COLOR_BLACK);cout << "编译完成后,请勿通过 IDE 直接运行!\n" << endl;SetColorAndBackground(COLOR_LIGHTYELLOW, COLOR_BLACK);cout << "建议不要开启快速编辑模式!" << endl;cout << "否则像下面的按钮可能会无法点击!" << endl;Button knowWarning(0, 5, ">我明白了", 9);while (1) {if (knowWarning.isClicked()) {while (knowWarning.isClicked()) {// TODO}break;}}// 主页面system("cls");// 启动监听addListener();try {// 失败:if (!listener.Start()) {throw runtime_error("无法监听按键");} else {isListen = 1;}} catch (const runtime_error& e) {// system("cls");// SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);cerr << endl;cerr << "ERROR:";SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);cerr << e.what() << endl;system("pause");exit(0);} catch (...) {// system("cls");// SetCursorPosition(0, 0);cerr << endl;SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);cerr << "UNKNOWN ERROR" << endl;system("pause");exit(0);}system("cls");SetColorAndBackground(COLOR_LIGHTPURPLE, COLOR_BLACK);cout << "窗口透明 v1.0.1" << endl;SetColorAndBackground(COLOR_LIGHTGREEN, COLOR_BLACK);Button help(0, 3, ">使用指南", 9);SetColorAndBackground(COLOR_LIGHTGREEN2, COLOR_BLACK);Button showList(0, 5, ">隐藏列表", 9);SetColorAndBackground(COLOR_LIGHTGREEN3, COLOR_BLACK);Button getRest(0, 7, ">暂停监听", 9);SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);Button leave(0, 9, ">退出程序", 9);Button goHome(0, 17, ">返回", 5, 0);while (1) {if (help.isClicked()) {system("cls");SetCursorPosition(0, 0);SetColorAndBackground(COLOR_PURPLE, COLOR_BLACK);cout << "欢迎使用本程序!\n" << endl;SetColorAndBackground(COLOR_LIGHTYELLOW, COLOR_BLACK);cout << "透明度 0 表示完全透明,255 表示完全不透明\n" << endl;SetColorAndBackground(COLOR_LIGHTBLUE, COLOR_BLACK);cout << "Ctrl+小键盘的加号 可以让最前方的窗口更不透明!\n";cout << "Ctrl+小键盘的减号 可以让最前方的窗口更透明!\n" << endl;SetColorAndBackground(COLOR_LIGHTGREEN2, COLOR_BLACK);cout << "Ctrl+Alt+空格 可以隐藏或显示本窗口!\n" << endl;SetColorAndBackground(COLOR_LIGHTRED, COLOR_BLACK);cout << "Ctrl+空格 可以隐藏任意窗口!\n";cout << "隐藏的窗口可以在主页的“隐藏列表”中恢复!\n" << endl;SetColorAndBackground(COLOR_LIGHTPURPLE, COLOR_BLACK);cout << "点击主页“暂停/恢复监听”可以开启或暂停功能!\n" << endl;SetColorAndBackground(COLOR_WHITE, COLOR_GREEN);cout << "上课摸鱼绝佳助手,快来体验吧!!!\n" << endl;SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);goHome.printText();while (1) {if (goHome.isClicked()) {goto HomeText;}}} else if (showList.isClicked()) {hiddenWindow.erase(remove_if(hiddenWindow.begin(), hiddenWindow.end(), [](const HWND & nowH) {return !isHandleValid(nowH);}), hiddenWindow.end());while (showList.isClicked()) {//TODO}int Start = 0;vector<Button> Items;Button Front(0, 16, ">上一页", 7, 0);Button Next(60, 16, ">下一页", 7, 0);Button Renew(62, 17, ">刷新", 5, 0);while (1) {hiddenWindow.erase(remove_if(hiddenWindow.begin(), hiddenWindow.end(), [](const HWND & nowH) {return !isHandleValid(nowH) || !isWindowHidden(nowH);9 行未改动system("cls");SetCursorPosition(0, 0);SetColorAndBackground(COLOR_YELLOW, COLOR_BLACK);cout << "隐藏的窗口如下,点击显示:" << endl;SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);Items.clear();for (int i = 0; i < min(15, (int)hiddenWindow.size() - Start); i++) {string n = GetWindowTitle(hiddenWindow.at(Start + i));if (n == "") {n = "[无名窗口]";}Button tp(0, i + 1, n, min((int)n.size(), 70), 1);Items.push_back(tp);}SetColorAndBackground(COLOR_LIGHTBLUE, COLOR_BLACK);27 行未改动SetWindowVisibility(tp, 1);}hiddenWindow.erase(remove(hiddenWindow.begin(), hiddenWindow.end(), tp), hiddenWindow.end());while (Items[i].isClicked()) {// TODO}goto ListInner;}}}}ListInner:;}//ListOuter:// ;} else if (leave.isClicked()) {listener.Stop();exit(0);} else if (goHome.isClicked()) {while (goHome.isClicked()) {//TODO}HomeText:;system("cls");SetColorAndBackground(COLOR_LIGHTPURPLE, COLOR_BLACK);cout << "窗口透明 v1.0.1" << endl;SetColorAndBackground(COLOR_LIGHTGREEN, COLOR_BLACK);help.printText();SetColorAndBackground(COLOR_LIGHTGREEN2, COLOR_BLACK);showList.printText();6 行未改动//TODO}if (isListen) {listener.Stop();getRest.name = ">恢复监听";isListen = 0;} else {if (listener.Start()) {addListener();getRest.name = ">暂停监听";isListen = 1;}}goto HomeText;}Sleep(2);}return 0;}```21 行未改动作者鼓励并倡导将此程序用于正当的学习用途。如果因使用者使用不当,由此造成的一切后果作者概不负责。作者承诺在发布代码前已经尽可能地进行了检查,但本程序仍然不能排除有存在错误与漏洞的可能。如果您发现了错误与漏洞,请尽快与作者私信反馈。如果本程序的错误与漏洞对您的电脑造成了损害,作者不承担任何责任,但会积极与您配合减小损害。未经作者亲自许可,不得随意修改本程序的任何部分。本程序有关按键监听的部分代码由 DeepSeek 编写。## Updateupd on 2026.1.2 添加暂停监听的功能;修复了“隐藏列表”会显示程序自身的问题;修复了通过本程序隐藏的窗口后来通过其他方式显示,会在列表中残留选项的问题。1234567891011121314101 行未改动全部展开116117118119120121122123124315 行未改动全部展开440441442443444445446447448376 行未改动全部展开82582682782882983083183283383483583683783883984084184284384484584623 行未改动87087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495539 行未改动99599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104112 行未改动10541055105610571058105910601061106210633 行未改动10671068106910701071107210731074107510767 行未改动10841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212739 行未改动1283128412851286128712881289129012911292129312941295129612971298129913001301130227 行未改动133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613676 行未改动13741375137613771378137913801381138213831384138513861387138813891390139113921393139421 行未改动141614171418141914201421142214231424142514261427142814291430# 窗口透明器退役 Oier,并非专业干工程的,做得不够优秀的地方请多指教。由 C++ 编写,用于 Windows。随便写的小玩具,也懒得大费周章上传 Github 什么的了。公布源代码,需要在自己电脑上编译一下。编译须知见后文,使用说明程序里有。发现 BUG 可找作者私信反馈,最多大概两天会看到。:::info[源代码]```cpp line-numbers// 禁用Windows宏冲突#ifdef _WIN32#ifndef NOMINMAX#define NOMINMAX101 行未改动全部展开if (GetKeyNameText(lParam, keyName, sizeof(keyName))) {result += keyName;} else {char buffer[32];snprintf(buffer, sizeof(buffer), "0x%02X", mainKey);result += buffer;}}return result;315 行未改动全部展开return string(mbBuffer);}// 返回虚拟键码char buffer[32];snprintf(buffer, sizeof(buffer), "Key 0x%02X", vkCode);return string(buffer);}}}376 行未改动全部展开const int COLOR_LIGHTPURPLE = 13;const int COLOR_LIGHTYELLOW = 14;const int COLOR_LIGHTWHITE = 15;// 宽字符输出函数封装void WriteConStr(const wstring& str) {HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);DWORD charsWritten;WriteConsoleW(hConsole, str.c_str(), (DWORD)str.length(), &charsWritten, NULL);}void WriteConStr(const wchar_t* str) {HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);DWORD charsWritten;WriteConsoleW(hConsole, str, (DWORD)wcslen(str), &charsWritten, NULL);}//更改颜色 文字+背景void SetColorAndBackground(int ForgC, int BackC) {WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);23 行未改动CONSOLE_CURSOR_INFO cursor_info = {1, x}; // 第二个值为 0 表示隐藏光标SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);}//按钮类(使用宽字符)class Button {public:int x, y;wstring name; // 改为宽字符串int len;// 构造函数Button(int _x, int _y, const wstring& _name, int _len, bool isPrint = true): x(_x), y(_y), name(_name), len(_len) {if (isPrint) {SetCursorPosition(x, y);WriteConStr(name);}}// 输出内容void printText() {SetCursorPosition(x, y);WriteConStr(name);}// 点击监听bool isClicked() {if (!isMyWinVisible || GetForegroundWindow() != myWindow) {return 0;}POINT pt;GetCursorPosition(pt);if (KEY_DOWN(MOUSE_MOVED)) {if (pt.y == y && (pt.x >= x && pt.x <= x + len)) {return 1;}}return 0;}};// 将UTF-8字符串转换为宽字符串wstring UTF8ToWString(const string& utf8) {if (utf8.empty()) return wstring();int size_needed = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), (int)utf8.size(), NULL, 0);wstring wstr(size_needed, 0);MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), (int)utf8.size(), &wstr[0], size_needed);return wstr;}// 将宽字符串转换为UTF-8字符串string WStringToUTF8(const wstring& wstr) {if (wstr.empty()) return string();int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);string strTo(size_needed, 0);WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);return strTo;}// 将系统本地编码(GBK)字符串转换为宽字符串wstring LocalToWString(const string& local) {if (local.empty()) return wstring();int size_needed = MultiByteToWideChar(CP_ACP, 0, local.c_str(), (int)local.size(), NULL, 0);wstring wstr(size_needed, 0);MultiByteToWideChar(CP_ACP, 0, local.c_str(), (int)local.size(), &wstr[0], size_needed);return wstr;}// 将宽字符串转换为系统本地编码(GBK)字符串string WStringToLocal(const wstring& wstr) {if (wstr.empty()) return string();int size_needed = WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);string strTo(size_needed, 0);WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);return strTo;}// IsWindow 检查窗口句柄是否存在bool isHandleValid(HWND hwnd) {return ::IsWindow(hwnd);}39 行未改动// 设置透明度return SetLayeredWindowAttributes(hwnd, 0, (BYTE)alpha, LWA_ALPHA);}// 获取窗口标题(返回宽字符串)wstring GetWindowTitleW(HWND hwnd) {wchar_t windowTitle[1024];GetWindowTextW(hwnd, windowTitle, 1024);wstring res = windowTitle;if ((int)res.size() > 33) {res = res.substr(0, 33);res += L"...";}return res;}// 获取窗口标题(兼容旧代码,返回UTF-8字符串)string GetWindowTitle(HWND hwnd) {wstring wtitle = GetWindowTitleW(hwnd);return WStringToUTF8(wtitle);}//查询指定窗口是否隐藏bool isWindowHidden(HWND hwnd) {if (hwnd == NULL) {return 0;}LONG style = GetWindowLong(hwnd, GWL_STYLE);return (style & WS_VISIBLE) == 0;}//查询指定窗口是否置顶bool IsWindowTopmost(HWND hwnd) {LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);return (exStyle & WS_EX_TOPMOST) != 0;}//设置指定窗口是否置顶void SetWindowTopmost(HWND hwnd, bool topmost) {HWND insertAfter = topmost ? HWND_TOPMOST : HWND_NOTOPMOST;SetWindowPos(hwnd, insertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);}int deltaAlpha = 20;vector<HWND> hiddenWindow;12 行未改动}}}, 1);// Alt+VK_RIGHT 不透明listener.RegisterComboKey(VK_RIGHT, 0, 1, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();int nowA = GetWindowTransparency(nowH);if (nowA > 255 - deltaAlpha) {3 行未改动}}}, 1);// Alt+VK_LEFT 透明listener.RegisterComboKey(VK_LEFT, 0, 1, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();int nowA = GetWindowTransparency(nowH);if (nowA < 2 * deltaAlpha) {7 行未改动// Ctrl+Space 隐藏listener.RegisterComboKey(VK_SPACE, 1, 0, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();if (!isWindowHidden(nowH) && SetWindowVisibility(nowH, 0)) {if (nowH == myWindow) {isMyWinVisible = false;} else {hiddenWindow.push_back(nowH);}}}}, 1);// Alt+VK_UP 置顶listener.RegisterComboKey(VK_UP, 0, 1, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();SetWindowTopmost(nowH, 1);}}, 1);// Alt+VK_DOWN 置顶listener.RegisterComboKey(VK_DOWN, 0, 1, 0, 0, [](const KeyInfo & info) {if (info.eventType == KeyEventType::KEY_UP) {HWND nowH = GetForegroundWindow();SetWindowTopmost(nowH, 0);}}, 1);}int main() {// 设置控制台输出编码为UTF-8(尽管我们使用WriteConsoleW,但系统命令可能需要)// system("chcp 65001 > nul");// 设置控制台标题为宽字符SetConsoleTitleW(L"窗口透明器");// 设置长宽 70 列,18 行,最好别改system("mode con cols=70 lines=18");system("cls");// 尝试获取本程序的窗口句柄try {myWindow = GetConsoleWindow();if (myWindow == NULL) {// 无法获取,抛异常throw runtime_error("无法获取窗口句柄");}} catch (const runtime_error& e) {// 报错,退出程序SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);WriteConStr(L"ERROR:");SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);// 转换错误信息为宽字符wstring errorMsg = LocalToWString(e.what());WriteConStr(errorMsg + L"\n");system("pause");exit(0);} catch (...) {system("cls");SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);WriteConStr(L"UNKNOWN ERROR");system("pause");exit(0);}hiddenWindow.clear();// 隐藏光标SetCursorVisibility(0);system("cls");// IDE 内编译警告:SetCursorPosition(0, 0);SetColorAndBackground(COLOR_LIGHTRED, COLOR_BLACK);WriteConStr(L"编译完成后,请勿通过 IDE 直接运行!\n\n");WriteConStr(L"请通过文件夹内双击程序运行!\n\n");WriteConStr(L"如果对任务管理器等窗口不生效,请尝试用管理员身份运行!\n\n");SetColorAndBackground(COLOR_LIGHTYELLOW, COLOR_BLACK);WriteConStr(L"建议不要开启快速编辑模式!\n");WriteConStr(L"否则像下面的按钮可能会无法点击!\n");Button knowWarning(0, 9, L">我明白了", 9);while (1) {if (knowWarning.isClicked()) {while (knowWarning.isClicked()) {// TODO}break;}Sleep(3);}// 主页面system("cls");// 启动监听addListener();try {// 失败:if (!listener.Start()) {throw runtime_error("无法监听按键");} else {isListen = 1;}} catch (const runtime_error& e) {SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);WriteConStr(L"\nERROR:");SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);wstring errorMsg = LocalToWString(e.what());WriteConStr(errorMsg + L"\n");system("pause");exit(0);} catch (...) {WriteConStr(L"\n");SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_RED);WriteConStr(L"UNKNOWN ERROR\n");system("pause");exit(0);}system("cls");SetColorAndBackground(COLOR_LIGHTPURPLE, COLOR_BLACK);WriteConStr(L"窗口透明 v1.2.0\n");SetColorAndBackground(COLOR_LIGHTGREEN, COLOR_BLACK);Button help(0, 3, L">程序使用指南", 13);SetColorAndBackground(COLOR_LIGHTGREEN2, COLOR_BLACK);Button showList(0, 5, L">隐藏窗口列表", 13);SetColorAndBackground(COLOR_LIGHTGREEN3, COLOR_BLACK);Button getRest(0, 7, L">暂停软件功能", 13);SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);Button leave(0, 9, L">退出程序并显示所有隐藏的窗口", 29);Button goHome(0, 17, L">返回", 5, 0);while (1) {if (help.isClicked()) {system("cls");SetCursorPosition(0, 0);SetColorAndBackground(COLOR_PURPLE, COLOR_BLACK);WriteConStr(L"欢迎使用本程序!\n\n");SetColorAndBackground(COLOR_LIGHTBLUE, COLOR_BLACK);WriteConStr(L"Alt+方向键右 可以让最前方的窗口更不透明!\n");WriteConStr(L"Alt+方向键左 可以让最前方的窗口更透明!\n\n");SetColorAndBackground(COLOR_LIGHTGREEN2, COLOR_BLACK);WriteConStr(L"Ctrl+Alt+空格 可以隐藏或显示本窗口!\n\n");SetColorAndBackground(COLOR_LIGHTRED, COLOR_BLACK);WriteConStr(L"Ctrl+空格 可以隐藏任意窗口!\n");WriteConStr(L"隐藏的窗口可以在主页的\"隐藏窗口列表\"中恢复!\n\n");SetColorAndBackground(COLOR_LIGHTWHITE, COLOR_BLACK);WriteConStr(L"Alt+方向键上 可以置顶任意窗口!\n");WriteConStr(L"Alt+方向键下 可以取消置顶任意窗口!\n\n");SetColorAndBackground(COLOR_LIGHTPURPLE, COLOR_BLACK);WriteConStr(L"点击主页\"暂停/恢复软件功能\"可以开启或暂停功能!\n\n");SetColorAndBackground(COLOR_WHITE, COLOR_GREEN);WriteConStr(L"适当的摸鱼是为了提高效率 ^_^\n");SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);goHome.printText();while (1) {if (goHome.isClicked()) {goto HomeText;}Sleep(5);}} else if (showList.isClicked()) {while (showList.isClicked()) {//TODO}int Start = 0;vector<Button> Items;Button Front(0, 16, L">上一页", 7, 0);Button Next(60, 16, L">下一页", 7, 0);Button Renew(62, 17, L">刷新", 5, 0);while (1) {hiddenWindow.erase(remove_if(hiddenWindow.begin(), hiddenWindow.end(), [](const HWND & nowH) {return !isHandleValid(nowH) || !isWindowHidden(nowH);9 行未改动system("cls");SetCursorPosition(0, 0);SetColorAndBackground(COLOR_YELLOW, COLOR_BLACK);WriteConStr(L"隐藏的窗口如下,点击显示:\n");SetColorAndBackground(COLOR_WHITE, COLOR_BLACK);Items.clear();for (int i = 0; i < min(15, (int)hiddenWindow.size() - Start); i++) {wstring n = GetWindowTitleW(hiddenWindow.at(Start + i));if (n == L"") {n = L"[无名窗口]";}// 确保显示宽度不超过70个字符// 注意:中文和英文字符宽度不同,这里简化为字符数Button tp(0, i + 1, n, 70, 1);Items.push_back(tp);}SetColorAndBackground(COLOR_LIGHTBLUE, COLOR_BLACK);27 行未改动SetWindowVisibility(tp, 1);}hiddenWindow.erase(remove(hiddenWindow.begin(), hiddenWindow.end(), tp), hiddenWindow.end());while (Items[i].isClicked()) {// TODO}goto ListInner;}}}Sleep(3);}ListInner:;}} else if (leave.isClicked()) {listener.Stop();hiddenWindow.erase(remove_if(hiddenWindow.begin(), hiddenWindow.end(), [](const HWND & nowH) {return !isHandleValid(nowH);}), hiddenWindow.end());for (auto i : hiddenWindow) {SetWindowVisibility(i, 1);Sleep(2);}exit(0);} else if (goHome.isClicked()) {while (goHome.isClicked()) {//TODO}HomeText:;system("cls");SetColorAndBackground(COLOR_LIGHTPURPLE, COLOR_BLACK);WriteConStr(L"窗口透明 v1.2.0\n");SetColorAndBackground(COLOR_LIGHTGREEN, COLOR_BLACK);help.printText();SetColorAndBackground(COLOR_LIGHTGREEN2, COLOR_BLACK);showList.printText();6 行未改动//TODO}if (isListen) {listener.Stop();getRest.name = L">恢复软件功能";isListen = 0;} else {if (listener.Start()) {addListener();getRest.name = L">暂停软件功能";isListen = 1;}}getRest.printText(); // 更新按钮显示goto HomeText;}Sleep(5);}return 0;}```21 行未改动作者鼓励并倡导将此程序用于正当的学习用途。如果因使用者使用不当,由此造成的一切后果作者概不负责。作者承诺在发布代码前已经尽可能地进行了检查,但本程序仍然不能排除有存在错误与漏洞的可能。如果您发现了错误与漏洞,请尽快与作者私信反馈。如果本程序的错误与漏洞对您的电脑造成了损害,作者不承担任何责任,但会积极与您配合减小损害。未经作者亲自许可,不得随意修改本程序的任何部分。如果未经允许随意修改本程序,由此造成的一切后果作者概不负责。本程序有关按键监听的部分代码由 DeepSeek 编写。## Update- upd on 2026.1.2 上午:添加暂停监听的功能;修复了“隐藏列表”会显示程序自身的问题;修复了通过本程序隐藏的窗口后来通过其他方式显示,会在列表中残留选项的问题。- upd on 2026.1.2 下午:修复名称过长的窗口在隐藏列表中的显示问题;修复重复按 Ctrl+Space 会重复向隐藏列表中添加同一窗口的问题。- upd on 2026.1.2 晚上:添加置顶窗口的功能;添加按钮检测的等待时间,减少 CPU 开销;添加“管理员身份”的启动提示;修复即使程序窗口不在最上层按钮也可被点击的问题;更改了调整透明度的快捷键。- upd on 2026.1.10 晚上:使用 `snprintf` 代替 `sprintf_s`,增强兼容性;更改首页按钮文案;退出按钮添加使所有隐藏的窗口显形的功能,防止关闭程序后窗口再也无法显形的情况。- upd on 2026.1.17 下午:全面使用宽字符,尽可能修复了乱码问题。