Sign in to follow this  
Followers 0
Angel

Changing the GUI size

2 posts in this topic

Hi,

I have made my first AutoIt3 GUI. What I have discovered is that it is a bit tricky to control the layout of the different GUI items unless you know the sizes of those items beforehand.

The current MsgBox does not allow me to set the text of the buttons, so I want to make a customize MsgBox function.

So I am trying to create a generic "msgbox" like window that will show a text message (which could have several lines and be quite long) and then show up to 3 buttons (but it could also show only 1 or only 2), each with a different text. Each time I will call this program the text in the buttons might change, so I need to adapt my code so that the buttons always have the right size. When the user clicks a button the program exits with a different code (1 for button 1, 2 for button 2, etc).

My problem is that until I have created all the elements in the GUI I do not know the size of the whole thing. So I need to be able to change the size of my GUI _after_ having created the controls, as I can't easilly set the right size when calling GuiCreate.

So my question is how to change the size of the GUI after the fact. I could use WinMove, but I don't seem to be able to make it work.

Or perhaps is there some other way to do all this?

Here I put the code of my program:

Opt("GuiNotifyMode",1) ; make all controls notify to avoid

#include "math.au3"

If $CmdLine[0] == 0 Then

;Exit -1

;$arg_filename = "none"

$arg_filename = "C:\mcc_out_14\tools\autoit\nirvana_msg_args.txt"

Else

$arg_filename = $CmdLine[1]

EndIf

$s_btn_1 = "Button 1"

$s_btn_2 = "Button 2"

$s_btn_3 = "Button 3"

$s_btn_default = "Button 2"

$s_title = "This is a Message"

$s_msg = "A little test" & @CR & "of this generic MsgBox"

$n_lines = 1

; GuiSetControlNotify() on each control

GuiCreate ($s_title)

; start the control definitions

$y_pos = $n_lines * 30 + 10

$x_pos = 20

$x_width = _MIN(15 * $max_line_length,10000)

$y_width = $n_lines * 30

$y_width = _MAX($y_width, 30 * (Round($total_length / $x_width) + 1))

$txt_msg=GuiSetControl ("label", $s_msg, 10,10, $x_width, $y_width, 0x2000) ; The text of the message

$x_width = 15 * StringLen($s_btn_1)

$btn_1=GuiSetControl ("button", $s_btn_1, $x_pos,$y_pos, $x_width, 30, 0x2000)

If $s_btn_2 <> "" Then

$x_pos = $x_pos + 10 + $x_width

$x_width = 15 * StringLen($s_btn_2)

$btn_2=GuiSetControl ("button", $s_btn_2, $x_pos,$y_pos, $x_width, 30, 0x2000) ; The text of the message

ElseIf $s_btn_3 <> "" Then

$x_pos = $x_pos + 10 + $x_width

$x_width = 15 * StringLen($s_btn_3)

$btn_3=GuiSetControl ("button", $s_btn_3, $x_pos, $y_pos, $x_width, 30, 0x2000) ; The text of the message

EndIf

GuiShow() ; to display the dialog box

WinMove ( $s_title, $s_msg, 10, 10 , $x_pos + 50, $y_pos + 10)

ControlFocus($s_title, "", $s_btn_default)

$n=0

While GuiMsg () > 0 ; to wait a click

If GuiRead() == $btn_1 Then MsgBox(0,"Debug",1) ;Exit 1

If $s_btn_2 <> "" Then

If GuiRead() == $btn_2 Then MsgBox(0,"Debug",2) ;Exit 2

EndIf

If $s_btn_3 <> "" Then

If GuiRead() == $btn_3 Then MsgBox(0,"Debug",3) ;Exit 3

EndIf

$n=$n+1

Wend

Share this post


Link to post
Share on other sites



The winMove should be working fine...

Maybe you need to put a WinWait($S_TITLE, $S_MSG, 1) between the guishow() and WinMove() to ensure the Window exists when the WinMove is done...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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