AutoHotkey Community

It is currently May 26th, 2012, 10:28 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: August 31st, 2009, 3:18 pm 
Offline

Joined: February 7th, 2005, 11:11 am
Posts: 192
Location: Munich, Germany
I found a nasty itch that would be great to heal: The vars A_GuiWidth and A_GuiHeight are only valid within the GuiSize subroutine. Why not always?
To fit a Tab within a GUI afterwards I has to do that following "construct" to outsmart it (working sample):
Code:
gui, add, Tab2, h30,Tab1|Tab2|Tab3
loop, 10
    gui, add, Button,, Button%A_Index%
gui, show
sleep, 500
msgbox, %mHeight% ; This is only for demonstration. Remove the Sleep command and watch the difference.
; The following line works, because due to the time lapse of the MsgBox command the subroutine had have enough time to fetch the height.
GuiControl, Move, SysTabControl321, % "h" mHeight + 25
Return

GuiSize:
mHeight = %A_GuiWidth%
Return

GuiEscape:
ExitApp


Especially the Sleep command is neccessary! W/o it the next command (MsgBox) is executed before the subroutine can fetch the value for the height!

Please make the vars A_GuiWidth and A_GuiHeight permanent. Also a pair for the upper left corner of the GUI would be great (A_GuiX an Y are sorrily preoccupied).

Many thanks in advance!

_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2009, 3:45 pm 
Offline

Joined: March 19th, 2006, 5:52 am
Posts: 419
The problem with doing that is how do you decide what value A_GuiHeight has when you have more than one GUI?

As an alternative, you could use WinGetPos to get the window size. Another option is to plan out the GUI ahead of time and do all the calculation before you call GUI show (and then set the size in the command).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2009, 5:28 pm 
Offline

Joined: February 7th, 2005, 11:11 am
Posts: 192
Location: Munich, Germany
Thanks for your hints, mate!
TheIrishThug wrote:
The problem with doing that is how do you decide what value A_GuiHeight has when you have more than one GUI?
It's value changes with the active GUI. :wink:
TheIrishThug wrote:
As an alternative, you could use WinGetPos to get the window size. Another option is to plan out the GUI ahead of time and do all the calculation before you call GUI show (and then set the size in the command).

That calculation-thing is much too difficult. And what if I wish to change the fontsize etc.? Actually I've 225 automatically generated Buttons spread over four tabs (keywords to index pictures in ThumbsPlus). :shock:

The solution was the WinGetPos command: I tried it before but it gave always the whole screensize back and not the size of my window, so I tried other solutions and found that "non-working" A_GuiHeight".
What I did wrong was, that I thought, that the "Gui, show" followed by a WinGetPos w/o a WinTitle uses the Last Found Window, but it didn't. After I wrote down the window name it works.

Many thanks for that unexpected solution! But nevertheless: a always active A_GuiWidth/Height variable would be great.

_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 7:06 am 
It's a good point. AutoHotkey already has features which use the "default" GUI; GUI subroutines such as GuiSize set it, as does this:
Code:
Gui, 2:Default

A_GuiWidth/Height should just get the size of the default GUI.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 9:11 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
kapege.de wrote:
What I did wrong was, that I thought, that the "Gui, show" followed by a WinGetPos w/o a WinTitle uses the Last Found Window, but it didn't.
Gui Show does not change the Last Found Window; Gui +LastFound does.

Here's an alternative to WinGetPos which should be equivalent to A_GuiWidth/Height:
Code:
Gui, Show, w500 h400 Hide
GetGuiSize(GuiWidth, GuiHeight)
Sleep 500 ; Delay for GuiSize.
MsgBox % "GetGuiSize: " GuiWidth "x" GuiHeight "`nGuiSize: " GuiWidth2 "x" GuiHeight2
ExitApp

GuiSize:
GuiWidth2 := A_GuiWidth
GuiHeight2 := A_GuiHeight
return


GetGuiSize(ByRef w, ByRef h, n="") {
    if n !=
        n = %n%:
    Gui, %n%+LastFoundExist
    ifWinNotExist
        return w := h := ""
    VarSetCapacity(rect, 16)
    DllCall("GetClientRect", "uint", WinExist(), "uint", &rect)
    w := NumGet(rect, 8)
    h := NumGet(rect, 12)
}
You may optionally specify the GUI number as the third parameter. If omitted, the current default GUI is used.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 3:47 pm 
Offline

Joined: February 7th, 2005, 11:11 am
Posts: 192
Location: Munich, Germany
Thank you, master! :wink:
You did it very well. But that amount of code let me yell for a simple solution in the next AHK-version for a plain working A_GuiWidth/Height.

...

Chris, please!

_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group