Announcement

Collapse
No announcement yet.

TimeSetEvent PBForms DDT

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

  • TimeSetEvent PBForms DDT

    I have compared SetTimer and TimeSetEvent and found that the latter fits my needs.
    However, though I have read Paul Dixon's post (Sep 24, 2007) explaining TimeSetEvent and the couple of links he gave, but being a novice I do not really understand how to use it in a DDT program generated by PB Forms.
    In my attached code, I find that function Test is triggered without a callback, though initialized by it.
    If this code looks OK so far, how ever do I get it to update the dialog each time Test runs?
    -----------------------------------------------------------------------------#PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    #COMPILE EXE
    #DIM ALL
    '------------------------------------------------------------------------------
    ' ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
    #INCLUDE "WIN32API.INC"
    #ENDIF
    #INCLUDE "PBForms.INC"
    #PBFORMS END INCLUDES

    '------------------------------------------------------------------------------
    ' ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_TimerHandleTest = 101
    %IDC_Stop = 1002
    %IDC_RunText = 1001
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    ' ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowTimerHandleTestProc()
    DECLARE FUNCTION ShowTimerHandleTest(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    GLOBAL lCount AS LONG, sRunText AS STRING
    '------------------------------------------------------------------------------
    ' ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION WINMAIN (BYVAL hInstance AS LONG, _
    BYVAL hPrevInstance AS LONG, _
    BYVAL lpCmdLine AS ASCIIZ PTR, _
    BYVAL iCmdShow AS LONG) AS LONG
    sRunText=TIME$
    ShowTimerHandleTest %HWND_DESKTOP

    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

    sRunText=TIME$
    '?????? CONTROL SET TEXT %IDD_TimerHandleTest, %IDC_RunText,sRunText ?????

    END FUNCTION

    '------------------------------------------------------------------------------
    ' ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowTimerHandleTestProc()

    SELECT CASE AS LONG CBMSG
    CASE %WM_INITDIALOG
    'start the timer
    '1=milliseconds between triggers, 0=maximum timer resolution, test=the routine to call
    'lTimerHandle = timeSetEvent(BYVAL 1000, BYVAL 0, CODEPTR(test), BYVAL 0&, BYVAL %TIME_PERIODIC)
    TimeSetEvent(BYVAL 1000, BYVAL 0, CODEPTR(test), BYVAL 0&, BYVAL %TIME_PERIODIC)

    CASE %WM_NCACTIVATE
    STATIC hWndSaveFocus AS DWORD
    IF ISFALSE CBWPARAM THEN
    ' Save control focus
    hWndSaveFocus = GetFocus()
    ELSEIF hWndSaveFocus THEN
    ' Restore control focus
    SetFocus(hWndSaveFocus)
    hWndSaveFocus = 0
    END IF

    CASE %WM_COMMAND
    ' Process control notifications
    SELECT CASE AS LONG CBCTL
    CASE %IDC_RunText

    CASE %IDC_Stop
    IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
    MSGBOX "Stopping " + FORMAT$(%IDC_Stop), _
    %MB_TASKMODAL
    DIALOG END CBHNDL
    END IF
    END SELECT

    END SELECT
    END FUNCTION

    '------------------------------------------------------------------------------
    ' ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowTimerHandleTest(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG

    #PBFORMS BEGIN DIALOG %IDD_TimerHandleTest->->
    LOCAL hDlg AS DWORD
    LOCAL hFont1 AS DWORD
    LOCAL hFont2 AS DWORD

    DIALOG NEW hParent, "Timer Handle Test 1", 70, 70, 201, 121, TO hDlg
    CONTROL ADD LABEL, hDlg, %IDC_RunText, sRunText, 15, 10, 165, 70, _
    %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_SUNKEN, %WS_EX_LEFT OR _
    %WS_EX_LTRREADING
    CONTROL ADD BUTTON, hDlg, %IDC_Stop, "Stop", 125, 95, 55, 15

    hFont1 = PBFormsMakeFont("MS Sans Serif", 12, 700, %FALSE, %FALSE, _
    %FALSE, %ANSI_CHARSET)
    hFont2 = PBFormsMakeFont("MS Sans Serif", 10, 400, %FALSE, %FALSE, _
    %FALSE, %ANSI_CHARSET)

    CONTROL SEND hDlg, %IDC_RunText, %WM_SETFONT, hFont1, 0
    CONTROL SEND hDlg, %IDC_Stop, %WM_SETFONT, hFont2, 0
    #PBFORMS END DIALOG

    DIALOG SHOW MODAL hDlg, CALL ShowTimerHandleTestProc TO lRslt

    #PBFORMS BEGIN CLEANUP %IDD_TimerHandleTest
    DeleteObject hFont1
    DeleteObject hFont2
    #PBFORMS END CLEANUP

    FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    Rich

  • #2
    What is the app. supposed to do?

    BTW it makes your code easier to read if you place the code block delimiters around it, {code} and {/code} but with square braces instead of {}.

    Comment


    • #3
      Rich,
      Just a word of formatting.
      When posting code, try to surround the code with

      [ c o d e ]
      Then insert your code here
      [ / c o d e ]

      Take out the spaces of course so it actually works, but it makes it MUCH easier for others to read
      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


      • #4
        You are nearly there . - Just pass the Dialog handle (CbHndl) to the callback function for use in the Control Set Text statement
        Code:
        FUNCTION test ( BYVAL uID AS LONG, BYVAL uMsg AS LONG, _
                        BYVAL dwUser AS Dword, BYVAL dw1 AS LONG, BYVAL dw2 AS LONG) AS LONG
        '...
          CONTROL SET TEXT dwUser, %IDC_RunText, sRunText  'dwUser = Dialog handle
        '...
        '..
        CALLBACK FUNCTION ShowTimerHandleTestProc()
        '... In the Dialog Callback Function CBHNDL = the Dialog's handle
          TimeSetEvent(BYVAL 1000, BYVAL 0, CODEPTR(test), BYVAL CBHNDL, BYVAL %TIME_PERIODIC)
        '...
        Rgds, Dave

        Comment

        Working...
        X