Jump to content

My auto sizing function


Recommended Posts

:geek: Im trying to make a function that displays a child message box for another GUI but my auto sizing calculations were wrong (The width and height for the window frame, label and the button combination are not pretty like a regular message box).

And also this function has the ability to add an input (More problems).

Well it works but its messed up. :o;)

If you could make it organized and pretty I will be grateful. :sorcerer:

Is it possible to add some thing like that in the autoit beta?

Thanks,

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

  • 1 month later...

:mellow: Im trying to make a function that displays a child message box for another GUI but my auto sizing calculations were wrong (The width and height for the window frame, label and the button combination are not pretty like a regular message box).

And also this function has the ability to add an input (More problems).

Well it works but its messed up. :):)

If you could make it organized and pretty I will be grateful. :o

Is it possible to add some thing like that in the autoit beta?

Thanks,

I should've posted this script in Chat , anyway here is what I've done so far.

Is there any way to swich it to chat.

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

i played with it a little

#include <GuiConstants.au3>
Dim $temp2 = ""
$GUI = GUICreate("Child msgboxes" , 205 , 140)
$OK = GUICtrlCreateButton( "  OK only  " , 3 , 20 , 200)
$yes_no = GUICtrlCreateButton( "   Yes and NO   " , 3 , 60 , 200 )
$OK_Cancel = GUICtrlCreateButton( " Input with OK AND Cancel "  , 3 , 100 , 200 )
GUISetState( @SW_SHOW )
While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then
        If message( "Exiting" , "Are you sure?" , $GUI  , 4) = 6 Then
            Exit
        EndIf
    ElseIf $MSG = $OK Then
        message( "OK only" , "Press OK to continue."&@LF&"Or..... exit from systray" , $GUI )
    ElseIf $MSG = $yes_no Then
        message( "Yes and NO" , "What is you answer usually?" , $GUI , 4 )
    ElseIf $MSG = $OK_Cancel Then
        message( "Input with OK AND Cancel" , "Usually a msgbox holds up every thing"&@LF&"but this doesn't;)"&@LF&"If OK was click the return will be a string (this is a useless line just to put some text for you)" , $GUI , 10 )
        message( "OK only" , $temp2, $GUI )
    EndIf
WEnd




Func message( $title , $text , $parent , $flag = 0 , $disable = 1 , $timeOut = 0)
;##This will create a MSGBOX with or withOut input using GUICREATE with a parent windows
;## flags: 0 for OK button only
;##     4 for Yes and NO will return 7 for NO and 6 for yes
;########  10 for INPUT BOX will return "INPUT" for OK and -1 for Cancel
    GUISetState( @SW_RESTORE , $parent );;restoring the GUI.
    Local Const $char_width = 5 , $button_width = 70 , $button_hight =23  , $char_hight = 15
    Local $get_win_pos , $MSG_BAD = -123 ,$input = -124 ,$temp_read , $input_Width  , $line_count , $TEMP_char_perLine
    Local $lable_width , $lable_hight , $temp , $get_win_pos , $temp_time , $first_button_left , $second_button_left
    $line_count = StringSplit( $text , @LF , 1 )
    Dim $char_perLine[$line_count[0] + 1]
    If $disable = 1 Then
        GUISetState( @SW_DISABLE , $parent)
    ElseIf $disable = 2 Then 
        GUISetState( @SW_DISABLE , $parent)
        GUISetState( @SW_HIDE , $parent)
    EndIf
    
    Select
    Case $line_count[0] > 1
        $char_perLine[0] = $line_count[0]
        For $a = 1 to $line_count[0]
            $TEMP_char_perLine = StringSplit( $line_count[$a] , '' )
            $char_perLine[$a] = $TEMP_char_perLine[0]
        Next
    Case $line_count[0] = 1
        $char_perLine = StringSplit( $text , "")
        $char_perLine[1] = $char_perLine[0]
        $char_perLine[0] = 1
    EndSelect
    
;;Calculating the lable width...and Lable hight..
    Select
    Case $char_perLine[0] = 1
        $lable_hight = $char_hight
        $lable_width = ($char_perLine[1] * $char_width)
    Case $char_perLine[0] > 1
        $temp = $char_perLine[1]
        For $a = 2 to $char_perLine[0]
            If $temp < $char_perLine[$a] Then
                $temp = $char_perLine[$a]
            EndIf
        Next
    ;setting the width
        $lable_width = ($temp * $char_width)
    ;setting the hight
        $lable_hight = ($char_hight * $char_perLine[0])
    EndSelect
;;Calculating the GUI width...
    Select
    Case $flag = 0; The OK button and the LABLE
        $GUI_Width = $lable_width + 30 
        $GUI_hight = $lable_hight + 85
        
    Case $flag = 4 ; TWO BUTTONS and the LABLE
        $GUI_hight = $lable_hight + 85
        $GUI_Width = $lable_width + 30
        
    Case $flag = 10; TWO BUTTONS , INPUT and the LABLE
        $GUI_Width = $lable_width + 30
        $GUI_hight = $lable_hight + 85 + 30
    EndSelect
    
;;Calculating buffer space between yes and no buttons
    $first_button_left = (($GUI_Width/4) - ($button_width/2)) + ($GUI_Width/10)
    If $first_button_left < 5 Then
        $first_button_left = 5
    EndIf
    
    $second_button_left = ((($GUI_Width/4) * 3) -($button_width/2)) - ($GUI_Width/10)
    If ($second_button_left) < ($first_button_left + $button_width + 4) Then
        $second_button_left = ($first_button_left + $button_width + 4)
    EndIf
    
    If ($second_button_left - $first_button_left) > 150 Then
        $buf_adjus = ($second_button_left - $first_button_left) / 4
        $first_button_left = $first_button_left + $buf_adjus
        $second_button_left = $second_button_left - $buf_adjus
    EndIf
    
    If $second_button_left + $button_width + 5 > $GUI_Width Then
        $GUI_Width = $second_button_left + $button_width + 10
    EndIf
    
    $get_win_pos = WinGetPos ( $parent )
    $MSG_GUI = GUICreate( $title , $GUI_Width , $GUI_hight , ($get_win_pos[0] + ($get_win_pos[2]/2))-( $GUI_Width/2), ($get_win_pos[1] + ($get_win_pos[3]/2))-( $GUI_hight/2) , 0x00000001  , -1 , $parent )
    $MSG_lable = GUICtrlCreateLabel( $text , 10 , 10 , $lable_width , $lable_hight )
;GUICtrlSetBkColor( -1 , 0x00ff00 )
    Select
    Case $flag = 0
        $MSG_GOOD = GUICtrlCreateButton( "  OK   " , (($GUI_Width/2))-($button_width / 2 ) , ($GUI_hight - 30 )-($button_hight + 10 ) ,$button_width , $button_hight)
        GUICtrlSetState( -1, $GUI_DEFBUTTON )
    Case $flag = 4
        $MSG_GOOD = GUICtrlCreateButton( "  Yes   " , $first_button_left , ($GUI_hight - 30 )-($button_hight + 10 ) , $button_width , $button_hight)
        GUICtrlSetState( -1, $GUI_DEFBUTTON )
        $MSG_BAD = GUICtrlCreateButton( "  No   " , $second_button_left , ($GUI_hight - 30 )-($button_hight + 10 ) , $button_width , $button_hight)
    Case $flag = 10
        $MSG_GOOD = GUICtrlCreateButton( "  OK   " , $first_button_left, ($GUI_hight - 30 )-($button_hight + 10 ) , $button_width , $button_hight)
        GUICtrlSetState( -1, $GUI_DEFBUTTON )
        $MSG_BAD = GUICtrlCreateButton( "  Cancel   " , $second_button_left , ($GUI_hight - 30 )-($button_hight + 10 ) , $button_width , $button_hight)
    EndSelect
    If $flag = 10 Then
        If $GUI_Width > 400 Then
            $input_Width = 340
        Else
            $input_Width = $GUI_Width - 50
        EndIf
        $input = GUICtrlCreateInput("" , (($GUI_Width /2) - ($input_Width/2)) , ($GUI_hight - ($button_hight + 10 + 60)) , $input_Width , 20 )
        GUICtrlSetState( -1, $GUI_FOCUS )
    EndIf
    
    GUISetState( @SW_SHOW , $MSG_GUI )
    If $timeOut <> 0 Then
        $temp_time = TimerInit()
    EndIf
    While 1
        If $timeOut <> 0 Then
            If (TimerDiff( $temp_time ) = $timeOut) or (TimerDiff( $temp_time ) > $timeOut) Then
                GUIDelete( $MSG_GUI )
                If $disable = 2 Then
                    GUISetState( @SW_SHOW , $parent )
                    GUISetState( @SW_ENABLE , $parent )
                ElseIf $disable = 1 Then
                    GUISetState( @SW_ENABLE , $parent )
                EndIf
                WinActivate( $parent )
                GUISwitch ( $parent )
                Return -1
            EndIf
        EndIf
        
        $MSG_MSG = GUIGetMsg($MSG_GUI)
        Select
        Case ($MSG_MSG = $MSG_GOOD) And ($flag <>10)
            GUIDelete( $MSG_GUI )
            If $disable = 2 Then
                GUISetState( @SW_SHOW , $parent )
                GUISetState( @SW_ENABLE , $parent )
            ElseIf $disable = 1 Then
                GUISetState( @SW_ENABLE , $parent )
            EndIf
            WinActivate( $parent )
            GUISwitch ( $parent )
            If $flag = 0 Then Return 0
            If $flag = 4 Then Return 6
            
        Case ($MSG_MSG = $MSG_BAD) And ($flag <> 0)
            GUIDelete( $MSG_GUI )
            If $disable = 2 Then
                GUISetState( @SW_SHOW , $parent )
                GUISetState( @SW_ENABLE , $parent )
            ElseIf $disable = 1 Then
                GUISetState( @SW_ENABLE , $parent )
            EndIf
            WinActivate( $parent )
            GUISwitch ( $parent )
            SetError( 1 )
            Return 7
            
        Case ($MSG_MSG = $MSG_GOOD) And ($flag = 10)
            $temp2 = guictrlread( $input )
            GUIDelete($MSG_GUI)
            If $disable = 2 Then
                GUISetState( @SW_SHOW , $parent )
                GUISetState( @SW_ENABLE , $parent )
            ElseIf $disable = 1 Then
                GUISetState( @SW_ENABLE , $parent )
            EndIf
            WinActivate( $parent )
            GUISwitch ( $parent )
            Return $temp2
        EndSelect
    WEnd
EndFunc

pretty nice!!

8)

NEWHeader1.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...