how to Get Current Window?

Everything else that doesn't fall into one of the other PB categories.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

how to Get Current Window?

Post by josku_x »

Hello!

since PB4, you have to place the Window parameter in the WindowID() function. In PB3.94, I was able to determine the current window using WindowID() without parameters.

However, I am making a custom gadget library and I thought it would be "handier" if the user doesn't need to supply the hWnd.

I am using Win32 API calls, like CreateWindowEx_() and so on.
Let's assume this is my current code:

Code: Select all

Procedure MyCustomGadget(Window, x, y, Width, Height)
 CreateCustomGadget(WindowID(Window), x, y, Width, Height)
EndProcedure
It would be better if it would look like this, wouldn't it?

Code: Select all

Procedure MyCustomGadget(x, y, Width, Height)
 Window=GetCurrentWindow()
 CreateCustomGadget(Window, x, y, Width, Height)
EndProcedure
The GetCurrentWindow() function should return the hWnd of the calling window. (For example, window #0 calls MyCustomGadget(), the procedure calls GetCurrentWindow() and the result is equal to WindowID(0))

I am asking how to achieve this, as I am sure there's a workaround, but I did not stumble in it yet.

Thanks! Any help is appreciated!
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: how to Get Current Window?

Post by traumatic »

GetForegroundWindow() ?
Good programmers don't comment their code. It was hard to write, should be hard to read.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

doesn't help much, as the window which calls the procedure can be hidden or not in the foreground.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

As PB is not documented at the moment you can't be sure if this is right,
but it seems to work:

Code: Select all

OpenWindow(0, 0, 0, 200, 200,"")
CreateGadgetList(WindowID(0))
OpenWindow(1, 0, 0, 200, 200,"")
CreateGadgetList(WindowID(1))

a.l
!EXTRN _PB_Gadget_Objects
!MOV Eax, [_PB_Gadget_Objects+16]
!MOV Eax, [Eax]
!MOV [v_a], Eax

Debug a
Debug WindowID(1)
Athlon64 3700+, 1024MB Ram, Radeon X1600
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

I get "Invalid Memory Access" at line 6. Using WinME.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

Right, in Debug mode it works here :?
So you have to wait for an "official" solution, but i think, there wont be
one :roll:
Athlon64 3700+, 1024MB Ram, Radeon X1600
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

well, it's not a problem but I'd like to have the WindowID() function again with the optional parameter
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

josku_x wrote:doesn't help much, as the window which calls the procedure can be hidden or not in the foreground.
Sorry, I should have read your post more carefully.

Just saw "get current window" twice or something,
that's what GetForegroundWindow() does ;)
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply