QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Cobalt on January 06, 2019, 12:31:23 pm

Title: Get the active windows X\Y position?
Post by: Cobalt on January 06, 2019, 12:31:23 pm
Is it possible to get the currently active program's window X and Y positions?, I know we can get its handle, but can we return its position on the desktop?
Title: Re: Get the active windows X\Y position?
Post by: SMcNeill on January 06, 2019, 12:34:28 pm
Is it possible to get the currently active program's window X and Y positions?, I know we can get its handle, but can we return its position on the desktop?

http://qb64.org/wiki/SCREENX
http://qb64.org/wiki/SCREENY
Title: Re: Get the active windows X\Y position?
Post by: RhoSigma on January 06, 2019, 12:44:51 pm
It should be noted, that both functions return -32000, if the window is currently minimized. Also be aware of negative positions, if the window is dragged partly off the desktop with its top/left border.
Title: Re: Get the active windows X\Y position?
Post by: Pete on January 06, 2019, 12:47:24 pm
I use negative positioning when I want to copy the desktop but get rid of the title bar. Very useful.

Pete
Title: Re: Get the active windows X\Y position?
Post by: Cobalt on January 06, 2019, 12:54:21 pm
Is it possible to get the currently active program's window X and Y positions?, I know we can get its handle, but can we return its position on the desktop?

http://qb64.org/wiki/SCREENX
http://qb64.org/wiki/SCREENY

when I tried that it gave me MY programs X\Y pos not the currently active Windows X\Y. which I thought was odd cause I used _SCREENHIDE on my program at the time. unless I used it wrong.
Title: Re: Get the active windows X\Y position?
Post by: SMcNeill on January 06, 2019, 01:10:33 pm
You’ll want a declare library routine to get another window’s X/Y position.

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowinfo — this one, maybe.
Title: Re: Get the active windows X\Y position?
Post by: Cobalt on January 06, 2019, 02:00:05 pm
i think what I might need is this,
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
but I'm not knowledgeable enough to know quite how to set that up. I have only dabbled in this a little with even littler success.

I think I start with
Code: QB64: [Select]
  1. DECLARE LIBRARY 'function is already used by QB64 so "User32" is not required
  2. FUNCTION GetWindowRect (BYVAL HWnd as HWND, BYVAL W_INFO)
  3.  
  4. Type WinINFO
  5.   W_left as LONG
  6.   W_top as LONG
  7.   W_right as LONG
  8.   W_bottom as long
  9.  
  10. DIM W_INFO as WinINFO
  11.  

but like I said I'm NOT knowledgeable enough to know just how to setup the Declare Library part. I could certainly use some help on that part.