Jump to content
Sign in to follow this  
Blue_Drache

GUI MsgBox UDF

Recommended Posts

Ok, I want to know if I'm spinning my tires, reinventing the wheel, and other such trite turns of phrase....

What I want to do is make a set of Message Box UDFs that uses the AutoIt GUI functions so the user can create it WHERE-EVER and WHATEVER size he/she wants it to be.

Ideally, it will (eventually) autosize from the default.

I just have a proof of concept (with barely functional code) at this time working with the one I use the most, the Yes/No/Cancel

#region Initilization section
opt("mustdeclarevars", 1)
;~ #include <BCBS-SupportFunctions.au3>
#include <GUIConstants.au3>
Dim $pos_e = WinGetPos($e)
Dim $hwnd_GUI, $hwnd_YN, $msg
#endregion

$hwnd_YN= _YesNoCancel("Question","Label")
GUISetState(@SW_SHOW,$hwnd_YN)

While 1
      $msg = GUIGetMsg()
WEnd

; Ok, this is going to be a UDF for a Y/N/Cx box with a customizable label and user specified position and size.
; Idealy the box will auto-size, but for now, it's just going to work.

Func _YesNoCancel($name, $label, $width = 300, $height = 100, $x = -1, $y = -1, $style = -1, $exStyle = -1, $parent = "")
   $hwnd_GUI = GUICreate($name, $width, $height, $x, $y, $style, $exStyle, $parent)
   If @error = 1 Then
      SetError(1)
      SetExtended(1)
      Return 0
   EndIf
    $button_yes = GUICtrlCreateButton("Yes",10,$height-20,50,10)
    Return $hwnd_GUI
EndFunc ;==>_YesNoCancel

Is this something that is desirable? Or is there a better way?

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Not that I remember, but here is yours with a bit of adjustments:

$YN= _YesNoCancel("Question","Lab"&@crlf&"el aklsjdf;lkj "&@crlf&"asdlfkj a;lsk"&@crlf&"djf asdfas"&@crlf&"dfasdfasdfa"&@crlf&"sdfasdfasasdfasdfdfasdfasdfasdfasd end "&@crlf&"al;skdjf l;aksjdf laksjdf bob",100,100)
msgbox(1,"",$YN)
; Ok, this is going to be a UDF for a Y/N/Cx box with a customizable label and user specified position and size.
; Idealy the box will auto-size, but for now, it's just going to work.

Func _YesNoCancel($name, $label, $width = 300, $height = 100, $x = -1, $y = -1, $style = -1, $exStyle = -1, $parent = "")
   if $width > 200 then $width = 200
   if $height <40 then $height = 40
     ;autosize
      $test=stringsplit($label,@cr)
      $len=0
      for $_i = 0 to $test[0]
         if StringLen($test[$_i])>$len then $len=StringLen($test[$_i])
         Next
         tooltip($len)
      if $width < $len*6 then  $width = ($len*6)
      if $height<($test[0]*20)+20 then $height=($test[0]*20)+20
     ; end autosize
   $hwnd_GUI = GUICreate($name, $width, $height, $x, $y, $style, $exStyle, $parent)
   $mylist=GUICtrlCreateedit ($label, 0,0,$width,$height-30)
   GUISetState(@SW_SHOW,$hwnd_GUI)
   If @error = 1 Then
      SetError(1)
      SetExtended(1)
      Return 0
   EndIf
    $button_yes = GUICtrlCreateButton("Yes",10,$height-20,50,20)
    $button_no = GUICtrlCreateButton("no",($width/2)-25,$height-20,50,20)
    $button_cancel = GUICtrlCreateButton("cancel",$width-60,$height-20,50,20)
      While 1
        $msg = GUIGetMsg()
        Select
        Case $msg= $button_cancel
               GUIDelete($hwnd_GUI)
               return 2
            Case $msg = $button_yes
               GUIDelete($hwnd_GUI)
               return 6
            Case $msg = $button_no
               GUIDelete($hwnd_GUI)
               return 7
        EndSelect
        sleep(10)
      WEnd
EndFunc;==>_YesNoCancel

For a GUI, you could use an edit box, and since it has scrollbars, it doesn't matter too much for resizing, but I put in a little resizing code ( not great due to font. )

Cool Idea though, a UDF yes/no/cancel box.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Leave it to Drache to "JUMP" out of the "Box" :(


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Thank you to both, for the code and compliment. I just get irritated sometimes at the Message box ALWAYS pops up in the center of the screen. There are times when that is just not desirable for my programs.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Yea, I have the same thoughts, and the fact that the script pauses until you close it or such. I use the gui and edit control all the time and usually put it on the right top corner. When I have a lot of info to display it also is always readable with the scroll bars, unlike the standard control that can go off the page.

Now I just need to find an atonomous(?) font that I like, to make a nice resizing gui UDF. (font that all letters are same width)

Forgot the actual word for it atm.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Yea, I have the same thoughts, and the fact that the script pauses until you close it or such.  I use the gui and edit control all the time and usually put it on the right top corner. When I have a lot of info to display it also is always readable with the scroll bars, unlike the standard control that can go off the page.

Now I just need to find an atonomous(?) font that I like, to make a nice resizing gui UDF. (font that all letters are same width)

Forgot the actual word for it atm.

<{POST_SNAPBACK}>

I think you're looking for a "Fixed Width Font" like "TERMINAL" That's my favourite one to use.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

I was thinking about making one of these, like, you could type in any text, and not have to specify a height or width (those could be optional) and have an X and Y pos optional too... The new msgbox would autosize to the amount of text, and fonts could be specified, and color, and size, etc... Seems like you're doing good though, keep it up! :(


FootbaG

Share this post


Link to post
Share on other sites

I was thinking about making one of these, like, you could type in any text, and not have to specify a height or width (those could be optional) and have an X and Y pos optional too... The new msgbox would autosize to the amount of text, and fonts could be specified, and color, and size, etc... Seems like you're doing good though, keep it up! :(

<{POST_SNAPBACK}>

Well, I've already specified an optional "timeout" in it. The GUI loops 1,000,000,000 times before giving up. That's a default of about 115.74 days at a 10 ms sleep per loop. [(10 * 1,000,000,000) / 1,000 / 60 / 60 / 24] Colours and fonts will be an additional headache that will add even more options to an already insanely long string between the brackets.

As far as colouring, I'll just have to leave it to the end user to customize the function loop, or create a system of tags that the function will recognize and change colour accordingly. Too much of a headache at this time though....I'll vote for "If you want colour, DIYFS" :(

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

ok, work in progress:

My next idea was to add the ability to add buttons dynamically. I still have some spacing issues to work out, but here is the raw version.

It returns the button you click, so very easy to script, and no looking up the tables to see if yes was 6 or 7.

$YN= _UDFButton("Question","A lazy fox jumpped over the brown truck","yes|no|cancel|your button here",100,100)
msgbox(1,"",$YN)
; Ok, this was originally going to be Blue_Drache's UDF for a Y/N/Cx box with a customizable label and user specified position and size.
; Idealy the box will auto-size, and center the buttons equally spaced, but for now, it's just going to work.

Func _UDFButton($name, $label,$buttons="ok|cancel", $width = 300, $height = 100, $x = -1, $y = -1, $style = -1, $exStyle = -1, $parent = "")
   if $width > 200 then $width = 200
   if $height <40 then $height = 40
   ;autosize
      $test=stringsplit($label,@cr)
      $len=0
      for $_i = 0 to $test[0]
         if StringLen($test[$_i])>$len then $len=StringLen($test[$_i])
         Next
         if StringLen($buttons)>$len then $len=StringLen($test[$_i])
         tooltip($len)
      if $width < $len*9 then  $width = ($len*9)
      if $height<($test[0]*20)+20 then $height=($test[0]*20)+20
   ; end autosize
   $hwnd_GUI = GUICreate($name, $width, $height, $x, $y, $style, $exStyle, $parent)
   $font="Terminal"
    GUISetFont (9, 400, 1, $font)  
   $mylist=GUICtrlCreateedit ($label, 0,0,$width,$height-30)
   GUISetState(@SW_SHOW,$hwnd_GUI)
   If @error = 1 Then
      SetError(1)
      SetExtended(1)
      Return 0
   EndIf
   $_bt=StringSplit($buttons,"|")
   dim $but[$_bt[0]+1]
   $offset=0
   for $i= 1 to $_bt[0]
      $but[$i]=GUICtrlCreateButton($_bt[$i],10 + $offset,$height-20)
      $offset=$offset+(stringlen($_bt[$i])*12)
   Next
      While 1
        $msg = GUIGetMsg()
           for $i= 1 to $_bt[0]
                if $msg=$but[$i] Then
                   GUIDelete($hwnd_GUI)
                   return $_bt[$i]
                EndIf
           Next
        sleep(10)
      WEnd
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

; Ok, this was originally going to be Blue_Drache's UDF for a Y/N/Cx box with a customizable label and user specified position and size.

Posted ImagePosted ImagePosted ImagePosted ImagePosted Image

LMFAO!!!

Go ahead and take off with it. I'm just an idea seed man anyway. I like what it's mutated into.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Ok, so try this, now you can exit the custom MsgBox by clicking the red X just like a normal GUI :) Not sure if it would work with more buttons, but, give it a try:

$YN= _UDFButton("Question","A lazy fox jumpped over the brown truck","yes|no|cancel|your button here",100,100)
msgbox(1,"",$YN)
; Ok, this was originally going to be Blue_Drache's UDF for a Y/N/Cx box with a customizable label and user specified position and size.
; Idealy the box will auto-size, and center the buttons equally spaced, but for now, it's just going to work.

Func _UDFButton($name, $label,$buttons="ok|cancel", $width = 300, $height = 100, $x = -1, $y = -1, $style = -1, $exStyle = -1, $parent = "")
   if $width > 200 then $width = 200
   if $height <40 then $height = 40
  ;autosize
      $test=stringsplit($label,@cr)
      $len=0
      for $_i = 0 to $test[0]
         if StringLen($test[$_i])>$len then $len=StringLen($test[$_i])
         Next
         if StringLen($buttons)>$len then $len=StringLen($test[$_i])
        ;tooltip($len)
      if $width < $len*9 then  $width = ($len*9)
      if $height<($test[0]*20)+20 then $height=($test[0]*20)+20
  ; end autosize
   $hwnd_GUI = GUICreate($name, $width, $height, $x, $y, $style, $exStyle, $parent)
   $font="Terminal"
    GUISetFont (9, 400, 1, $font)  
   $mylist=GUICtrlCreateedit ($label, 0,0,$width,$height-30)
   GUISetState(@SW_SHOW,$hwnd_GUI)
   If @error = 1 Then
      SetError(1)
      SetExtended(1)
      Return 0
   EndIf
   $_bt=StringSplit($buttons,"|")
   dim $but[$_bt[0]+1]
   $offset=0
   for $i= 1 to $_bt[0]
      $but[$i]=GUICtrlCreateButton($_bt[$i],10 + $offset,$height-20)
      $offset=$offset+(stringlen($_bt[$i])*12)
   Next
      While 1
        $msg = GUIGetMsg()
           for $i= 1 to $_bt[0]
                if $msg=$but[$i] Then
                   GUIDelete($hwnd_GUI)
                   return $_bt[$i]
               ElseIf $msg = -3 Then
                   Exit
                EndIf
           Next
        sleep(10)
      WEnd
EndFunc

I added this part in the GUI loop:

ElseIf $msg = -3 then
      Exit

:(

EDIT: I commented the tooltip with the length in it, it was pissing me off ::(

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

Took out tooltip, was just in there for testing.

Esc or closing buttons work now.

fixed some errors and put in code to make sure never larger than your screen.

$text = ClipGet()
$YN = _UDFButton("Question", $text, "yes|no|cancel|your button here", 100, 100)
MsgBox(1, "", $YN)
; Ok, this was originally going to be Blue_Drache's UDF for a Y/N/Cx box with a customizable label and user specified position and size.
; Idealy the box will auto-size, and center the buttons equally spaced, but for now, it's just going to work.

Func _UDFButton($name, $label, $buttons = "ok|cancel", $width = 300, $height = 100, $x = -1, $y = -1, $style = -1, $exStyle = -1, $parent = "")
   #include <GUIConstants.au3>
  ;autosize
   $test = StringSplit($label, @CR)
   $len = 0
   For $_i = 0 To $test[0]
      If StringLen($test[$_i]) > $len Then $len = StringLen($test[$_i])
   Next
   If StringLen($buttons) > $len Then $len = StringLen($buttons) + 2
   If $width < $len * 9 Then $width = ($len * 9)
   If $height< ($test[0] * 15) + 20 Then $height= ($test[0] * 15) + 20
   Select; width adj
      Case $width < 200
         $width = 200
      Case $width > @DesktopWidth
         $width = @DesktopWidth
   EndSelect
   Select; hieght adj
      Case $height < 40
         $height = 40
      Case $height > @DesktopHeight
         $height = @DesktopHeight - 60
   EndSelect
  ; end autosize
   $hwnd_GUI = GUICreate($name, $width, $height, $x, $y, $style, $exStyle, $parent)
   $font = "Terminal"
   GUISetFont(9, 400, 1, $font)
   $mylist = GUICtrlCreateEdit($label, 0, 0, $width, $height - 30)
   GUISetState(@SW_SHOW, $hwnd_GUI)
   If @error = 1 Then
      SetError(1)
      SetExtended (1)
      Return 0
   EndIf
   $_bt = StringSplit($buttons, "|")
   Dim $but[$_bt[0] + 1]
   $offset = 0
   For $i = 1 To $_bt[0]
      $but[$i] = GUICtrlCreateButton($_bt[$i], 10 + $offset, $height - 20)
      $offset = $offset+ (StringLen($_bt[$i]) * 12)
   Next
   While 1
      $msg = GUIGetMsg()
      For $i = 1 To $_bt[0]
         If $msg = $but[$i] Then
            GUIDelete($hwnd_GUI)
            Return $_bt[$i]
         EndIf
      Next
      If $msg = $GUI_EVENT_CLOSE Then Return "Closed"; must have #include <GUIConstants.au3> to work.
      Sleep(10)
   Wend
EndFunc  ;==>_UDFButton

AutoIt3, the MACGYVER Pocket Knife for computers.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...