#85291 - 2002-03-12 08:48 PM
Kixforms: KixMenu - Dynamically build button menus from INI configuration files
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Along the lines of more pratical application - this script builds a custom button menu from information contained in an INI file. Start this script, click a button, then watch your shell commands get executed in the DOS command window.
This script is relatively small and easy to understandand and also shows that the DoEvents loop isn't just for executing kixtart functions:
Heres a screenshot:
Heres the menu INI file:
KIXMENU.INI
---8<--- [dir] caption = "Directory of c:\temp" shell = "%comspec% /c dir c:\temp" [notepad] caption = "IP Configuration" shell = "%comspec% /c ipconfig /all" [youradhere] caption = "This space for rent" shell = "%comspec% /c echo Just kidding" [explore_c] caption = "Explore C:" shell = "%comspec% /c explorer c:\" [explore_d] caption = "Explore D:" shell = "%comspec% /c explorer d:\" [explore_e] caption = "Explore E:" shell = "%comspec% /c explorer e:\" [explore_f] caption = "Explore F:" shell = "%comspec% /c explorer f:\"
---8<---
And heres KixMenu.kix:
KIXMENU.KIX
code:
break on ; KIXMENU.KIX ; ; Require KiXtart 4 and Kixforms Build 9 ; ; Dynamically builds a button menu from configuration ; information contained in an INI file. ; ; -Shawn ; $PROFILE = "@CURDIR\KIXMENU.INI" $MAXBUTTONS = 25 dim $buttons[$MAXBUTTONS] $form = createobject("kixtart.form") $form.caption = "Menu" $form.minbutton = 0 $form.fontsize = 10 $form.fontname = "verdana" $form.fontbold = 1 $i = 0 $maxlen = 0 ; first - create the buttons for each $section in split(readprofilestring($PROFILE,"",""),chr(10)) if $section $buttons[$i] = $form.commandbutton $buttons[$i].caption = readprofilestring($PROFILE,$section,"caption") if len($buttons[$i].caption) > $maxlen ; is this our biggest button so far ? $maxlen = len($buttons[$i].caption) endif $buttons[$i].onclick = 'shell "' + readprofilestring($PROFILE,$section,"shell") + '"' $i = $i + 1 if $i > $MAXBUTTONS ?"too many menu items" quit() endif endif next ; Redim the button array to the actual no. of button if $i $i=$i-1 redim preserve $buttons[$i] endif ; Layout the buttons on the form $cury = 0 for each $button in $buttons $button.top = $cury $button.width = $maxlen * 9 $cury = $cury + $button.height + 1 next ; Resize the form to hug the buttons (ahhh) $form.scalewidth = $buttons[$i].right $form.scaleheight = $buttons[$i].bottom ; Center the form $form.center ; Run the eventloop $form.show while $form.visible $=execute($form.doevents) loop exit
[ 16 March 2002, 16:04: Message edited by: Shawn ]
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2312 anonymous users online.
|
|
|