Created
July 8, 2022 15:06
-
-
Save Far-Se/b8daaf637f160dfa9f4cb4655292d623 to your computer and use it in GitHub Desktop.
This file contains 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
#include <Windows.h> | |
#include <stdio.h> | |
#include <iostream> | |
void SetTransparent(HWND target_window, bool type) | |
{ | |
DWORD exstyle; | |
typedef BOOL(WINAPI* MySetLayeredWindowAttributesType)(HWND, COLORREF, BYTE, DWORD); | |
static MySetLayeredWindowAttributesType MySetLayeredWindowAttributes = (MySetLayeredWindowAttributesType) | |
GetProcAddress(GetModuleHandle(L"user32"), "SetLayeredWindowAttributes"); | |
exstyle = GetWindowLong(target_window, GWL_EXSTYLE); | |
if (!MySetLayeredWindowAttributes || !exstyle)return; | |
if (!type) SetWindowLong(target_window, GWL_EXSTYLE, exstyle & ~WS_EX_LAYERED); | |
else { | |
SetWindowLong(target_window, GWL_EXSTYLE, exstyle | WS_EX_LAYERED); | |
MySetLayeredWindowAttributes(target_window, 0, 0, LWA_ALPHA); | |
if (!type) | |
{ | |
InvalidateRect(target_window, NULL, TRUE); | |
} | |
} | |
} | |
void ToggleTaskbar(bool visible) | |
{ | |
APPBARDATA abd = { sizeof abd }; | |
abd.lParam = visible ? ABS_ALWAYSONTOP : ABS_AUTOHIDE; | |
SHAppBarMessage(ABM_SETSTATE, &abd); | |
//SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd); | |
HWND mainHwnd = FindWindow(L"Shell_traywnd", L""); | |
SetTransparent(mainHwnd, !visible); | |
//ShowWindow(mainHwnd, visible ? SW_SHOWNA : SW_HIDE); | |
//SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd); | |
HWND hwndNext = nullptr; | |
HWND hwnd = nullptr; | |
do | |
{ | |
hwnd = FindWindowEx(NULL, hwndNext, L"Shell_SecondaryTrayWnd", L""); | |
if (hwnd) | |
{ | |
//ShowWindow(hwnd, visible ? SW_SHOWNA : SW_HIDE); | |
SetTransparent(hwnd, !visible); | |
} | |
hwndNext = hwnd; | |
} while (hwnd != nullptr); | |
SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd); | |
} | |
int main() | |
{ | |
ToggleTaskbar(false); | |
std::cin.get(); | |
ToggleTaskbar(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment