Announcement

Collapse
No announcement yet.

Timer

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

  • Timer

    Can someone pls tell me what all the parameters of this TIMER funtion do pls.

    SetTimer CBHNDL, 1, 500, BYVAL %Null

    How can I use it to count down from 500m/s to 0 and sent something to a variable like true when done, or the number of m/s elapsed etc.

    There is nothing in the manual about it.

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

  • #2
    You have to look in your MSDN-Library helpfile (or Win32.Hlp ?)
    There are no help for this API-call in Powerbasic helpfiles


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Comment


    • #3
      This is a Basic Function, so I dont think it is on the website. I cant find it in any VB reference works either.

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

      Comment


      • #4
        There is a Timer function in PB which returns the number of seconds since midnight
        it seems to do it precise to 50ms or so.

        Is that what you mean, you could countdown with that. Otherwise I think you mean a control or API, not native to PB

        Try this:

        Code:
        #Compile Exe
        
        Function PbMain
            Dim a As String
            Dim b As String
            Dim c As String
            Dim x As Long
            
            a = Str$(Timer)
            For x = 1 To 10000000:Next
            b = Str$(Timer)
            For x = 1 To 10000000:Next
            c = Str$(Timer)
            
            MsgBox a + b +c
        
        End Function
        ------------------

        Paul Dwyer
        Network Engineer
        Aussie in Tokyo
        (Paul282 at VB-World)

        Comment


        • #5
          This is a Basic Function, so I dont think it is on the website. I cant find it in any VB reference works either.

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

          Comment


          • #6
            Hi Paul,

            No this is not the TIMER function.

            There is an undocumented function called
            SETTIMER
            and
            KILLTIMER

            as used in this POWER BASIC code (complie it to see it work)

            Im asking what the parameters are?

            ----------------------------------------------------------------

            '--------------------------------------------------------------------------------------
            ' Create a progress bar with text in it
            '--------------------------------------------------------------------------------------
            #COMPILE EXE
            #REGISTER NONE
            #DIM ALL
            #INCLUDE "WIN32API.INC"
            '--------------------------------------------------------------------------------------
            CALLBACK FUNCTION PicProc
            STATIC hBrush() AS LONG
            STATIC hDC() AS LONG
            STATIC hBmp() AS LONG
            STATIC Clr() AS LONG
            STATIC i AS LONG
            STATIC Done AS LONG
            STATIC LpPaint AS PaintStruct
            STATIC tRect AS Rect
            STATIC zText AS ASCIIZ * 255
            '----------------------------
            SELECT CASE CBMSG
            CASE %WM_INITDIALOG
            REDIM hBrush(1 TO 2)
            REDIM hDC(0 TO 2)
            REDIM hBmp(1 TO 2)
            REDIM Clr(1 TO 2)
            hBrush(1) = CreateSolidBrush(RGB( 0, 0, 255)): Clr(1) = %White
            hBrush(2) = CreateSolidBrush(RGB(255, 255, 255)): Clr(2) = %Black
            CASE %WM_DESTROY
            FOR i = 1 TO 2: DeleteObject hBrush(i): NEXT
            InvalidateRect GetParent(CBHNDL), BYVAL 0, %True
            UpdateWindow GetParent(CBHNDL)
            CASE %WM_ERASEBKGND: FUNCTION = 1: EXIT FUNCTION
            CASE %WM_USER + 1
            Done = CBWPARAM
            InValidateRect CBHNDL, BYVAL 0, %True: UpdateWindow CBHNDL
            CASE %WM_PAINT
            GetClientRect CBHNDL, tRect
            hDC(0) = BeginPaint(CBHNDL, LpPaint)
            FOR i = 1 TO 2
            hDC(i) = CreateCompatibleDC(hDC(0))
            hBmp(i) = CreateCompatibleBitMap (hDC(0), tRect.nRight, tRect.nBottom)
            SelectObject hDc(i), hBmp(i)
            FillRect hDC(i), tRect, hBrush(i)
            SetBkMode hDC(i), %TRANSPARENT
            SetTextColor hDC(i), Clr(i)
            SELECT CASE Done
            CASE 6 TO 12: zText = "Go get Coffee ..."
            CASE 86 TO 92: zText = "Almost there ..."
            CASE ELSE: zText = STR$(Done)+"%"
            END SELECT
            DrawText hDC(i), zText, -1, tRect, _
            %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
            NEXT
            BitBlt hDC(2), 0, 0, tRect.nRight * Done * 0.01, tRect.nBottom, hDC(1), 0, 0, %SRCCOPY
            BitBlt hDC(0), 0, 0, tRect.nRight, tRect.nBottom, hDC(2), 0, 0, %SRCCOPY
            EndPaint CBHNDL, LpPaint
            FOR i = 1 TO 2: DeleteDC hDC(i): DeleteObject hBmp(i): NEXT
            FUNCTION = 0: EXIT FUNCTION
            END SELECT
            END FUNCTION
            '--------------------------------------------------------------------------------------
            CALLBACK FUNCTION DlgProc
            STATIC Done AS LONG
            STATIC hDlg AS LONG
            SELECT CASE CBMSG
            CASE %WM_COMMAND
            IF CBCTL = 101 THEN
            Done = 0
            SetTimer CBHNDL, 1, 500, BYVAL %Null
            DIALOG NEW CBHNDL, "", 10, 10, 176, 12, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER TO hDlg
            DIALOG SHOW MODELESS hDlg CALL PicProc
            DIALOG SEND hDlg, %WM_USER + 1, Done, 0
            END IF
            CASE %WM_TIMER
            Done = Done + 2
            IF Done > 100 THEN DIALOG END hDlg: KillTimer CBHNDL, 1 ELSE _
            DIALOG SEND hDlg, %WM_USER + 1, Done, 0
            END SELECT
            END FUNCTION
            '--------------------------------------------------------------------------------------
            FUNCTION PBMAIN
            LOCAL hDlg AS LONG
            LOCAL hDlg1 AS LONG
            DIALOG NEW 0, "Progress Bar",,, 200, 80, %WS_SYSMENU TO hDlg
            CONTROL ADD BUTTON, Hdlg, 101, "Show", 50, 40,100, 14, %BS_DEFAULT
            DIALOG SHOW MODAL hDlg CALL DlgProc
            END FUNCTION
            '--------------------------------------------------------------------------------------

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

            Comment


            • #7
              SetTimer is an API function, not a native PowerBASIC function.

              It is documented in MSDN, and in the WIN32.HLP file. WIN32.HLP is available to all registered PowerBASIC/Windows users, and can be downloaded from http://www.powerbasic.com/files/pub/mstools/win32.zip - Warning: this is an 8Mb download that installs to approx 25Mb!

              For a direct link to MSDN on SetTimer, try http://msdn.microsoft.com/library/ps...imers_0euq.htm

              BTW, if you search this BBS for "settimer", you should find some examples. Also, the COOL.BAS demo supplied with PB/DLL uses this API call too.

              I hope this helps!

              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                Here ya go, this will allow you to use multiple timers as well if need be.
                %IDT_TIMER1 = %WM_USER + 2500 'OR WHATEVER

                Code:
                In Your WM_INITDIALOG:
                'Sets it for 250 ms
                     SetTimer CbHndl, %IDT_TIMER1,250, ByVal %NULL
                
                
                Now add this:
                    Case %WM_TIMER
                        Select Case CbWparam
                          Case %IDT_TIMER1
                              'USE CAUTION, this will pop up ever 250ms
                              And do NOT kill it until you are done with your code
                              'Or use a global variable instead of cbhndl and do it from another function (ie use hDlg) 
                              KillTimer cbhndl,%IDT_TIMER1 'DEBUG
                
                        End Select
                ------------------
                Scott
                mailto:[email protected][email protected]</A>
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  for true ms resolution, use the mutimedia timer - not the windows timer (settimer).
                  an example was recently posted. search for timesetevent.

                  *** actually - the search does not find the word. here is the link:

                  ------------------
                  ron

                  Comment

                  Working...
                  X