It is currently Fri May 24, 2013 8:08 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: [SOLVED] WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 11:32 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
Why does the following code not work?
Code:
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.

Top
 Profile  
 
 Post subject: Re: WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 11:35 am 
Offline
Addict
Addict

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


Top
 Profile  
 
 Post subject: Re: WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 11:44 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
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.

Top
 Profile  
 
 Post subject: Re: WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 11:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jun 26, 2003 2:09 am
Posts: 731
Location: Spain (Galicia)
Or try this:
Code:
 
Macro PosM   : MMx|MMy<<32  : EndMacro

ChildWindowFromPoint_(GetParent_(HWnd),  MMx|MMy<<32)
ChildWindowFromPoint_(hWnd, PosM)

Macro hWndUnderMous
  WindowFromPoint_(PosM)
EndMacro

Cheers!


Top
 Profile  
 
 Post subject: Re: WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 11:56 am 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1459
@Danilo, from viewtopic.php?f=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:
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!


Top
 Profile  
 
 Post subject: Re: [SOLVED] WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 12:03 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
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.


Top
 Profile  
 
 Post subject: Re: [SOLVED] WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 2:16 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
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.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject: Re: [SOLVED] WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 8:08 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
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:
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:
#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.


Top
 Profile  
 
 Post subject: Re: [SOLVED] WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 9:01 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1472
Hi Danilo
Usually I keep my tests in a file with comments
And here is my notes

Code:
;**********************************************************************

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


Top
 Profile  
 
 Post subject: Re: [SOLVED] WindowFromPoint_() not working?
PostPosted: Tue Dec 06, 2011 10:05 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
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 :?

_________________
Veni, vidi, vici.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye