Get opacity of a window?

Just starting out? Need help? Post your questions and find answers here.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Get opacity of a window?

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Get opacity of a window?

Post by netmaestro »

Have a look at GetLayeredWindowAttributes_() on msdn. It will give you the needed information.
BERESHEIT
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Get opacity of a window?

Post by MachineCode »

Code: Select all

GetLayeredWindowAttributes_() is not a function, array, macro or linked list.
Now you see my problem. :P PureBasic supports SetLayerWindowAttributes, but not getting them.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Get opacity of a window?

Post 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. :P PureBasic supports SetLayerWindowAttributes, but not getting them.
Dig, my son, dig! Don't stop until you hit paydirt :evil:

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)
BERESHEIT
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Get opacity of a window?

Post 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).
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Get opacity of a window?

Post 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.
BERESHEIT
Post Reply