Page 1 of 1
Get opacity of a window?
Posted: Sat Aug 13, 2011 1:34 am
by MachineCode
I know how to set the opacity of a window, so that it's 50% visible for example, but how can I get that % value from a window that is already opaque that I didn't set? Or, if not as a %, just as whatever opacity value it holds. Thanks.
Re: Get opacity of a window?
Posted: Sat Aug 13, 2011 4:06 am
by netmaestro
Have a look at GetLayeredWindowAttributes_() on msdn. It will give you the needed information.
Re: Get opacity of a window?
Posted: Sat Aug 13, 2011 4:42 am
by MachineCode
Code: Select all
GetLayeredWindowAttributes_() is not a function, array, macro or linked list.
Now you see my problem.

PureBasic supports SetLayerWindowAttributes, but not getting them.
Re: Get opacity of a window?
Posted: Sat Aug 13, 2011 5:29 am
by netmaestro
MachineCode wrote:PureBasic supports SetLayerWindowAttributes, but not getting them.
Code: Select all
GetLayeredWindowAttributes_() is not a function, array, macro or linked list.
Now you see my problem.

PureBasic supports SetLayerWindowAttributes, but not getting them.
Dig, my son, dig! Don't stop until you hit paydirt
Code: Select all
Prototype LayeredWindowAttributes(a,b,c,d)
OpenLibrary(0, "user32.dll")
Global GetLayeredWindowAttributes_.LayeredWindowAttributes = GetFunction(0, "GetLayeredWindowAttributes")
OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0), 0, 128, #LWA_ALPHA)
Define.a alpha
GetLayeredWindowAttributes_(WindowID(0), #Null, @alpha, #Null)
Debug alpha
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
CloseLibrary(0)
Re: Get opacity of a window?
Posted: Sat Aug 13, 2011 5:31 am
by MachineCode
I don't understand what Prototypes are or what they do, but thanks for showing me how to do it (until natively supported).
Re: Get opacity of a window?
Posted: Sat Aug 13, 2011 5:40 am
by netmaestro
Prototypes are easy. All they do is describe the number, order and type of expected parameters. Once you've created a prototype, you can append it to a (usually global) variable as a structured type. After you do that, simply set the variable to the address of the function you want to call and Bob's your uncle. Here I've opened user32.dll, which msdn told me contains GetLayeredWindowAttributes, created the prototype according to msdn's spec, used GetFunction() to give me the address of the exported function in the dll, created a global variable with the structured type (prototype) and set the address to it. The rest is no more difficult than just calling it. It's now "supported". Often you can use Import with the .lib version of the dll, but this one's not in it. You have to go to the dll and get the function there. Try this with some other functions from the windows api, whether they're supported natively or not. You'll eventually find your sea legs and nothing will stop you again.