Stop dialogboxes 
Author Message
 Stop dialogboxes

Hello,

I'm trying to stop a dialogbox after 60 seconds. When I end the dialog box
directly this works.

Here's my code:

DIALOG SHOW MODELESS hDlg TO Result
DO
        DIALOG DOEVENTS
        DIALOG GET SIZE hDlg TO x&, y&
LOOP UNTIL ISFALSE (x& + y&)
SLEEP 6000
DIALOG END hDlg

The de{*filter*} stops at the DO statement and doesn't run further.

Please help.

Thanx.


begin 666 Streur Frans.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..E-T<F5U<CM&<F%N<PT*1DXZ
M4W1R975R($9R86YS#0I"1$%9.C(P,#$P,S$U#0I%34%)3#M04D5&.TE.5$52

M<W1R975R0&YL+F9O<G1I<V)A;FLN8V]M#0I2158Z,C P,C$P,#E4,38T-#$V

`
end



Mon, 28 Mar 2005 00:44:16 GMT  
 Stop dialogboxes
Hi Frans,

Writing "solid" GUI code can be a little confusing, and the
requirement that a message pump runs continuously until the dialog has
been closed appears to create an impossible situation.  It's certainly
not impossible though... you just have to approach the problem the
correct way -- by writing event-driven code.

Before I offer a solution, I'll try to explain what is happening in
the code you posted, with the aim of helping you improve your design
by helping you understand where you went wrong... :)

At first glance, it looks like the code was written more like
procedural (DOS BASIC) code than event-driven (WIN32) code.  In the
code posted, the message pump loop is running continuously but there
is no "mechanism" in the loop to close the dialog programmatically
(there is no callback function specified, so the dialog could only be
closed by user-intervention).

However, after the loop does terminate [from manual intervention], the
code than waits for 6 seconds (sleep 6000) then tries to close the
[already closed] dialog.  Even if that DIALOG END statement did
reference a valid dialog, the message pump has already stopped running
at that point, so the dialog engine might not be able to process any
queued messages that should be processed in order to close the dialog
(For example, any messages relating to deactivation of focus, close
notification, destruction notification, etc).

The key rule to remember is that a message pump MUST run for the
_entire_ life of a modeless dialog.  Closing a dialog generally causes
a slurry of message to flow through the message pump before and after
the visible dialog window disappears, so it is generally best if the
dialog can be closed from within the callback, rather than from within
the message pump loop... this will ensure that the pumps runs for the
full duration, and the app will behave like a proper Win32
application. {smile}

Therefore, the first task is to create a callback function for the
dialog.

Since you want the screen to disappear after 60 seconds, the usual way
to do this is to use a timer which will tell us when 60 seconds is up.
However, the best design wont use SLEEP 60000... rather it should use
a timer, provided kindly by Windows!  We'll set this timer up to send
the callback a %WM_TIMER message when our 60 seconds is up.

Finally, before I show you some code, I'll point out that using a
system timer within the callback means that there is no need to
operate a "manual" message pump to solve this task... a MODAL dialog
will work perfectly for us here, so we can eliminate the message pump
and related code in your example.  

Here is my suggested solution (disclaimer: I wrote this on-line
without testing it, but it should work pretty much as-is!)

DIALOG SHOW MODAL hDlg CALL dlgcb  ' I added a CALL clause
...
CALLBACK FUNCTION dlgcb  ' Don't forget to DECLARE this!
   SELECT CASE CBMSG
     CASE %WM_INITDIALOG
        ' Dialog starting so initialize timer for 60-sec notifications
        ' 60000 = 60 seconds, timer ID = 1
        SetTimer CBHNDL, 1&, 60000&, BYVAL 0&
     CASE %WM_TIMER
        ' Timer message has arrived... 60 seconds is up!
        DIALOG END CBHNDL
     CASE %WM_DESTROY
        ' Dialog is closing, so we must clean up after ourselves.
        KillTimer CBHNDL, 1&
   END SELECT
END FUNCTION

I hope this helps.  If you have any further questions, please do not
hesitate to ask!

Thanks!

Quote:

>Hello,

>I'm trying to stop a dialogbox after 60 seconds. When I end the dialog box
>directly this works.

>Here's my code:

>DIALOG SHOW MODELESS hDlg TO Result
>DO
>        DIALOG DOEVENTS
>        DIALOG GET SIZE hDlg TO x&, y&
>LOOP UNTIL ISFALSE (x& + y&)
>SLEEP 6000
>DIALOG END hDlg

>The de{*filter*} stops at the DO statement and doesn't run further.

>Please help.

>Thanx.



Lance
powerbasic Support

-------------------------------------------------------------------------
PowerBASIC, Inc.      | 800-780-7707 Sales | "We put the Power in Basic!"
316 Mid Valley Center | 831-659-8000 Voice | http://www.*-*-*.com/



Thu, 31 Mar 2005 23:08:32 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. STOP doesn't stop this procedure [TECHNICAL]

2. stop, I repeat, stop replying to nudds you godam dumbfuks

3. Stopping Stop complaining about FORTRAN and C

4. To STOP or not to STOP

5. URL in a dialogbox?

6. Dialogbox example in win32for?

7. VO: dialogboxes in terminal window

8. dialogboxes in VO

9. FiveWin: Close Window/Dialogbox

10. Dialogbox in windows - How?

11. DialogBox in SBM2

12. DialogBox not supported by Ruby/Tk ??

 

 
Powered by phpBB® Forum Software