Software Archive
Read-only legacy content
17061 Discussions

on closing a modal dialog box

Intel_C_Intel
Employee
240 Views
How can I close a modal dialog box displaying an image, after a given time is elapsed (using a sleep or slipqq command) without
pressing any key as esc ?
It seems that an event of some sort must be necessarily produced and then processed by a callback containing a dlgexit command. Is there any possibility of mimic pressing ok or cancel button closing automatically the dialog box?
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
240 Views
Splash screen, ha :-). You cannot quite do it with sleep(qq) since it blocks the calling thread, but you may try creating a Windows timer object on dialog start. There's also DlgExit function. I mean something like:

 
USE DFWIN 
... 
INTERFACE  
    SUBROUTINE TimerProc(hWnd, Msg, id, iTime) 
    !DEC$ATTRIBUTES STDCALL:: TimerProc 
    INTEGER hWnd, Msg, iEvent, iTime 
    END SUBROUTINE TimerProc 
END INTERFACE 
... 
!Create a timer object which will call TimerProc each 2000 ms 
IDTimer = SetTimer(NULL, 0, 2000, LOC(TimerProc)) 
... 
iRet=DlgModal(MyDlg) 
... 
SUBROUTINE TimerProc(hWnd, Msg, id, iTime) 
!This one gets called automatically each 2s 
!DEC$ATTRIBUTES STDCALL:: TimerProc 
USE DFWIN 
USE DFLOGM 
INTEGER hWnd, Msg, id, iTime 
 
!Destroy the timer 
iSt = KillTimer(hWnd, id) 
!Close the dialog 
CALL DlgExit(MyDlg) 
 
END SUBROUTINE TimerProc 


In the sample above, MyDlg should be defined globally somehow so that TimerProc could close it appropriately. I'm not sure whether the TimerProc gets called first time at 0 and second time at 2s or only once on 2s -- if the former, you'll have to protect against executing it at 0s.

Sleep(qq) might do the trick also, but

a) it shouldn't be called before DlgModal, but in a dialog initialization callback (if you're not aware about it, please see nearby messages, it's
frequently used trick). After that, DlgExit should be called.

b) even then, your dialog won't be repainted (i.e. if you, say, switch to another app and then back, you'll get impression that your app is dead).

HTH

Jugoslav
0 Kudos
Reply