Announcement

Collapse
No announcement yet.

How to create the "continuous timer" in modeless dialog?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?

    Many thanks
    Last edited by Alexander Holzer; 25 Jun 2008, 06:19 AM.
    Yours sincerely

    #2
    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
    -

    Comment


      #3
      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

      Comment


        #4
        Hello, Wayne Diamond,
        thanks, but I do not understand in THREAD
        Now I shall prepare an example...
        Yours sincerely

        Comment


          #5
          >thanks, but I do not understand in THREAD

          Perhaps some demos would help?

          GUI + Worker Thread + Abort Demo 11-24-07

          Waitable Timer Object Demo June 2005
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


            #6
            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
            Last edited by Alexander Holzer; 25 Jun 2008, 07:21 AM.
            Yours sincerely

            Comment


              #7
              Code:
                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.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


                #8
                Originally posted by Michael Mattias View Post
                Code:
                  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#).
                Last edited by Alexander Holzer; 25 Jun 2008, 07:40 AM.
                Yours sincerely

                Comment


                  #9
                  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.

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                    #10
                    Originally posted by Michael Mattias View Post
                    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.
                    Yours sincerely

                    Comment


                      #11
                      Hello, Wayne Diamond!
                      Super! I used THREAD, how you wrote, everything functions!
                      Now runs my timer without problem.
                      Many thanks!

                      Code:
                      FUNCTION MyThread (BYVAL x AS LONG) AS LONG
                      CALL MakeMsgDialog(...)
                       DO
                         DIALOG DOEVENTS 330
                       LOOP
                      END FUNCTION
                      Yours sincerely

                      Comment


                        #12
                        Alix, glad to hear that fixed the problem

                        You should take some time to read the help files information on the THREAD statement as it will help empower you.
                        -

                        Comment


                          #13
                          THREAD = Friend

                          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.
                          Engineer's Motto: If it aint broke take it apart and fix it

                          "If at 1st you don't succeed... call it version 1.0"

                          "Half of Programming is coding"....."The other 90% is DEBUGGING"

                          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                          Comment

                          Working...
                          X
                          😀
                          🥰
                          🤢
                          😎
                          😡
                          👍
                          👎