透明
al.cpp
#include<windows.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
using namespace std;
struct windowdata{
string name;
HWND hwnd;
windowdata(string n,HWND h):name(n),hwnd(h){};
};
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam){
vector<windowdata>* data=reinterpret_cast<vector<windowdata>*>(lParam);
const int length=256;
static char windowText[length];
if(GetWindowText(hwnd, windowText,length)){
data->push_back({windowText,hwnd});
}
return TRUE;
}
void SetWindowTransparency(HWND hwnd,int alpha){
SetWindowLongPtr(hwnd,GWL_EXSTYLE,GetWindowLongPtr(hwnd,GWL_EXSTYLE)|WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd,RGB(0,0,0),alpha,LWA_ALPHA);
}
int main(){
vector<windowdata> wins;
EnumWindows(EnumWindowsProc,reinterpret_cast<LPARAM>(&wins));
for(int i=0;i<wins.size();i++)
cout<<right<<setw(4)<<i<<": "<<"Handle: "<<left<<setw(10)<<wins[i].hwnd<<"- "<<wins[i].name<<'\n';
cout<<"输入窗口编号和透明度(0-255):";
int n,a;cin>>n>>a;
SetWindowTransparency(wins[n].hwnd,a);
return 0;
}
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define Downbd(vk) (bool(GetAsyncKeyState(vk)&0x8000))
void SetWindowTransparency(HWND hwnd,int alpha){
SetWindowLongPtr(hwnd,GWL_EXSTYLE,GetWindowLongPtr(hwnd,GWL_EXSTYLE)|WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd,RGB(0,0,0),alpha,LWA_ALPHA);
}
BYTE GetWindowAlpha(HWND h){
BYTE res=255;
GetLayeredWindowAttributes(h,nullptr,&res,0);
return res;
}
int main(){
while(true){
if(Downbd(VK_MENU)){
HWND h=GetForegroundWindow();
int val=(Downbd(VK_UP)-Downbd(VK_DOWN))*4;
SetWindowTransparency(h,(BYTE)clamp(GetWindowAlpha(h)+val,0,255));
}
Sleep(32);
}
return 0;
}