Last active
August 13, 2023 04:58
-
-
Save Aetopia/aaefa706d7eb552a2cb5db4ccfa130c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _WIN32_WINNT 0x0602 | |
#include <windows.h> | |
#include <dwmapi.h> | |
#define printf __builtin_printf | |
HWND windowHandle = NULL; | |
BOOL windowCloak = FALSE; | |
LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
{ | |
static UINT shellHookMessage = 0; | |
if (uMsg == WM_CREATE) | |
{ | |
shellHookMessage = RegisterWindowMessageW(L"SHELLHOOK"); | |
RegisterShellHookWindow(hWnd); | |
SendNotifyMessageW(hWnd, shellHookMessage, GetShellWindow() ? 0x35 : 0x36, 0); | |
ShowWindow(hWnd, SW_SHOW); | |
} | |
else if (uMsg == WM_NCACTIVATE) | |
{ | |
wParam = hWnd == GetForegroundWindow(); | |
if (GetShellWindow()) | |
DwmSetWindowAttribute(hWnd, DWMWA_CLOAK, &((BOOL){!wParam}), sizeof(BOOL)); | |
else | |
SetLayeredWindowAttributes(hWnd, 0, wParam ? 255 : 0, LWA_ALPHA); | |
} | |
else if (uMsg == WM_STYLECHANGING && wParam == GWL_EXSTYLE) | |
((LPSTYLESTRUCT)lParam)->styleNew = GetShellWindow() ? 0 : WS_EX_LAYERED; | |
else if (uMsg == shellHookMessage && (wParam == 0x35 || wParam == 0x36)) | |
{ | |
HWND shellWindowHandle = GetShellWindow(); | |
BOOL isForegroundWindow = hWnd == GetForegroundWindow(); | |
SetWindowLongPtrW(hWnd, GWL_EXSTYLE, 0); | |
DwmSetWindowAttribute(hWnd, DWMWA_CLOAK, &((BOOL){shellWindowHandle ? !isForegroundWindow : FALSE}), sizeof(BOOL)); | |
SetLayeredWindowAttributes(hWnd, 0, shellWindowHandle ? 255 : (isForegroundWindow ? 255 : 0), LWA_ALPHA); | |
} | |
return DefWindowProcW(hWnd, uMsg, wParam, lParam); | |
} | |
INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd) | |
{ | |
MSG msg = {}; | |
if (!RegisterClassW(&((WNDCLASSW){.lpszClassName = L" ", .lpfnWndProc = WndProc, .hbrBackground = GetStockObject(BLACK_BRUSH)})) || | |
!CreateWindowExW(WS_EX_LAYERED, L" ", NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL)) | |
return EXIT_FAILURE; | |
while (GetMessageW(&msg, NULL, 0, 0)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessageW(&msg); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment