Jump to content

Recommended Posts

Posted (edited)

Hi Everyone

I want to have a GUI, but which will accept command line options on launch.

So, the commanline would look something like

myAPP.EXE -bigfont -bigicon

where myAPP.EXE would be the name of the AutoIt EXE, and the -bigfont & -bigicon items represent optional command line parameters with which the EXE starts.

I am not looking at creating a CUI.  This is GUI, but with startup command line parameters.  These command line parameters would only be read once, during start up of the EXE.

I have searched the forum, no luck.  What I did find was this commented by Water: https://www.autoitscript.com/forum/topic/138754-adding-command-line-parameter/

Should I start the GUI EXE as normal, and then first possible opportunity read the command line? Is that the way to go?

Thanks in advance

Edited by Skysnake

Skysnake

Why is the snake in the sky?

  • Moderators
Posted

This is by no means a finished script, as you didn't specify what you were trying to do in your gui (I took an educated guess with font and icon). But this should give you an idea:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Local $font, $icon

    Switch $CmdLine[0]
        Case 1
            $font = $CmdLine[1]
        Case 2
            $font = $CmdLine[1]
            $icon = $CmdLine[2]
        Case Else
            Exit(MsgBox($MB_ICONERROR, "My App", "Incorrect Number of Parameters"))
    EndSwitch


    $hGUI = GUICreate("Test", 300, 300)
        GUISetFont(11, 400, Default, ($font = Null) ? "Arial" : $font)
 ;Set font to Arial unless otherwise specified.
        GUISetState(@SW_SHOW)

    $inp = GUICtrlCreateInput("Test Font", 10, 20, 280, 40)
    $icon = GUICtrlCreatePic(($icon = "") ? @DesktopDir & "\Error.jpg" : $icon, 10, 80, 280, 200) ;Set pic path unless otherwise specified.

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

I replied and my reply seems to have gone to limbo...

@spudw2k, thx, I have read that page, but it left me with gaps in my understanding

@JLogan3o13 THANK YOU VERY MUCH!  This is exactly what I was looking for. I can work with this. Thank you for the accurate and prompt response. :)

Skysnake

Why is the snake in the sky?

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
×
×
  • Create New...