View previous topic :: View next topic |
Author |
Message |
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Tue Nov 19, 2002 10:43 am Post subject: Multiple Child Windows... |
|
|
Creates multiple windows and matches events to the
appropriate one.
This example allows the user to open an unlimited
number of cascading resizable child windows with
edit boxes. Click "File" then select "New Window"
to open a child window.
__________________________________________________________________________________________________________________________
Code: |
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
%%main = "Multiple Child Windows"
DIALOG CREATE,%%main,20,20,500,300,RESIZABLE
DIALOG ADD,MENU,&File,&New Window,-,E&xit|Alt+X
DIALOG ADD,EDIT,MainEdit,0,0,500,300,,,MULTI,SCROLL
DIALOG SHOW
rem -- For child dialog numbers --
LIST CREATE, 1
LIST ADD, 1, ""
%%num = 0
:EVLOOP
WAIT EVENT
rem -- %e is event, %d is dialog number that issued it (0,1,2,etc.) --
PARSE "%e;%d", @event(d)
DIALOG SELECT, %d
goto %e
:RESIZE
LIST SEEK, 1, 0
if @match(1, @winactive())
%d = @index(1)
PARSE "%%window;%%edit", @item(1)
DIALOG SETPOS, %%edit, 0, 0, @diff(@winpos(%%window, W), 8), @diff(@winpos(%%window, H), 26)
else
DIALOG SETPOS, MainEdit, 0, 0, @diff(@winpos(%%main, W), 8), @diff(@winpos(%%main, H), 46)
end
goto EVLOOP
:New WindowMENU
%%num = @succ(%%num)
%%top = @sum(@winpos(%%main, T), @prod(%%num, 20), 26)
%%left = @sum(@winpos(%%main, L), @prod(%%num, 20))
LIST ADD, 1,"Child Window "%%num|"Edit"%%num
DIALOG CREATE,"Child Window "%%num,%%top,%%left,300,200,ONTOP,RESIZABLE
DIALOG ADD,EDIT,"Edit"%%num,0,0,300,200,,,MULTI,SCROLL
DIALOG SHOW
goto EVLOOP
:ExitMENU
:CLOSE
if @greater(%d, 0)
DIALOG CLOSE
LIST SEEK, 1, %d
LIST DELETE, 1
%e = @event()
goto EVLOOP
end
EXIT
|
EDIT - Changed EVLOOP to select appropriate dialog (thanks
to cnodnarb for this).
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Last edited by Mac on Wed Dec 11, 2002 1:35 am; edited 1 time in total |
|
Back to top |
|
|
cnodnarb Professional Member
Joined: 11 Sep 2002 Posts: 762 Location: Rockeledge, GA
|
Posted: Wed Dec 11, 2002 1:24 am Post subject: |
|
|
To avoid having to select dialog during an event occurance replace evloop with below. This will avoid having the wrond dialog selected when referencing controls.
Code: |
:evloop
wait event
parse "%e;%d",@event(d)
dialog select,%d
goto %e
|
NodNarb |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Dec 11, 2002 1:37 am Post subject: |
|
|
Good idea, that saves a lot of code.
I changed the code example above.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Serge Professional Member
Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Wed Dec 11, 2002 12:19 pm Post subject: |
|
|
Runs great Mac - nice job!
Serge _________________
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Dec 11, 2002 10:50 pm Post subject: |
|
|
Thanks Serge.
BTW guys, selecting the dialog from the EVLOOP requires
special handling of TIMER events. TIMER events will parse
the last dialog selected into %d, and if it's closed ya get an
error.
So if ya don't use separate EVLOOPs for child windows,
use something like this to catch TIMER events:
Code: |
:TIMER
rem -- Do nothing, this is just a test --
:EVLOOP
WAIT EVENT, 1
rem -- %e is event, %d is dialog number that issued it (0,1,2,etc.) --
PARSE "%e;%d", @event(d)
if @equal(%e, "TIMER")
goto TIMER
end
DIALOG SELECT, %d
goto %e
|
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
cnodnarb Professional Member
Joined: 11 Sep 2002 Posts: 762 Location: Rockeledge, GA
|
Posted: Thu Dec 12, 2002 2:13 pm Post subject: |
|
|
How many ways are there to tackle an issue? How many programmers are there to discuss it? Same answer
Code: |
:evloop
wait 1
%%eventdialog = @event(d)
parse "%%event;%%dialog",%%eventdialog
if %%event
dialog select,%%dialog
goto %%event
else
rem commands and functions to occur while idle go here
end
rem or here
goto evloop
|
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Dec 12, 2002 9:44 pm Post subject: |
|
|
Well, all things being equal, I prefer less code
and fewer vars. The TIMER event is hard to beat.
Your example can wait up to a full second before
processing an event (or longer if the idle stuff
needs more WAIT time).
If ya wanna use a loop, I'd go with REPEAT/UNTIL,
a shorter WAIT, and an incremented VAR for timing
idle events. Ya can either reset %%timer to zero at
the beginning of the loop, or once at the beginning
of the program to make it fulfill the count before
each timed event (even if ya do other stuff).
Requires OPTION DECIMALSEP, "."
Code: |
:EVLOOP
%%timer = 0
REPEAT
WAIT ".5"
%%timer = @succ(%%timer )
rem -- Do something approx every 5 seconds --
if @equal(%%timer , 10)
INFO Time to do something...@tab()
%%timer = 0
end
PARSE "%e;%d", @event(d)
UNTIL %e
DIALOG SELECT, %d
goto %e
|
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
cnodnarb Professional Member
Joined: 11 Sep 2002 Posts: 762 Location: Rockeledge, GA
|
Posted: Fri Dec 13, 2002 5:26 pm Post subject: |
|
|
*BANG*
Ooo, you got me Mac!
I didn't realize the additional advantage of using a TIMER label believe it or not!! When I needed the same ability I would break down my delay into multiple wait commands and check for events after each wait...
NodNarb |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Dec 13, 2002 11:33 pm Post subject: |
|
|
LOL, musta been a lucky shot...
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|