Announcement

Collapse
No announcement yet.

Timer (without a Dialog) please

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

    Timer (without a Dialog) please

    First, Thanks to all those who have posted replys. I have learnt alot since I posted my first question.

    I understand alot more about Dialogs, callback funtions but I still dont get how to create a timer OUTSIDE of a Dialog.

    I have a DLL that is called by a commercially avilable app TradeStation. My DLL is called many many times. The first time it is called I set a DELAY value.

    From then on (2 thru n) I do not want to create a window, but I want to execute the timer to act as a delay ie:

    WHILE TIMER is counting down
    LOOP

    I need delays of the order of 10m/s to 500m/s

    So can i create a DIALOG without showing it to allow the creation of timer?

    [email protected]

    ------------------
    Kind Regards
    Mike

    #2
    mike --

    is this what you're looking for?
    http://


    --
    best regards
    peter scheutz


    ------------------
    Best Regards
    Peter Scheutz

    Comment


      #3
      Timer needs message loop only (which will exist thanks to main modal dialog).
      Simple sample:

      1) Compile Dll
      Code:
        #Compile Dll "a.dll"
        #Dim All
        #Register None
        #Include "Win32Api.Inc"
      
        Global hTimer As Long
        Function TimerProc(ByVal hwnd As Long, ByVal wMsg As Long, idEvent As Dword Ptr,  ByVal dwTime As Dword) As Long
           WinBeep 800, 200
           Function = %True
        End Function
      
        Function LibMain(ByVal hInstance   As Long, _
                          ByVal fwdReason   As Long, _
                          ByVal lpvReserved As Long) Export As Long
            Select Case fwdReason
               Case %DLL_PROCESS_ATTACH: hTimer = SetTimer (%HWND_DESKTOP, 1, 1000, CodePtr(TimerProc))
               Case %DLL_PROCESS_DETACH: KillTimer %HWND_DESKTOP, hTimer: hTimer = 0
            End Select
            LibMain = 1
         End Function
      2) Compile and run Exe
      Code:
         #Compile Exe
         #Register None
         #Dim All
         #Include "win32api.inc"
      
         Function PbMain
            Dim hLib As Long
            hLib = LoadLibrary ("a.dll")
            MsgBox "Nice music ?"
            FreeLibrary hLib
            MsgBox "Silence ?"
         End Function
      BTW, Winbeep under 9x does "hru-hru" instead of beep.

      ------------------
      E-MAIL: [email protected]

      Comment


        #4
        Semen Thankyou,

        However this does not work on my machine
        It compiles and runs, I get the two msgbox's but there is no delay no matter what I set timer to, and no sound (yes vol is up) - sorry.

        I did learn alot about the other methods though - esp attach and detach

        400mhz P2 / win98SE OS

        ------------------
        Kind Regards
        Mike

        Comment


          #5
          Mike --
          see my remark about "hru-hru".
          Under 98 Api WinBeep doesn't work correctly with a speaker.
          If you have a sound card try to use MessageBeep instead of WinBeep.

          For example, MessageBeep %MB_OK or MessageBeep %MB_ICONEXCLAMATION
          But, of course, before it look Control Panel, Sounds and test here default/exclamation sound.

          ------------------
          E-MAIL: [email protected]

          Comment


            #6
            Dear Peter / Ron,

            Here is this MM timer rewritten so it will compile and run (you have to hit the OK btn in the MSGBOX dialog each time tho - stdout is not recognized by PB it seems)

            Perhaps someone could fill in the question marks.

            I also dont understand why there is the ability to call %TIME_CALLBACK_FUNCTION as well as lpFunction. surely you only need to call one function??

            I am also confused about how you would use:
            %TIME_ONESHOT = 0
            %TIME_PERIODIC = 1
            %TIME_CALLBACK_FUNCTION = 1
            %TIME_CALLBACK_EVENT_SET = 16
            %TIME_CALLBACK_EVENT_PULSE = 32

            is %TIME_ONESHOT a handle to a function you want called once after timer has expired?

            Also, why are we DECLARE SUB MMTimerProc and then defining it again?

            Regards
            Mike


            #COMPILE EXE
            GLOBAL Count AS LONG
            '------------------------------------------------------------------------------
            DECLARE FUNCTION timeSetEvent LIB "WINMM.DLL" ALIAS "timeSetEvent" _
            ( BYVAL uDelay AS LONG,_ 'delay between timer firings
            BYVAL uResolution AS LONG, _ '0 = finest resolution (more work for the system)
            BYVAL lpFunction AS LONG,_ 'Function or Sub called after timer expires ????
            BYVAL dwUser AS LONG,_ '?????
            BYVAL uFlags AS LONG) AS LONG'??????
            '----------------------------------------------------------------------------
            DECLARE FUNCTION timeKillEvent LIB "WINMM.DLL" ALIAS "timeKillEvent" _
            ( BYVAL TimerID AS LONG) AS LONG
            '----------------------------------------------------------------------------
            DECLARE SUB MMTimerProc _
            ( BYVAL uID AS LONG,_
            BYVAL uMsg AS LONG, _
            BYVAL dwUser AS LONG,_
            BYVAL lp1 AS LONG,_
            BYVAL lp2 AS LONG )
            '------------------------------------------------------------------------------
            SUB MMTimerProc _
            ( BYVAL uID AS LONG,_
            BYVAL uMsg AS LONG, _
            BYVAL dwUser AS LONG,_
            BYVAL lp1 AS LONG,_
            BYVAL lp2 AS LONG )
            ' *** If using a periodic MM timer, you should ensure the code you place in the timer callback function
            ' *** can finish executing before the next MM timer event.
            INCR Count
            MSGBOX STR$(Count)
            END SUB
            '------------------------------------------------------------------------------
            FUNCTION PBMAIN
            LOCAL hMMTimer AS LONG

            %TIME_ONESHOT = 0 ' Event occurs once, after uDelay milliseconds
            %TIME_PERIODIC = 1 ' Event occurs every uDelay milliseconds.
            %TIME_CALLBACK_FUNCTION = 1 ' When the timer expires, Windows calls the function pointed to by the
            ' lpTimeProc parameter. This is the default.
            %TIME_CALLBACK_EVENT_SET = 16 ' When the timer expires, Windows calls theSetEvent function to set the event
            ' pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.
            %TIME_CALLBACK_EVENT_PULSE = 32 ' When the timer expires, Windows calls thePulseEvent function to pulse the
            ' event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.

            hMMTimer = timeSetEvent ( 2000, 10, CODEPTR(MMTimerProc), 0&, %TIME_PERIODIC OR %TIME_CALLBACK_FUNCTION )
            SLEEP 11000
            timeKillEvent hMMTimer
            END FUNCTION
            '------------------------------------------------------------------------------

            ------------------
            Kind Regards
            Mike

            Comment


              #7
              mike --

              just posted another "timer" related piece of code.
              have a looksee here: timer loop (messagepump with interval function call)

              --
              best regards
              peter scheutz

              ------------------
              Best Regards
              Peter Scheutz

              Comment

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