Posts: 1,769
Threads: 410
Joined: Feb 2003
02-17-2021, 06:13 PM
(This post was last modified: 02-17-2021, 06:14 PM by ken gray.)
I have a function that will lower (and raise) the transparency when I scroll the mouse wheel when over the window's caption. I'd like for it to work on the non-active window as well.
How can I do this?
Function
Trans_Lower
Trigger
#Dh2 0x1
dll user32 #GetLayeredWindowAttributes hwnd *crKey !*bAlpha *dwFlags
int col flags; byte alpha
int z
GetLayeredWindowAttributes win &col &alpha &flags
z=18
if alpha=0
,alpha=255
else
,alpha-z
;out "alpha %i" alpha
if alpha<18
,bee "C:\downloads\sounds\system\comp3.wav"
,Transparent(win 25)
,3
,end
Transparent(win alpha)
Posts: 1,338
Threads: 61
Joined: Jul 2006
just need to grap the windowhandle from the mouse and change win to hwnd so it will work on inactive window as well
Function
Trans_Lower
Trigger
#Dh2 0x1
int hwnd=win(mouse)
int col flags; byte alpha
int z
GetLayeredWindowAttributes hwnd &col &alpha &flags
z=18
if alpha=0
,alpha=255
else
,alpha-z
;out "alpha %i" alpha
if alpha<18
,bee "C:\downloads\sounds\system\comp3.wav"
,Transparent(hwnd 25)
,3
,end
Transparent(hwnd alpha)
Posts: 1,769
Threads: 410
Joined: Feb 2003
dang! I was just using win(mouse) earlier too!!
thanks.
Posts: 1,769
Threads: 410
Joined: Feb 2003
SHoot....this seems to only work for some windows (most notably QM). anyone have an idea as to why?
Function
Trans_Lower
Trigger
#Dh2 0x1
int hwnd=win(mouse)
int col flags
byte alpha
int z
GetLayeredWindowAttributes hwnd &col &alpha &flags
out "alpha %i" alpha
z=18
if alpha=0
,alpha=255
else
,alpha-z
out "alpha %i %i" alpha hwnd
if alpha<24
,Transparent(hwnd 25)
,3
,end
Transparent(hwnd alpha)
Posts: 1,338
Threads: 61
Joined: Jul 2006
Its because GetLayeredWindowAttributes is for layered windows. On non layered windows the function doesn't work correctly .reports alpha incorrectly.
Posts: 1,338
Threads: 61
Joined: Jul 2006
sorry wasn't at pc when I posted before. This should work as expected.
just need to add a check to see if the window is layered first and if not make it so.
Function
Trans_Lower
Trigger
#Dh2
int hwnd=win(mouse)
int col flags z
byte alpha
int e(GetWindowLong(hwnd GWL_EXSTYLE)) t(e&WS_EX_LAYERED!=0)
if(!t)
,out "not Layered"
,SetWindowLong(hwnd GWL_EXSTYLE e|WS_EX_LAYERED)
,SetLayeredWindowAttributes(hwnd 0 255 2)
GetLayeredWindowAttributes hwnd &col &alpha &flags
out "alpha %i" alpha
z=15
if alpha=0
,alpha=255
else
,alpha-z
out "alpha %i %i" alpha hwnd
if alpha<15
,Transparent(hwnd 15)
,3
,end
Transparent(hwnd alpha)
Posts: 1,338
Threads: 61
Joined: Jul 2006
02-20-2021, 12:46 AM
(This post was last modified: 02-21-2021, 02:22 PM by Kevin.)
I adjusted this version so it will go all the way down and when it gets to 0 will set alpha to 255.
Function
Trans_Lower_Mod1
Trigger
#Dh2
int hwnd=win(mouse)
int col flags
byte alpha
int e(GetWindowLong(hwnd GWL_EXSTYLE)) t(e&WS_EX_LAYERED!=0)
if(!t)
,out "not Layered"
,SetWindowLong(hwnd GWL_EXSTYLE e|WS_EX_LAYERED)
,SetLayeredWindowAttributes(hwnd 0 255 2)
GetLayeredWindowAttributes hwnd &col &alpha &flags
alpha-17
out "alpha %i" alpha
if alpha<17
,alpha=255
,Transparent(hwnd -alpha)
else
,Transparent(hwnd alpha)
Function
Trans_Raise_Mod1
Trigger
#Uh2
int hwnd=win(mouse)
int col flags
byte alpha
int e(GetWindowLong(hwnd GWL_EXSTYLE)) t(e&WS_EX_LAYERED!=0)
if(!t)
,out "not Layered"
,SetWindowLong(hwnd GWL_EXSTYLE e|WS_EX_LAYERED)
,SetLayeredWindowAttributes(hwnd 0 0 2)
GetLayeredWindowAttributes hwnd &col &alpha &flags
alpha+17
if alpha =255
,Transparent(hwnd -alpha)
else
,Transparent(hwnd alpha)
out "alpha %i" alpha
Posts: 1,769
Threads: 410
Joined: Feb 2003
Fantastic!!!1
works great! I never even thought you could change the window to into a layered one.
THANKS!!!