You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Announcement
Collapse
No announcement yet.
How to create the "continuous timer" in modeless dialog?
Walking away from Friend, and not letting them know when their back is turned and helping you = "Just how many nights can a human live without sleep anyways????"
THREADS are great....just be careful if too many, or if you leave one running...it could drive you nuts trying to find where and why a program will not end.
It's NOT the fact there is a COM object. The WM_TIMER messages are backed up until the function you call (not shown) on WM_COMMAND is completed and returns control to your main dialog procedure.
Unfortunately it so. Without COM-reference work of the program (not this example ) does not influence the timer. I do not observe any "interruptions" of time.
but during COM reference (create Object, call.., let.., get..) - freezes and then jumps on correct value of time. In it that and a problem
It's NOT the fact there is a COM object. The WM_TIMER messages are backed up until the function you call (not shown) on WM_COMMAND is completed and returns control to your main dialog procedure.
What you are seeing is absolutely the expected behavior the way you coded the program. If that is a "problem" then you have to change the way you coded the program.
Those are some nice demos if I do say so myself. Study them.
CASE %IDC_BTN_DLG3
IF CBCTLMSG = %BN_CLICKED THEN
' com objects reference...through FUNCTION...
' that makes problem !!!
It's not that there is a COM object reference here which is causing your timer code to not execute; it could be anything.
...
The timer goes, but during COM reference (create Object, call.., let.., get..) - freezes and then jumps on correct value of time. In it that and a problem!
But this problem is not shown with standard COM from Мicrosoft App, but only with other programs with COM (writen with C#).
CASE %IDC_BTN_DLG3
IF CBCTLMSG = %BN_CLICKED THEN
' com objects reference...through FUNCTION...
' that makes problem !!!
It's not that there is a COM object reference here which is causing your timer code to not execute; it could be anything.
Whenever any thread of execution - including the main thread - is processing a message, it will not process another message until it has completed processing of the current message.
In your case, it has to complete the processing of WM_COMMAND in the 'main' dialog before it can start processing WM_TIMER in the second dialog.
Hello, Michael Mattias,
thanks, but I have not understood.
@Wayne Diamond & Michael Mattias
How properly to apply THREAD?
Can show on my example?
Many thanks.
Code:
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
%IDC_BTN_DLG1 = 1000
%IDC_BTN_DLG2 = 1001
%IDC_BTN_DLG3 = 1002
%IDC_TIMER = 1003
%IDC_TIME = 1004
GLOBAL hMsgDialog AS DWORD
DECLARE FUNCTION MakeMsgDialog() AS LONG
DECLARE CALLBACK FUNCTION ProcMsgDialog() AS LONG
DECLARE CALLBACK FUNCTION ProcDlg() AS LONG
'==============================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, _
BYVAL hPrevInst AS DWORD, _
BYVAL lpszCmdLine AS ASCIIZ PTR, _
BYVAL nCmdShow AS LONG ) AS LONG
LOCAL hDlg AS DWORD
DIALOG NEW 0, "TEST", , , 70, 75, %WS_CAPTION OR %WS_SYSMENU OR %DS_SETFOREGROUND, TO hDlg
CONTROL ADD BUTTON, hDlg, %IDC_BTN_DLG1, "Start", 12, 10, 50, 14
CONTROL ADD BUTTON, hDlg, %IDC_BTN_DLG2, "End", 12, 30, 50, 14
CONTROL ADD BUTTON, hDlg, %IDC_BTN_DLG3, "COM", 12, 50, 50, 14
DIALOG SHOW MODAL hDlg, CALL ProcDlg()
END FUNCTION
'==============================================================================
CALLBACK FUNCTION ProcDlg() AS LONG
SELECT CASE AS LONG CBMSG
CASE %WM_INITDIALOG
CASE %WM_COMMAND
SELECT CASE AS LONG CBCTL
CASE %IDC_BTN_DLG1
IF CBCTLMSG = %BN_CLICKED THEN
MakeMsgDialog
END IF
CASE %IDC_BTN_DLG2
IF CBCTLMSG = %BN_CLICKED THEN DIALOG END hMsgDialog, 0
CASE %IDC_BTN_DLG3
IF CBCTLMSG = %BN_CLICKED THEN
' com objects reference...through FUNCTION...
' that makes problem !!!
END IF
END SELECT
END SELECT
END FUNCTION
'==============================================================================
CALLBACK FUNCTION ProcMsgDialog() AS LONG
LOCAL sText AS STRING
SELECT CASE AS LONG CBMSG
CASE %WM_INITDIALOG
SetTimer CBHNDL, %IDC_TIMER, 250, BYVAL %NULL
CASE %WM_TIMER
sText = TIME$
CONTROL SET TEXT CBHNDL, %IDC_TIME, sText
CASE %WM_DESTROY
KillTimer CBHNDL, %IDC_TIMER
END SELECT
END FUNCTION
'==============================================================================
FUNCTION MakeMsgDialog() AS LONG
DIALOG NEW 0, "MsgDialog", 0, 0, 60, 30, _
%WS_POPUP OR %WS_BORDER OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME, %WS_EX_TOOLWINDOW, TO hMsgDialog
CONTROL ADD LABEL, hMsgDialog, %IDC_TIME,"", 10, 10, 40, 10, %SS_SUNKEN
DIALOG SHOW MODELESS hMsgDialog, CALL ProcMsgDialog()
DIALOG DOEVENTS 200
END FUNCTION
Alexander,
set up your timer as shown in this PBCC program and it should continue to run, i.e. the function TEST will get called.
Paul.
Code:
$DEBUG ERROR ON
REM use a TIMER TO 0.001s
$INCLUDE "WIN32API.INC"
DECLARE FUNCTION test( BYVAL uID AS LONG, BYVAL uMsg AS LONG, _
BYVAL dwUser AS LONG, BYVAL dw1 AS LONG, BYVAL dw2 AS LONG) AS LONG
GLOBAL COUNT AS LONG
FUNCTION WINMAIN (BYVAL hInstance AS LONG, _
BYVAL hPrevInstance AS LONG, _
BYVAL lpCmdLine AS ASCIIZ PTR, _
BYVAL iCmdShow AS LONG) AS LONG
'start the timer
'1=milliseconds between triggers, 0=maximum timer resolution, test=the routine to call
TimerHandle& = timeSetEvent ( BYVAL 10, BYVAL 0, CODEPTR(test), BYVAL 0&, BYVAL %TIME_PERIODIC)
PRINT "press a key to end."
DO
LOCATE 10,10
PRINT "Time=";FORMAT$(count&/1000,"#######.###");"secs."
SLEEP 1
LOOP UNTIL INSTAT
timeKillEvent TimerHandle&
END FUNCTION
FUNCTION test ( BYVAL uID AS LONG, BYVAL uMsg AS LONG, _
BYVAL dwUser AS LONG, BYVAL dw1 AS LONG, BYVAL dw2 AS LONG) AS LONG
'this is the routine that is run everytime the timer triggers
INCR COUNT
END FUNCTION
Sorry but I don't quite understand your problem, but it seems that using another THREAD may solve it?
Code:
FUNCTION MyThread (BYVAL x AS LONG) AS LONG
DO
'// Put all your important code here
SLEEP 1000
LOOP
END FUNCTION
FUNCTION PBMAIN () AS LONG
LOCAL hThread AS DWORD
THREAD CREATE MyThread(BYVAL 0) TO hThread
END FUNCTION
How to create the "continuous timer" in modeless dialog?
Hello,
my Problem:
Timer freezes during the moment of the reference program to COM-objects. And then goes/jumps further...
How to create the "continuous timer", without freezing/show interruptions?
It probably to make?
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: