Author Topic: Get the active windows X\Y position?  (Read 3557 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Get the active windows X\Y position?
« 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?
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Get the active windows X\Y position?
« Reply #1 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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Get the active windows X\Y position?
« Reply #2 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.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Get the active windows X\Y position?
« Reply #3 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Get the active windows X\Y position?
« Reply #4 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.
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Get the active windows X\Y position?
« Reply #5 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.
« Last Edit: January 06, 2019, 01:15:51 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Get the active windows X\Y position?
« Reply #6 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.
Granted after becoming radioactive I only have a half-life!