Sign in to follow this  
Followers 0
maikelmeyers

WinGetPos strange behaviour?

8 posts in this topic

Hi,

I try to program a gui for some simple things and I want to save the window size (it is a resizeable gui), when the program is closed. After a restart the gui should have the same size as before closing. The problem is, that WinGetPos and WinGetClientSize give me weird values. Have a look at this example.

CODE
#include <GUIConstants.au3>

#include <WindowsConstants.au3>

$gui = GUICreate ("",500,500,100,100,$WS_MAXIMIZEBOX+$WS_MINIMIZEBOX+$WS_CAPTION+$WS_SIZEBOX)

$size1 = WinGetPos($gui)

$size2= WinGetClientSize($gui)

MsgBox(1,"created a gui with 500x500","Style: $WS_MAXIMIZEBOX+$WS_MINIMIZEBOX+$WS_CAPTION+$WS_SIZEBOX" & @crlf & @crlf & "WinGetPos: " & $size1[2] & " " & $size1[3] & " WinGetClientSize: " & $size2[0] & " " & $size2[1])

$gui = GUICreate ("",500,500,100,100,$WS_SIZEBOX)

$size1 = WinGetPos($gui)

$size2= WinGetClientSize($gui)

MsgBox(1,"created a gui with 500x500","Style: $WS_SIZEBOX" & @crlf & @crlf & "WinGetPos: " & $size1[2] & " " & $size1[3] & " WinGetClientSize: " & $size2[0] & " " & $size2[1])

$gui = GUICreate ("",500,500,100,100,$WS_SYSMENU)

$size1 = WinGetPos($gui)

$size2= WinGetClientSize($gui)

MsgBox(1,"created a gui with 500x500","Style: $WS_SYSMENU" & @crlf & @crlf & "WinGetPos: " & $size1[2] & " " & $size1[3] & " WinGetClientSize: " & $size2[0] & " " & $size2[1])

on my computer the first gui is:

WinGetPos 508 529, WinGetClientSize 500 500

the second gui:

WinGetPos 506 506, WinGetClientSize 498 477

the third gui:

WinGetPos 500 500, WinGetClientSize 494 473

??? This means WinGetPos and WinGetClientSize show different gui sizes than created. How should I handle this?

Share this post


Link to post
Share on other sites



maikelmeyers

Welcome! :P

A window client size contain only a client coordinates exclusive of borders and title. The array returned from function WinGetPos() contains the client coordinates with borders and title. :(

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

maikelmeyers

Welcome! :P

A window client size contain only a client coordinates exclusive of borders and title. The array returned from function WinGetPos() contains the client coordinates with borders and title. :(

...and when you create a window the width and height you specify are used for the client size not the overall window size.

I thought that was correct but I see I am wrong. If you use the default styles then it is correct but otherwise, as maikelmeyers post #1 demonstrates, it is not correct.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

...and when you create a window the width and height you specify are used for the client size not the overall window size.

Yes, that is the point. Look at the example. I created a gui with width 500 and height 500(GuiCreate). You say this is the client size. But directly after creating it I call WinGetClientSize to get the size and it should be 500x500 right? But it is not 500x500 it is 498x477 or 494x473 depending on the window style. And also WinGetPos has different values than 500x500. Why are the sizes of the window and the window client different to the desired size (500x500)? So it is impossible for me to save and restore the actual window size.

Thanks

Share this post


Link to post
Share on other sites

@maikelmeyers

Check _WinAPI_GetSystemMetrics() in the helpfile, with that you can get the size of borders etc and then subtract that from the value you get with WinGetPos() so you can get that 500x500 value you want.

Share this post


Link to post
Share on other sites

that is just what the form designer does, before you add it to your script manually change the height and width of the window to 500 in your code, the form designer just puts it out by a few numbers for some reason, dont know why it does it to me aswell.


Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites

Yes, that is the point. Look at the example. I created a gui with width 500 and height 500(GuiCreate). You say this is the client size. But directly after creating it I call WinGetClientSize to get the size and it should be 500x500 right? But it is not 500x500 it is 498x477 or 494x473 depending on the window style. And also WinGetPos has different values than 500x500. Why are the sizes of the window and the window client different to the desired size (500x500)? So it is impossible for me to save and restore the actual window size.

Thanks

Hmm... good question. I think for retrieving a correct form size you need to calculate size as says AdmiralAlkex and check styles of the form.

GetSystemMetrics

For retrieving styles use a _WinAPI_GetWindowLong() function.

Share this post


Link to post
Share on other sites

OK, thank you all. This is a workaround I can live with. But I think it would be better if the GuiCreate size would always be the window client size in future AutoIt versions, because this is very confusing :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0