[SOLVED] WindowFromPoint_() not working?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

[SOLVED] WindowFromPoint_() not working?

Post 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?
Last edited by Danilo on Tue Dec 06, 2011 12:01 pm, edited 1 time in total.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: WindowFromPoint_() not working?

Post by MachineCode »

Got changed a while back. Do it like this instead: hwnd = WindowFromPoint_(PeekQ(@pt))
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
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: WindowFromPoint_() not working?

Post 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? :shock:
Last edited by Danilo on Tue Dec 06, 2011 11:47 am, edited 1 time in total.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: WindowFromPoint_() not working?

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

Re: WindowFromPoint_() not working?

Post 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! :wink: )
Using PeekQ() achieves the same result with a bit less typing. :)
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
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: [SOLVED] WindowFromPoint_() not working?

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: [SOLVED] WindowFromPoint_() not working?

Post 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.
BERESHEIT
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: [SOLVED] WindowFromPoint_() not working?

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: [SOLVED] WindowFromPoint_() not working?

Post 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
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: [SOLVED] WindowFromPoint_() not working?

Post 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 :?
BERESHEIT
Post Reply