Page 1 of 1
[SOLVED] WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 11:32 am
by Danilo
Why does the following code not work?
Code: Select all
EnableExplicit
Define i, pt.Point
Repeat
GetCursorPos_(@pt)
Debug WindowFromPoint_(@pt)
Delay(1000)
i+1
Until i = 10
Yesterday i played with WindowFromPoint_(), ChildWindowFromPoint_(),
ChildWindowFromPointEx_(), RealChildWindowFromPoint_() ... but never get
a hWnd back. Always 0. Nothing works. What is wrong?
Re: WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 11:35 am
by MachineCode
Got changed a while back. Do it like this instead: hwnd = WindowFromPoint_(PeekQ(@pt))
Re: WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 11:44 am
by Danilo
Thank you, MachineCode. This is changed for all POINT structures? Use PeekQ?
Looks very silly. In C you can give a POINT directly for some functions, i remember this.
But using PeekQ now is weird.
Who changed it to use PeekQ? Fred or freak?

Re: WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 11:46 am
by einander
Or try this:
Code: Select all
Macro PosM : MMx|MMy<<32 : EndMacro
ChildWindowFromPoint_(GetParent_(HWnd), MMx|MMy<<32)
ChildWindowFromPoint_(hWnd, PosM)
Macro hWndUnderMous
WindowFromPoint_(PosM)
EndMacro
Cheers!
Re: WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 11:56 am
by MachineCode
@Danilo, from
http://www.purebasic.fr/english/viewtop ... 12&t=33954 :
srod wrote:Careful with WindowFromPoint_() as it's internal prototype has now changed between PB 4.3 beta 2 and beta 3. This means that between PB 4.2 and 4.3 (the latest beta) WindowFromPoint_() has gone from accepting two parameters of type long to one of type quad.
PB 4.3 beta 3 onwards :
Code: Select all
x = DesktopMouseX()
y = DesktopMouseY()
pos.q = y<<32 + x
hWnd = WindowFromPoint_(pos)
(Note there is a bug in PB 4.3 beta 3 x64 which means that this function does not currently work in 64-bit PB!

)
Using PeekQ() achieves the same result with a bit less typing.

Re: [SOLVED] WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 12:03 pm
by Danilo
Thanks again guys!
I am still shocked. Yesterday i tried everything with this functions
and lost 2 or 3 hours of my life because of this.
Re: [SOLVED] WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 2:16 pm
by netmaestro
MS Platform SDK wrote:Syntax
HWND WindowFromPoint( POINT Point
);
Parameters
Point
[in] Specifies a POINT structure that defines the point to be checked.
This was changed some time back to conform with Microsoft's specification. The API expects the full point structure as input, not a pointer to it and not two parameters x,y. Purebasic in the past had been taking (x,y) for simplicity and converting under the hood but they've stopped doing that now. I say simplicity but in reality it was probably necessity as this API was first imported before Purebasic had native quads. The change has caused some confusion, to be sure, but now that quads are available it was the right thing to do.
Re: [SOLVED] WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 8:08 pm
by Danilo
netmaestro wrote:but now that quads are available it was the right thing to do.
Sure. But then PB should also be able to push structures onto the stack that are quad size (like POINT).
Code: Select all
Define pt.Point
GetCursorPos_(@pt)
hWnd = WindowFromPoint_(pt)
That would make sense, but it does not work in PB like in C and C++ (for what the API documentation is).
Code: Select all
#include <iostream>
#include <Windows.h>
#define Debug(a) std::cout << (a) << std::endl;
int main(int argc, char *argv[]) {
POINT pt; int i=0;
do {
GetCursorPos(&pt);
Debug( WindowFromPoint(pt) );
Sleep(1000);
i++;
} while( i != 10 );
return 0;
}
The QuickHelp in the statusbar shows "WindowFromPoint_(POINT)". PB can not handle this,
so it should show "WindowFromPoint_(point.q)" in my opinion.
Re: [SOLVED] WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 9:01 pm
by RASHAD
Hi Danilo
Usually I keep my tests in a file with comments
And here is my notes
Code: Select all
;**********************************************************************
ChildWindowFromPoint_(Handle of Parent Window,lParam >> 16 << 32 + lParam & $FFFF) = Handle of Child Window
;**********************************************************************
WindowFromPoint_(pt\y << 32 + pt\x)
;**********************************************************************
GetCursorPos_(p.POINT)
GetWindowRect_(Static2,re.RECT)
PtInRect_(re,pt\y << 32 + pt\x)
;PtInRect_(re,PeekQ(@p))
;PtInRect_(re, p\x|(p\y<<32))
;**********************************************************************
GetCursorPos_(@cp.POINT)
MapWindowPoints_(0,hwnd,@cp,1)
;**********************************************************************
and the best after some times is
Y << 32 + x
The others failed me in some cases
Re: [SOLVED] WindowFromPoint_() not working?
Posted: Tue Dec 06, 2011 10:05 pm
by netmaestro
Danilo wrote:The QuickHelp in the statusbar shows "WindowFromPoint_(POINT)". PB can not handle this,
so it should show "WindowFromPoint_(point.q)" in my opinion.
I agree, the doc isn't correct and your suggestion would make it clearer. I can see a reason why the API designers would need a parameter to be passed by reference in a lot of cases but I can't see a reason to force passing by value when a structure is involved, just because its size happens to fit in an intrinsic data type. They could have worked with the pointer just as well for conformity with the vast majority of other API calls which use pointers to structures. I remember the first time I used the AlphaBlend API I tussled with it for over an hour before I realized they wanted the BLENDFUNCTION structure passed by value where I was trying to pass its address. As if we don't have enough headaches trying to get things to work
