Jump to content

InputBox always on top


Recommended Posts

Hi everybody,
I wanted to share with you this short piece of code where InputBox will always be on top (it's important to have it on top, kind of "MsgBox style") .  It's the shortest way I found to make it happen, with few lines of code :

Do
   $sNb_Quest = InputBox("Quiz", "How many questions to answer ? (1-99)", "10", " M2", _
      220, 140, Default, Default, 0, GUICreate("", 0, 0, 0, 0, Default, @SW_SHOWDEFAULT))
   If @error = 1 Then
      MsgBox(4096, "End of script", "You choosed to Quit")
      Exit
   EndIf
   GUIDelete() ; place this line here, not just after InputBox, or @error will be reset to 0
   $iNb_Quest = Number($sNb_Quest)
Until $iNb_Quest > 0 And IsInt($iNb_Quest) = 1

MsgBox(4096, "Result", "Your choice : " & $iNb_Quest)

In the precedent code, the user can't type more than 2 characters. Inputs like "0" or ".5" or "-1" will be automatically rejected, also the Input is mandatory, default is 10. The last parameter, GUICreate, is the key to have this InputBox always on top (in a quick way)


My question is : should GUIDelete() be present in the code or can we delete that line ?
It seems to work fine without the GUIDelete() line, but in case the loop repeats several times (because of bad inputs), then we will have several GUICreate() without a single GUIDelete() ?
Thanks for... your input :)
 

Link to comment
Share on other sites

this snipet:

$hGui = GUICreate("", 0, 0, 0, 0, Default, @SW_SHOWDEFAULT)
Do
    $sNb_Quest = InputBox("Quiz", "How many questions to answer ? (1-99)", "10", " M2", _
            220, 140, Default, Default, 0, $hGui)
    If @error = 1 Then
        MsgBox(4096, "End of script", "You choosed to Quit")
        Exit
    EndIf
    $iNb_Quest = Number($sNb_Quest)
Until $iNb_Quest > 0 And IsInt($iNb_Quest) = 1

MsgBox(4096, "Result", "Your choice : " & $iNb_Quest)

do the same.

Link to comment
Share on other sites

1 hour ago, pixelsearch said:

should GUIDelete() be present

Like you already speculated, I would agree that the cleanup is probably a good idea in order to avoid any leaks.

20 minutes ago, AutoBert said:

do the same.

Agreed, just uses the same parent gui for each InputBox.  Probably less critical to clean up versus creating a new one each loop.

Link to comment
Share on other sites

Great ! So I'll create the "dummy GUI" outside the loop, as AutoBert suggested.

Then I'll delete it outside the loop too, which should lead us to this final snipet :

$hGui = GUICreate("", 0, 0, 0, 0, Default, @SW_SHOWDEFAULT)
Do
   $sNb_Quest = InputBox("Quiz", "How many questions to answer ? (1-99)", "10", " M2", _
      220, 140, Default, Default, 0, $hGui)
   If @error = 1 Then
      MsgBox(4096, "End of script", "You choosed to Quit")
      Exit
   EndIf
   $iNb_Quest = Number($sNb_Quest)
Until $iNb_Quest > 0 And IsInt($iNb_Quest) = 1

MsgBox(4096, "Result", "Your choice : " & $iNb_Quest)
GUIDelete($hGui)

 Thanks to both of you !

By the way, I guess everybody would like his own InputBox(es) to stay on top. Don't you think the help file could be amended with this kind of snipet, as the InputBox help file doesn't indicate at all how to create an "on top" InputBox ?
 

Edited by pixelsearch
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

×
×
  • Create New...