Page 1 of 1 1
Topic Options
#85291 - 2002-03-12 08:48 PM Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Shawn Administrator Offline
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
#85292 - 2002-03-12 09:46 PM Re: Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Shawn et al,

well it's been a long time ... and occassionaly i am enabled (after 9pm when all kids are sleeping)

So now I am surprised : You say it requires build 9 and obviously my build 6 is way out of date ...

damn have to go and dl ... stand by

J.

ps. : wait a tick ... the design of bb has changed too (man, 3 weeks of being off-line can beat one back to stone-age , eh ?)

[ 12 March 2002, 21:48: Message edited by: jpols ]
_________________________



Top
#85293 - 2002-03-12 10:04 PM Re: Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ah yeah ....

it errors out with unknown command! at line '$button.top = $cury' in 'for each $button in $buttons' ...

Is it me ? Hey, I missed build 7 and 8 then [Frown]

J.
_________________________



Top
#85294 - 2002-03-12 10:31 PM Re: Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hey j !!!

Great to finally see you back. Was just thinking about you this morning in fact.

Couple of things to check bud:

1) Get the latest build from kixtart.tripod.ca

2) Install kixforms.dll into a seperate folder

3) Most important - check if you already have an older version of kixforms.dll in winnt/system32 - if so, remove it. Check elsewhere on your machine as well.

4) Re-register and let me know how it goes.

Or - if you want to keep kixforms.dll in system32, just over-write the old one and re-register from there.

I learned this painfully just a little while ago, when one runs this command:

regsvr32 kixforms.dll

regsvr32 first look in system32 for a dll with that name - if it finds it, it registers that one. If not found, it looks in your current directory ... that's my understanding and its kinda ass-backwards if you ask me. That one had me chasing it for a good day and half.

-Shawn

Top
#85295 - 2002-03-12 11:08 PM Re: Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
uh ... have those dll's kept in system32 since the days of kixlib ... overwritten with build 9 and re-registered , yes ...

stand by .. maybe i have to unzip those alpha kix' ???
_________________________



Top
#85296 - 2002-03-12 11:13 PM Re: Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Should work with 4.02 - what OS ?
Top
#85297 - 2002-03-12 11:50 PM Re: Kixforms: KixMenu - Dynamically build button menus from INI configuration files
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Shawn,

it does work ... again hit by @Curdir ... executing scripts from my Uedit @curdir is %Systemroot%\system32 ... always had to change to @scriptdir ... will never learn ! Will go now hiding under a rock [Embarrassed]

J.
_________________________



Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.057 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org