Page 1 of 1

how to Get Current Window?

Posted: Thu May 25, 2006 1:07 pm
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!

Re: how to Get Current Window?

Posted: Thu May 25, 2006 1:42 pm
by traumatic
GetForegroundWindow() ?

Posted: Thu May 25, 2006 1:55 pm
by josku_x
doesn't help much, as the window which calls the procedure can be hidden or not in the foreground.

Posted: Thu May 25, 2006 2:37 pm
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)

Posted: Thu May 25, 2006 3:13 pm
by josku_x
I get "Invalid Memory Access" at line 6. Using WinME.

Posted: Thu May 25, 2006 3:20 pm
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:

Posted: Thu May 25, 2006 3:35 pm
by josku_x
well, it's not a problem but I'd like to have the WindowID() function again with the optional parameter

Posted: Thu May 25, 2006 11:46 pm
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 ;)