getting position of window after auto-positioning

Posted by Zimmy on Fri 24 Apr 2020 05:56 AM — 3 posts, 14,597 views.

#0

win = "plugin_id"
WindowCreate(win, 0, 0, 0, 0, miniwin.pos_center_all, 0, ColourNameToRGB("black")) 
print(WindowInfo(win, 10), WindowInfo(win, 11))


The window is in the middle of the screen but this gives me 0, 0. How I can I find it's actual position?
Australia Forum Administrator #1

According to the documentation for WindowInfo:

InfoType 10 to 13 are where the auto positioning last placed the window (the last time the main screen was refreshed).

Since the auto positioning is calculated each time the screen is redrawn it cannot be known the moment after you do the WindowCreate. The screen will not be redrawn in the middle of running a script (unless you call Repaint). Plus, you haven’t “shown” the window yet with WindowShow, so even if the screen refreshed the position would not be calculated.

For the code to work the way you are trying to use it, you have to both show the window, and also cause it to be displayed, with the Repaint function. So:

WindowShow (win,  true)  -- show it
Repaint ()
print(WindowInfo(win, 10), WindowInfo(win, 11))

That will display the correct coordinates.

Amended on Fri 24 Apr 2020 09:52 AM by Nick Gammon
#2
Thanks, I was getting weirdness with my resize handler if the mini-window had not yet been re-positioned with my drag move handler. Adding this at the beginning of my resize handler did the trick:

local auto_pos = WindowInfo(win, 7)
if auto_pos ~= 0 then 
   Repaint()
   WindowPosition(win, WindowInfo(win, 10), WindowInfo(win, 11), 0, 2)
end