Jump to content

How to create a dropdown box that read from .ini?


dkwokgs
 Share

Recommended Posts

Hi there,

How to create a dropdown box with list that reads from .ini, on selection also display the discription of the selection and run the app according to the dropdown selection.

??Cannot figure out how.

Please advise. Thanks in advance.

eg. Dropdown list = drop.ini

On selection of Game1-->description box will display "FIFA 2004 - Soccer game" and a "OK" button.

drop.ini contents

--------------------

[App0]

discription="Microsoft Winword"

run="C:\Program Files\Microsoft Office\Office\winword.exe"

[App4]

discription="Firefox Internet Browser"

run="C:\Program Files\Mozilla Firefox\firefox.exe"

[Game1]

discription="FIFA 2004 - Soccer game"

run="C:\Program Files\EA\FIFA2004\FIFA.exe"

Link to comment
Share on other sites

Ok done, that was easier then thought. This was all coded in Autoit V3.0.103.

It can be located here http://www.autoitscript.com/autoit3/files/unstable/autoit/

Here you go....

drop.au3

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("Program Selector", 120, 150,(@DesktopWidth-115)/2, (@DesktopHeight-80)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Button = GuiCtrlCreateButton("OK", 15, 45, 75, 25)
$Combo = GuiCtrlCreateCombo("Microsoft Word", 10, 10, 100, 25)
GUICtrlSetData(-1,"FireFox Internet|FIFA 2004","Microsoft Word")
GUICtrlCreateLabel ( "Description:", 25, 80, 60, 20)
GUICtrlCreateLabel ( "", 10, 95, 100, 50)

GuiSetState()
While 1
FileInstall("drop.ini", @tempdir & "drop.ini")
$msg = GuiGetMsg()
$ReadCombo = GUIRead ( 4 )

If $msg = $GUI_EVENT_CLOSE Then
Exit
ElseIf $ReadCombo = "Microsoft Word" and $msg = 3 Then
Run("C:\Program Files\Microsoft Office\Office\winword.exe")
ElseIf $ReadCombo = "FireFox Internet" and $msg = 3 Then
Run("C:\Program Files\Mozilla Firefox\firefox.exe")
ElseIf $ReadCombo = "FIFA 2004" and $msg = 3 Then
Run("C:\Program Files\EA\FIFA2004\FIFA.exe")
EndIf

If $ReadCombo = "Microsoft Word" Then
$label_dis = IniRead ( @tempdir & "drop.ini", "App0", "dis", "" )
GUICtrlSetData ( 6, $label_dis)
ElseIf $ReadCombo = "FireFox Internet" Then
$label_dis = IniRead ( @tempdir & "drop.ini", "App1", "dis", "" )
GUICtrlSetData ( 6, $label_dis) 
ElseIf $ReadCombo = "FIFA 2004" Then
$label_dis = IniRead ( @tempdir & "drop.ini", "Game0", "dis", "" )
GUICtrlSetData ( 6, $label_dis) 
EndIf

WEnd
Exit

drop.ini

[App0]
dis="Microsoft Winword"
run="C:\Program Files\Microsoft Office\Office\winword.exe"

[App1]
dis="Firefox Internet Browser"
run="C:\Program Files\Mozilla Firefox\firefox.exe"

[Game0]
dis="FIFA 2004 - Soccer game"
run="C:\Program Files\EA\FIFA2004\FIFA.exe"
Edited by Agent Smith
Link to comment
Share on other sites

  • Developers

Ok done, that was easier then thought.  This was all coded in Autoit V3.0.103.

It can be located here http://www.autoitscript.com/autoit3/files/unstable/autoit/

Here you go....

<{POST_SNAPBACK}>

Just a couple of pointers:

- you do a FileInstall("drop.ini", @tempdir & "drop.ini") in the While 1 loop. i would move it up that its only executed once.

- Why not retrieve the run command from the INI file ?

- change the combo Height to 80, else the dropdown doesn't work in win9x

:idiot:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Just a couple of pointers:

- you do a FileInstall("drop.ini", @tempdir & "drop.ini") in the While 1 loop. i would move it up that its only executed once.

- Why not retrieve the run command from the INI file ?

- change the combo Height to 80, else the dropdown doesn't work in win9x

:idiot:

<{POST_SNAPBACK}>

sorry to trouble again.

one question. how to do a auto scan and pull all the sections in the drop.ini without defining it, cos the section might be changing from time to time.

eg. to pull all sections automatically to the dropdown list. includes the description and the run upon click ok.

Sections In drop.ini --> App0 & App4 & Game1 etc.....

---------

[App0]

discription="Microsoft Winword"

run="C:\Program Files\Microsoft Office\Office\winword.exe"

[App4]

discription="Firefox Internet Browser"

run="C:\Program Files\Mozilla Firefox\firefox.exe"

[Game1]

discription="FIFA 2004 - Soccer game"

run="C:\Program Files\EA\FIFA2004\FIFA.exe"

Thanks

Link to comment
Share on other sites

Make a

[_GLOBAL]
Number=(number of programs)
App=(Number of apps)
Game=(number of apps)
App1=(1 or 0 means valid or not)
App2=(1 or 0 means valid or not)
Game1=(1 or 0 means valid or not)
Game2=(1 or 0 means valid or not)

This will work (i think) Note: DO NOT HAVE App0! It should start with App1

Global $file = @tempdir & "drop.ini"
GuiCreate("Program Selector", 220, 400,-1, -1, 0)
$list = GUICtrlSetData(GUICtrlCreateList('', 10, 10, 200, 350),StringTrimRight(List(1),1))
$Button = GuiCtrlCreateButton("OK", 65, 340, 50, 25)
GUISetState()
While 1
   $msg = GUIGetMsg()
   If $msg = $button Then
      $msg = GUIRead($list)
      Run(IniRead($file, List(0), 'Run', ''))
      Exit
   EndIf
WEnd
Func List($flag)
   If $flag Then
      $list = ''
      For $x = 1 To IniRead ($file, "_GLOBAL", "App", "" )
         If IniRead($file,"_GLOBAL",'App' & $x) Then $list = $list & IniRead($file, 'App' & $x, 'Description', '') & '|'
      Next
      For $x = 1 To IniRead ($file, "_GLOBAL", "Game", "" )
         If IniRead($file,"_GLOBAL",'Game' & $x) Then $list = $list & IniRead($file, 'Game' & $x, 'Description', '') & '|'
      Next
      Return $list
   Else
      While 1
         For $x = 1 To IniRead ($file, "_GLOBAL", "App", "" )
            If IniRead($file,"_GLOBAL",'App' & $x) Then 
               If IniRead($file, 'App' & $x, 'Description', '') = $msg Then 
                  $flag = 'App'
                  ExitLoop[2]
               EndIf
            EndIf
         Next
         For $x = 1 To IniRead ($file, "_GLOBAL", "Game", "" )
            If IniRead($file,"_GLOBAL",'Game' & $x) Then 
               If IniRead($file, 'Game' & $x, 'Description', '') = $msg Then 
                  $flag = 'Game'
                  ExitLoop[2]
               EndIf
            EndIf
         Next
         MsgBox('0','','Error', 5000)
         Exit
      WEnd
      Return $flag & $x
   EndIf
EndFunc
Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

Hi Wolvereness,

I get a blank box. Please advise.

can you guide me what does this line means?

and what is this " & '|' " at the end

If IniRead($file,"_GLOBAL","App" & $x,"") Then $list = $list & IniRead($file, 'App' & $x, 'Description', '') & '|'

Thanks

Daniel

Link to comment
Share on other sites

Working on a scipt to write the .ini (that is most likely the problem). Just chill real quick.

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

- change the combo Height to 80, else the dropdown doesn't work in win9x

:idiot:

<{POST_SNAPBACK}>

AMEN To That Brother!!! That drove me crazy for a few days

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

I am coding for Win2k/XP.

But I get a blank box.,

I am trying to " scan for existing section header " in the drop.ini (because the section name will be change from time to time and put into the dropdown list. Is there a way to that. Please see attached.

and upon selection on the dropdown then the description appears..

Please advise.

Thanks

Daniel

Link to comment
Share on other sites

Try this code ... Place the drop.ini in the same directory as the script

This loops through the file a preset number of times(could also be set in the drop.ini) and returns the string you would need for the combo box.

#include <GUIConstants.au3>

$ini = @ScriptDir & "\Drop.ini"
$cnt = 0
While 1
   $tmp = IniRead($ini, "App" & $cnt, "Description", "")
   If $tmp <> "" Then
      $str = $tmp & "|" & $str
   EndIf
   $cnt = $cnt + 1
   If $cnt > 10 then exitloop
Wend
$str = StringTrimRight($str, 1)      
   
GuiCreate("Test", 200, 100, -1, -1)

GUISetState (@SW_SHOW)      ; will display an empty dialog box

$combo1 = GuiCtrlCreateCombo("", 20, 10, 165, 80)
GuiCtrlSetData($combo1, $str)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by sykes

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

Here, just try this

IniWrite(@tempdir & '\drop.ini', '_Global', 'App', 2)
IniWrite(@tempdir & '\drop.ini', '_Global', 'Game', 2)
IniWrite(@tempdir & '\drop.ini', '_Global', 'App1', 1)
IniWrite(@tempdir & '\drop.ini', '_Global', 'App2', 1)
IniWrite(@tempdir & '\drop.ini', '_Global', 'Game1', 1)
IniWrite(@tempdir & '\drop.ini', '_Global', 'Game2', 0)
IniWrite(@tempdir & '\drop.ini', 'App1', 'description', "Microsoft Winword")
IniWrite(@tempdir & '\drop.ini', 'App1', 'run', '"C:\Program Files\Microsoft Office\Office\winword.exe"')
IniWrite(@tempdir & '\drop.ini', 'App2', 'description', "Firefox Internet Browser")
IniWrite(@tempdir & '\drop.ini', 'App2', 'run', '"C:\Program Files\Mozilla Firefox\firefox.exe"')
IniWrite(@tempdir & '\drop.ini', 'Game1', 'description', "FIFA 2004 - Soccer game")
IniWrite(@tempdir & '\drop.ini', 'Game1', 'run', '"C:\Program Files\EA\FIFA2004\FIFA.exe"')
Run that above just once to make a mold for future additions.

Below is the 'fixed' code (I messed up, forgot the \ trailing @TempDir)

Global $file = @tempdir & "\drop.ini"
GuiCreate("Program Selector", 220, 400,-1, -1, 0)
$list = GUICtrlSetData(GUICtrlCreateList('', 10, 10, 200, 350),StringTrimRight(List(1),1))
$Button = GuiCtrlCreateButton("OK", 65, 340, 50, 25)
GUISetState()
While 1
  $msg = GUIGetMsg()
  If $msg = $button Then
     $msg = GUIRead($list)
     Run(IniRead($file, List(0), 'Run', ''))
     Exit
  EndIf
WEnd
Func List($flag)
  If $flag Then
     $list = ''
     For $x = 1 To IniRead ($file, "_GLOBAL", "App", "" )
        If IniRead($file,"_GLOBAL",'App' & $x,'') Then $list = $list & IniRead($file, 'App' & $x, 'Description', '') & '|'
     Next
     For $x = 1 To IniRead ($file, "_GLOBAL", "Game", "" )
        If IniRead($file,"_GLOBAL",'Game' & $x,'') Then $list = $list & IniRead($file, 'Game' & $x, 'Description', '') & '|'
     Next
     Return $list
  Else
     While 1
        For $x = 1 To IniRead ($file, "_GLOBAL", "App", "" )
           If IniRead($file,"_GLOBAL",'App' & $x,'') Then 
              If IniRead($file, 'App' & $x, 'Description', '') = $msg Then 
                 $flag = 'App'
                 ExitLoop[2]
              EndIf
           EndIf
        Next
        For $x = 1 To IniRead ($file, "_GLOBAL", "Game", "" )
           If IniRead($file,"_GLOBAL",'Game' & $x,'') Then 
              If IniRead($file, 'Game' & $x, 'Description', '') = $msg Then 
                 $flag = 'Game'
                 ExitLoop[2]
              EndIf
           EndIf
        Next
        MsgBox('0','','Error', 5000)
        Exit
     WEnd
     Return $flag & $x
  EndIf
EndFunc
Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

is there a ON FOCUS FUNCTION in the combo or list box.

So that when upon focus (click) on the item on the list/dropdown, a msgbox will pop up.

eg. on focus on "Firefox browser" in the list (when click on and item on the list /drop down) not the ok button.

I cannot find anything in the help.

Please advise.

Daniel

Link to comment
Share on other sites

$msg = GUIGetMsg()
   Select
      Case $msg = $combo1
         $selection = GUIRead($combo1)
            Select
               Case $selection = "Firefox Browser"
                  MsgBox(0, "Popup", "You Selected Firefox Browser")
                  
               Case $selection = "Microsoft Word"
                  MsgBox(0, "Popup", "You selected Microsoft Word")
                  
            EndSelect

You would place this in the While/WEnd loop that keeps the GUI running

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

The msg ID would equal the ID of the box...

You just use the List(0) to return which selection was in the box.

If you were to PM me I could provide better help on exactly what your doing.

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

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...