1. Another Windows Programming Question
- Posted by Ted Fines <fines at macalester.edu> Sep 20, 2003
- 412 views
Thanks for the answers Derek and Elliott. Yes, adding doEvents(0) in a couple of places did the trick. Here's another Windows programming question. This one is more of a style question. I'm working on a program that is similar in format to a 'Wizard'. That is, at the bottom of the screen, there are Previous, Next and Cancel buttons. Above them is a Multi-Line text box. When Next is clicked, the text changes, when Previous is clicked, the last text is shown again. I thought of two ways to do this: (1) Have Multiple Next and Previous Buttons: btnNext1, btnNext2, etc. and btnPrev1, btnPrev2, etc. All the Next buttons would be in exacttly the same location. All the Previous buttons would be in exactly the same location. Each buttons onClick procedure would have something like this: procedure btnNext2_onClick() setVisible(btnNext2,False) setVisible(btnNext3,True) setText(MLText,"This text appears when button 2 gets clicked") end procedure So while the user would be actually clicking a different Next or Previous button each time, they'd never know it. At program startup, all Next buttons, except for 1 are set invisible. Same for the Previous buttons. (2) Create a global variable, current_page, incrementing or decrementing it with each click of Next or Previous, and having a procedure like this: procedure btnNext_onClick() if current_page = 1 then current_page += 1 setText(MLText,"Here is the text for page 2") elsif current_page = 2 then current_page += 1 setText(MLText,"Here is the text for page 3") end if end procedure Of course I'd have checks in there to make sure I didn't go past my last page and all that. Anyway, these are the two ways I thought of to do this sort of thing. I have opted for the first. What do other Eu programmers out there think, and what would/did you do about this sort of program? Thanks, Ted Fines --On Saturday, September 20, 2003 9:15 AM +1000 Derek Parnell <ddparnell at bigpond.com> wrote: > > > ----- Original Message ----- > From: "Ted Fines" <fines at macalester.edu> > To: "EUforum" <EUforum at topica.com> > Sent: Saturday, September 20, 2003 4:59 AM > Subject: Windows programming question > > >> Hi all, >> >> I am not understanding how the order of events really works. I'm using >> Judith's IDE, and Win32lib--both the newest versions. >> >> Here is a procedure for a button: >> procedure btnOK_onClick >> sequence themsg >> themsg = "Now about to run other procedure.\n" >> setText(InfoWindow,themsg) >> sleep(10) >> process_requirement({InfoWindow,DLProgress}) >> end procedure >> >> But even with the sleep(10) in there (which I just added for >> troubleshooting this), the text in my InfoWindow (a ML Text box) doesn't >> get updated until AFTER the other procedure has completed. >> >> I am guessing there is some way to force a refresh of my InfoWindow >> before continuing the procedure. How? > > If the routine 'process_requirement' can take some time (say more than 1 > second) then it would be a good idea to insert some 'doEvents(0)' into > it. The way Windows words is that events that happen while YOUR code is > running, is blocked until your code returns to Windows. To help alleviate > this, the doEvents(0) call will temporarily give control back to Windows > so it can process any events that might have happened - including > repainting parts of your screen. >> Similarly, the procedure that gets called downloads a file, then runs it >> with a "system" call. It shows the download progress while downloading >> the file, in a label box. What is displayed are bytes downloaded so >> far, and the percent of the total, like this: >> "12849 bytes (5%)" >> >> But again, the updating of the label box lags far behind. The program >> actually gets downloaded, runs, and only after I quit it does the >> progress indicator get refreshed to say 100%. In my initial testing of >> the download procedure, I just wrote everything to a command window >> with "puts" commands, and did not have this problem. >> >> Could someone fill me in on refreshing widget/window contents? > > Yes, definitely run a doEvents(0) call after each time you update the > progress display. > > -- > Derek > > > > TOPICA - Start your own email discussion group. FREE! > >
2. Re: Another Windows Programming Question
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Sep 20, 2003
- 411 views
On Sat, 20 Sep 2003 10:00:09 -0500, Ted Fines <fines at macalester.edu> wrote: >(2) Create a global variable, current_page, incrementing or decrementing= it=20 >with each click of Next or Previous, and having a procedure like this: >procedure btnNext_onClick() > if current_page =3D 1 then > current_page +=3D 1 > setText(MLText,"Here is the text for page 2") > elsif current_page =3D 2 then > current_page +=3D 1 > setText(MLText,"Here is the text for page 3") > end if >end procedure > >Anyway, these are the two ways I thought of to do this sort of thing. I= =20 >have opted for the first. What do other Eu programmers out there think,= =20 >and what would/did you do about this sort of program? I'd definitely go for the second, and have a table of the required texts, so I could just code: if current_page<max_pages then current_page+=3D1 setText(MLText,texttable[current_page]) end if end procedure. If you put several buttons at the same place, without calling SetVisible() like a maniac, then (I haven't tested this) Windows won't know which one to pass the click message to, and will always send it to the first or the last, or maybe even all the buttons. Pete
3. Re: Another Windows Programming Question
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 20, 2003
- 396 views
----- Original Message ----- From: "Ted Fines" <fines at macalester.edu> To: "EUforum" <EUforum at topica.com> Subject: Another Windows Programming Question > > > Thanks for the answers Derek and Elliott. Yes, adding doEvents(0) in a > couple of places did the trick. > > Here's another Windows programming question. This one is more of a style > question. > > I'm working on a program that is similar in format to a 'Wizard'. That is, > at the bottom of the screen, there are Previous, Next and Cancel buttons. > Above them is a Multi-Line text box. When Next is clicked, the text > changes, when Previous is clicked, the last text is shown again. > > I thought of two ways to do this: > (1) Have Multiple Next and Previous Buttons: btnNext1, btnNext2, etc. and > btnPrev1, btnPrev2, etc. All the Next buttons would be in exacttly the > same location. All the Previous buttons would be in exactly the same > location. Each buttons onClick procedure would have something like this: > procedure btnNext2_onClick() > setVisible(btnNext2,False) > setVisible(btnNext3,True) > setText(MLText,"This text appears when button 2 gets clicked") > end procedure > > So while the user would be actually clicking a different Next or Previous > button each time, they'd never know it. At program startup, all Next > buttons, except for 1 are set invisible. Same for the Previous buttons. > > (2) Create a global variable, current_page, incrementing or decrementing it > with each click of Next or Previous, and having a procedure like this: > procedure btnNext_onClick() > if current_page = 1 then > current_page += 1 > setText(MLText,"Here is the text for page 2") > elsif current_page = 2 then > current_page += 1 > setText(MLText,"Here is the text for page 3") > end if > end procedure > > Of course I'd have checks in there to make sure I didn't go past my last > page and all that. > > Anyway, these are the two ways I thought of to do this sort of thing. I > have opted for the first. What do other Eu programmers out there think, > and what would/did you do about this sort of program? Definitely the second approach, but use 'current_page' as an index for the text to display. procedure btnNextPrev_onClick(integer self, integer event, sequence parms) if self = PrevBtn then current_page -= 1 else current_page += 1 end if setEnabled(NextBtn, current_page != LastPage) setEnabled(PrevBtn, current_page != 1) setText(MLText,PageText[current_page]) end procedure setHandler({PrevBtn,NextBtn, w32HClick, routine_id("btnNextPrev_onClick")) -- Initially -- current_page = 0 btnNextPrev_onClick(NextBtn, 0, {}) -- Derek