Announcement

Collapse
No announcement yet.

Timer Display

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

  • Gösta H. Lovgren-2
    replied
    Originally posted by Paul Dixon View Post
    Gösta,

    you're creating a "Dummy graphic window" for some reason every time you start or stop the timer. It's that window which is showing up as a new task.

    Paul.
    That was it, Paul. I never Ended the G Window I was creating so I could use the G Inkey$ to trap a keystroke and so created a new one each time the timer was (re)started.

    Add this in Timer_Start
    Code:
    'end loop '***********************
    '
    trexit:
    [COLOR=red] Graphic Window End[/COLOR]
      Graphic Detach
    Sometimes I'm so dumb I amaze myself even.

    ========================================================
    It seems to me, Golan, that the advance of civilization
    is nothing but an exercise in the limiting of privacy.
    Isaac Asimov, Foundation's Edge (1920- 1992)
    ========================================================

    Leave a comment:


  • Mike Doty
    replied
    It is more general so it could be popped into any program.

    It doesn't change the focus to a specific button (which might not be the one wanted.)
    I did not test setting focus to a button that is disabled, not visible, etc.

    Leave a comment:


  • Rodney Hicks
    replied
    Gösta
    I'm not(and never have) getting multiple instances of the program. I'm running Vista.

    Mike
    I'm not disputing, just curious as to why one might be better than the other in this case?

    Leave a comment:


  • Mike Doty
    replied
    This might be better than hardcoding focus to a button.
    DIALOG SHOW STATE ghDlg, %SW_SHOWNORMAL 'in case minimized
    SetForegroundWindow(ghDlg)

    Leave a comment:


  • Paul Dixon
    replied
    Gösta,
    Now the only thing to figure out is why it creates so many instances.
    you're creating a "Dummy graphic window" for some reason every time you start or stop the timer. It's that window which is showing up as a new task.

    Paul.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Thanks guys. The Digital_Timer now appears to work like I want it to. It does pop up on top when expired w/o the msgbox. (Note to Mike, I saw the ghdlg. I'd just gotten into the (not good) habit of always making hdlg global. Think I'll break it now {grin}

    What I wrote the timer for is to record DVD's from the tv for the kids/grandkids. Shows they wouldn't get to see for one reason or another (have actually made of 500 of them). What I was doing before was setting a manual timer but that was soooo last century. I had seen digital timers and thought this would be a perfect app for one. Big easy to see letters. Easy to set.

    This timer is slient unil the last 10 seconds when it starts ticking until the alarm goes off.

    Now the only thing to figure out is why it creates so many instances. Set te timer for a minute and stop it (stop button) then do an Alt Tab (or look at te program bar on te bottom of your screen) and you'll see several instances (two extra for each time it stops/starts). Curious. Not fatal but confusing for sure.

    Here's final code (I think):
    '
    Code:
    'PBWIN 9.02 - Win32Api 10/2009 - XP Pro SP
    '1} force on top when time is done
    #Dim All
    #Compile Exe
    #Optimize SPEED
    '#Debug Display On'off for production code
    #Include "WIN32API.INC" '10/2009
    #Include "COMDLG32.INC" '08/2008
    #Include "InitCtrl.inc" '08/2008
    '
    '
    ' *******************************************************
    '
    %ButtonPlus_Loaded = 1 'Note set to 0 if you don't have ButtonPlus, rem  Include &
                           '3 lines within 2 functions beginning with z_ (should be line numbers in the 80's)
                           ' if you still get errors
    #If %ButtonPlus_Loaded
       #Include "C:\Only_My_Programs\Include Files\ButtonPlus.bas"
    #EndIf
     
    #If Not %ButtonPlus_Loaded    'else will get extra errors from existing calls
       %BP_TEXT_COLOR    = 1
       %BP_ICON_ID       = 2
       %BP_ICON_WIDTH    = 3
       %BP_ICON_HEIGHT   = 4
       %BP_ICON_POS      = 5
       %BP_FACE_COLOR    = 6
       %BP_FACE_BLEND    = 7
       %BP_SPOT_COLOR    = 8
       %BP_SPOT_BLEND    = 9
       %BP_SPOT_WIDTH    = 10
       %BP_SPOT_HEIGHT   = 11
       %BP_SPOT_POS      = 12
    #EndIf
    ' #Else
    '   #Include "C:\Only_My_Programs\Include Files\ButtonPlus.bas"
    '#EndIf
    '
    ' *******************************************************
    '
    '
    %Id_Exit_Btn = 999
    %Hours_tb = 1000
    %Hour_Spinner = 1002
    %Minutes_tb = 1010
    %Minute_Spinner = 1012
    %Seconds_tb = 1020
    %Second_Spinner = 1022
    %Start_Timer_Btn = 1100
    %Stop_Timer_Btn  = 1110
    %Reset_Timer_Btn  = 1120
    %Graphic_Target = 1200
    '
    %Top = %MB_SYSTEMMODAL
    '
    %Btn_Color = &he75718
    %Neutral_Color = &hd8e9ec
    '
    $Title = Space$(20) & "Timer"
    '
    ' *******************************************************
    '
        'keep consistent style wherever used
    %spinner_style = %WS_CHILD Or _
                     %WS_VISIBLE 'Or _
                     's_wrap Or _
                    ' s_arrowkeys
    '
    ' *******************************************************
    '
      Global g_hdlg As Dword
      Global Comic(), Consolas() As Dword
      Global g_Secs_to_go, Dlg_ht, Dlg_Wd As Long 'Global in case want to use in Controls
      Global pnmud As nm_updown Ptr     'pointer to structure used by spinner
      Global g_Title As String * 50
      Global g_Start_Stop_Flag, g_Button_Plus1, g_Button_Plus2, g_Button_Plus3 As Long
    '
    ' *******************************************************
    '
    '
    #If %ButtonPlus_Loaded = 1
    Function  z_Btn_Set_Face_Color(ddlg As Dword, dId As Long, Btn_Color As Long) As Long
       ButtonPlus  ddlg, dId, %BP_FACE_BLEND, 255 'true color
       ButtonPlus dDlg, dId, %BP_FACE_COLOR, Btn_Color ' &H008FDF8F
    End Function
    '
    Function z_Btn_Set_Text_Color(ddlg As Dword, Id As Long, Btn_Color As Long) As Long
       ButtonPlus dDlg, Id, %BP_Text_COLOR, Btn_Color ' &H008FDF8F
    End Function
    #EndIf
    '
    Macro Common_Locals 'Macro easier than retyping and maintains coding consistency
      Local Stile, Row, col, ht, wd, Longest,ctr, ln, ln1, i As Long
      Local text_Color, Face_color, tctl, spcr, idd, idd1 As Long
      Local flag, n, hrs, secs, mins, tmr, tmr1, Secs_To_Run As Long
    '
      Local  w, l, s As String
    End Macro
    '
    Sub Fonts_Setup
      common_locals
             Dim Comic(2 To 72), Consolas(2 To 72)
             For ctr = 2 To 72
               Font New "Comic Sans MS", ctr To Comic(ctr)
               Font New "Consolas", ctr To Consolas(ctr)
             Next ctr
    End Sub
    '
    Macro Show_Time_in_Title = Dialog Set Text g_hdlg, Using$("##:##:##", hrs, mins, secs)
    '
    Macro Redraw_Textboxes
      n = g_Secs_to_go
      hrs = n \ 3600
        n = n - (Hrs * 60)
      Mins = (n  \ 60)
       Secs = n - (mins * 60)
      idd = %Hours_tb: Control Set Text g_hdlg, idd, Right$(Str$(hrs), 2): Control ReDraw  g_hdlg, idd
      idd = %Minutes_tb: Control Set Text g_hdlg, idd, Right$(Str$(mins), 2): Control ReDraw  g_hdlg, idd
      idd = %Seconds_tb: Control Set Text g_hdlg, idd, Right$(Str$(Secs), 2): Control ReDraw  g_hdlg, idd
      'control set focus g_hdlg, idd 'Attempt to keep dialog updating
    End Macro
    '
    Sub Disable_Buttons
      common_locals
       idd = %Start_Timer_Btn: l$ = " ": Face_color = %Neutral_Color: Text_Color = %Neutral_Color: GoSub Color_Btn
       idd = %Reset_Timer_Btn: l$ = " ": Face_color = %Neutral_Color:  Text_Color = %Neutral_Color: GoSub Color_Btn
       idd = %Stop_Timer_Btn : l$ = "Stop ": Face_color = %Red: Text_Color = %White: GoSub Color_Btn
       idd = %Id_Exit_Btn: l$ = "Press Any Key to Stop": Face_color = %White: Text_Color = %Black: GoSub Color_Btn
      Control Enable g_hdlg, %Stop_Timer_Btn
     Exit Sub
    '
    Color_Btn:
      Control Disable g_hdlg, idd
      Control Set Text g_hdlg, idd, l$
      #If %ButtonPlus_Loaded = 1
        z_Btn_Set_Face_Color(g_hdlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(g_hdlg, Idd, Text_Color)
      #EndIf
      Control ReDraw g_hdlg, idd
    Return
    End Sub
    '
    '
    Sub Enable_Buttons
      common_locals
       idd = %Start_Timer_Btn: l$ = "&Start": Face_color = %Green: Text_Color = %Black: GoSub Color_Btn
       idd = %Reset_Timer_Btn: l$ = "&Reset": Face_color = %Blue:  Text_Color = %White: GoSub Color_Btn
       idd = %Stop_Timer_Btn : l$ = "Unknown": Face_color = %Neutral_Color: Text_Color = %Neutral_Color: GoSub Color_Btn
       idd = %Id_Exit_Btn: l$ = "Abandon Ship": Face_color = %White : Text_Color = %Black: GoSub Color_Btn
      Control Disable g_hdlg, %Stop_Timer_Btn
     Exit Sub
    '
    Color_Btn:
      Control Enable g_hdlg, idd
      Control Set Text g_hdlg, idd, l$
      #If %ButtonPlus_Loaded = 1
        z_Btn_Set_Face_Color(g_hdlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(g_hdlg, Idd, Text_Color)
      #EndIf
      Control ReDraw g_hdlg, idd
    Return
    End Sub
    '
    ' *******************************************************
    '
    Function WorkerThread(ByVal x As Long) As Long
      Function = Timer_Start()
    End Function
    '
    ' *******************************************************
    '
    '
    Function Time_Left As Long
      common_Locals
      idd = %Hours_tb: Control Get Text g_hdlg, idd To s$
       hrs = Val(s$)
       Secs_To_Run = hrs * 60 * 60
      idd = %Minutes_tb: Control Get Text g_hdlg, idd To s$
       mins = Val(s$)
       Secs_To_Run = Secs_To_Run + (mins * 60)
      idd = %Seconds_tb: Control Get Text g_hdlg, idd To s$
       secs = Val(s$)
       Secs_To_Run = Secs_To_Run + secs
       Function = Secs_To_Run
    End Function
    '
    Function Timer_Start() As Long
      common_locals
      Local hwin As Dword
      Local Time_to_Elapse As Long
      g_Secs_to_go = Time_Left 'calculates from textboxes
      If g_Secs_to_go = < 0 Then
         ? "Timer not set yet", %Top, Trim$($Title)
         Exit Function
      End If
    '
      Time_to_Elapse = Timer + g_Secs_to_go
      Graphic Window "", 1, 1, 1,  1 To hWin 'set dummy graphic window
      Graphic Attach hwin, 0
      CSet g_Title$ = "Timer At Work": Dialog Set Text g_hdlg, g_Title$
      Disable_Buttons
      flag = 0
    '
    'start loop *********************
      Do
       If g_Start_Stop_Flag = 1 Then 
         Exit Loop 'sent from Stop button
       End If  
    '
         g_Secs_to_go = Time_to_Elapse - Timer
         Graphic INKEY$ To w$
         n = Len(w$)
         Select Case n
           Case 0
           '
           Case 1 'key pressed
              g_Start_Stop_Flag = 2
              Exit Loop 
           Case 2 'extended key pressed  '<<< Never gets hit
             ?"extended"
             Exit Loop
         End Select
    '
       If Timer => tmr + 1 Then 'only once a second
          Redraw_Textboxes  'redraw tb's
          Show_Time_in_Title
          If g_Secs_to_go  < 11 Then winbeep 100, 10 'only last 10 seconds
          tmr = Timer
       End If
      Loop While g_Secs_to_go > 0
      Select Case g_Start_Stop_Flag
         Case 0
          CSet g_Title$ = "Timer Finished"
         Case 1
         CSet g_Title$ = "Timer Stopped by Button"
         Case 2
           CSet g_Title$ = "Timer Stopped by key"
      End Select                          
      Dialog Set Text g_hdlg, g_Title$
    'end loop '***********************
    '
    trexit:
      Graphic Detach
      Redraw_Textboxes  'redraw tb's
      If flag + g_Start_Stop_Flag = 0 Then 'else no alarm
         For ctr = 1 To 10
            winbeep 2000, 1
            Sleep 100
         Next ctr
         '? "Timer expired", %Top, $title
         'SetWindowPos g_hdlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE
         Dialog Show State g_hdlg, %SW_SHOWNORMAL   'restore if minimized after seeing Rodney Hicks post
         Control Set Focus g_hdlg, %Start_Timer_Btn      'brings to foreground
     
     
      End If
      Enable_Buttons
    End Function
    '
    '
    CallBack Function Dialog_Processor
      Common_Locals
      Local h_thread, dwres As Dword
      '
      Select Case CbMsg     'This is TO determine the message TYPE
         '
         Case %WM_INITDIALOG'<- Initialiaton when the program loads
           Enable_Buttons
         '
         Case %WM_SYSCOMMAND 'Traps Any Alt key but only F4 closes
    '
         Case %WM_NOTIFY: 'Spinner_Macro   'for spinners
            pnmud = CB.lParam
              If @pnmud.hdr.Code = 
    n_deltapos Then  '+1 or -1
                 ctr =  @pnmud.idelta * -1 'change sign to match arrows
             End If
             tctl = CB.Ctl - 2 ' -2 to match to textboxes id's
             Select Case CB.Ctl
               Case %Hour_Spinner   '
                 Control Get Text g_hdlg, tctl To s$
                   ctr = Val(s$) + ctr
                   If ctr > 24 Then ctr = 0
                   If ctr < 0 Then ctr = 24
                  Control Set Text g_hdlg, CB.Ctl - 2,  Right$(Str$(ctr), 2)
               '
               Case %Minute_Spinner, %Second_Spinner
                 Control Get Text g_hdlg, tCtl To s$
                   ctr = Val(s$) + ctr
                   If ctr > 60 Then ctr = 0
                   If ctr < 0 Then ctr = 60
                  Control Set Text g_hdlg, CB.Ctl - 2,  Right$(Str$(ctr), 2)
             End Select
         '
         Case %WM_COMMAND  'This processes command messages
           Select Case CbCtl
             Case %Id_Exit_Btn
               Select Case CbCtlMsg
                  Case 0
                    Dialog End CbHndl 'Applikation beenden
               End Select
         '
         Case %Start_Timer_Btn
            g_Start_Stop_Flag = 0
            Thread Create WorkerThread(0)  To h_Thread
            Thread Close h_thread To dwres
             CSet g_Title$ = "Time Elapsed": Dialog Set Text g_hdlg, g_Title$
         '
         Case %Stop_Timer_Btn
            g_Start_Stop_Flag = 1
            Timer_start
             CSet g_Title$ = "Timer Stopped": Dialog Set Text g_hdlg, g_Title$
    '        WorkerThread(1)
         '
         Case %Reset_Timer_Btn
            idd = %Hours_tb: Control Set Text g_hdlg, idd, "0"
            idd = %Minutes_tb: Control Set Text g_hdlg, idd, "0"
            idd = %Seconds_tb: Control Set Text g_hdlg, idd, "0"
            Dialog Set Text g_hdlg, $Title
         '
           End Select
      End Select
    End Function
    Function PBMain
      Common_Locals
      Fonts_Setup
       Stile = Stile Or %WS_CAPTION
       Stile = Stile Or %WS_SYSMENU
       Stile = Stile Or %WS_THICKFRAME
       Stile = Stile Or %WM_HELP
       Stile = Stile Or %WS_BORDER  'doesn't do anything
      Dlg_ht = 250
      Dlg_Wd = 415
    '  Dialog Font "Consolas", 60 ' Big Unicodes
      Dialog New Pixels, g_hdlg, $Title, , , Dlg_Wd, Dlg_Ht, Stile To g_hdlg 'centered
      Row = 10
      col = 10
      Wd = 100
      Ht = 50
      Stile = %SS_RIGHT
      idd = %Hours_tb: idd1 = %Hour_Spinner: l$ = "Hours": GoSub Draw_tb
      idd = %Minutes_tb: idd1 = %Minute_Spinner: l$ = "Mins": GoSub Draw_tb
      idd = %Seconds_tb: idd1 = %Second_Spinner: l$ = "Secs": GoSub Draw_tb
      '
      Row = Row + (ht *3) + 5
      col = 20 '+(wd / 2)
      spcr = 30 'wd
       idd = %Start_Timer_Btn: l$ = "&Start": Face_color = %Green: Text_Color = %Black: GoSub Draw_Btn
       idd = %Reset_Timer_Btn: l$ = "Reset": : Face_color = %Blue: Text_Color = %White: GoSub Draw_Btn
       idd = %Stop_Timer_Btn: l$ = "Stop": : Face_color = %Red: Text_Color = %White: GoSub Draw_Btn
    '
       ht = 25
       Wd = dlg_wd - 20
       Col = 10
       Row = Dlg_ht - Ht - 2 'Just off bottom
       idd = %Id_Exit_Btn: l$ = "Abandon Ship": : Face_color = %White: Text_Color = %Blue: GoSub Draw_Btn
    '
         Dialog Show Modal g_hdlg   Call Dialog_Processor
    Exit Function
    ''''''''''''''''''''''
    Draw_Tb:
      spcr = 24
      Control Add Label, g_hdlg, idd + 1, l$ & " ", Col, Row, Wd, Ht, %SS_CENTER
       Control Set Font g_hdlg, idd + 1, Comic(24)
      Control Add TextBox, g_hdlg, idd, "OO", Col, Row + ht + 2, Wd, Ht, stile
       Control Set Font g_hdlg, idd, Consolas(60)
       Control ReDraw g_hdlg, idd
        Control Add $updown_class, g_hdlg, idd1, "", Col + wd + 6, Row + ht + (ht / 2), 24, 48, %spinner_style
      Col = Col + Wd + spcr + 10 'just past label
    Return
    Draw_Btn:
      Control Add Button, g_hdlg, idd, l$, col, row, wd, ht
      Control Set Font g_hdlg, idd, Comic(14)
      #If %ButtonPlus_Loaded = 1
        z_Btn_Set_Face_Color(g_hdlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(g_hdlg, Idd, Text_Color)
      #EndIf
      col = Col + wd + spcr
    Return
    End Function  'Applikation befurschtunkenspielenden
    ==================================================
    Acquaintance, n.:
    A person whom we know well enough to borrow from,
    but not well enough to lend to.
    Ambrose Bierce (1842-1914)
    ==================================================
    Last edited by Gösta H. Lovgren-2; 20 Oct 2009, 08:25 AM.

    Leave a comment:


  • Mike Doty
    replied
    It does allow him to give the user the option of minimizing.
    DIALOG SHOW STATE ghDlg, %SW_SHOWNORMAL
    CONTROL SET FOCUS ghDlg, %Start_Timer_Btn

    Leave a comment:


  • Mike Doty
    replied
    His dialog will not come to the foreground using DIALOG SHOW STATE ghDlg, %SW_SHOWNORMAL

    Leave a comment:


  • Rodney Hicks
    replied
    What I would like to do is to force the Dialog to the top when the timer runs out but I dont know how to do that. I fooled with Dialog styles but no go.
    Did you happen to try DIALOG SHOW STATE?

    Leave a comment:


  • Mike Doty
    replied
    Changed a couple of things so code does not need to change
    to compile with or without butttonplus.bas

    Placed a couple of lines where your timer expires.
    One just sets focus to a button on your dialog and the
    other (remarked out) could be used to optionally use TOPMOST.

    Removed unused SLEEPER function and changed hdlg to ghDlg



    Code:
    'PBWIN 9.02 - Win32Api 10/2009 - XP Pro SP
    '1} force on top when time is done
    #DIM ALL
    #COMPILE EXE
    #OPTIMIZE SPEED
    '#Debug Display On'off for production code
    #INCLUDE "WIN32API.INC" '10/2009
    #INCLUDE "COMDLG32.INC" '08/2008
    #INCLUDE "InitCtrl.inc" '08/2008
    '
    %ButtonPlus_Loaded = 0 'Note set to 0 if you don't have ButtonPlus, rem  Include &
                           'lines within functions beginning with z_ (should be line numbers in the 70's)
                           ' if you still get errors
    #IF %ButtonPlus_Loaded
    #INCLUDE "C:\Only_My_Programs\Include Files\ButtonPlus.bas"
       %BP_TEXT_COLOR    = 1
       %BP_ICON_ID       = 2
       %BP_ICON_WIDTH    = 3
       %BP_ICON_HEIGHT   = 4
       %BP_ICON_POS      = 5
       %BP_FACE_COLOR    = 6
       %BP_FACE_BLEND    = 7
       %BP_SPOT_COLOR    = 8
       %BP_SPOT_BLEND    = 9
       %BP_SPOT_WIDTH    = 10
       %BP_SPOT_HEIGHT   = 11
       %BP_SPOT_POS      = 12
    ' #Else
    '   #Include "C:\Only_My_Programs\Include Files\ButtonPlus.bas"
    #ENDIF
    '
    %Id_Exit_Btn = 999
    %Hours_tb = 1000
    %Hour_Spinner = 1002
    %Minutes_tb = 1010
    %Minute_Spinner = 1012
    %Seconds_tb = 1020
    %Second_Spinner = 1022
    %Start_Timer_Btn = 1100
    %Stop_Timer_Btn  = 1110
    %Reset_Timer_Btn  = 1120
    %Graphic_Target = 1200
    '
    %Top = %MB_SYSTEMMODAL
    '
    %Btn_Color = &he75718
    %Neutral_Color = &hd8e9ec
    '
    $Title = SPACE$(20) & "Timer"
    '
    ' *******************************************************
    '
        'keep consistent style wherever used
    %spinner_style = %WS_CHILD OR _
                     %WS_VISIBLE 'Or _
                    ' 
    s_wrap Or _
                    ' 
    s_arrowkeys
    '
    ' *******************************************************
    '
      GLOBAL ghDlg AS DWORD
      GLOBAL Comic(), Consolas() AS DWORD
      GLOBAL g_Secs_to_go, Dlg_ht, Dlg_Wd AS LONG 'Global in case want to use in Controls
      GLOBAL pnmud AS nm_updown PTR     'pointer to structure used by spinner
      GLOBAL g_Title AS STRING * 50
      GLOBAL g_Start_Stop_Flag, g_Button_Plus1, g_Button_Plus2, g_Button_Plus3 AS LONG
    '
    ' *******************************************************
    '
    '
    #IF %ButtonPlus_Loaded = 1
    FUNCTION  z_Btn_Set_Face_Color(ddlg AS DWORD, dId AS LONG, Btn_Color AS LONG) AS LONG
       ButtonPlus  ddlg, dId, %BP_FACE_BLEND, 255 'true color
       ButtonPlus dDlg, dId, %BP_FACE_COLOR, Btn_Color ' &H008FDF8F
    END FUNCTION
    '
    FUNCTION z_Btn_Set_Text_Color(ddlg AS DWORD, ID AS LONG, Btn_Color AS LONG) AS LONG
       ButtonPlus dDlg, ID, %BP_Text_COLOR, Btn_Color ' &H008FDF8F
    END FUNCTION
    #ENDIF
    '
    MACRO Common_Locals 'Macro easier than retyping and maintains coding consistency
      LOCAL Stile, Row, col, ht, wd, Longest,ctr, ln, ln1, i AS LONG
      LOCAL text_Color, Face_color, tctl, spcr, idd, idd1 AS LONG
      LOCAL flag, n, hrs, secs, mins, tmr, tmr1, Secs_To_Run AS LONG
    '
      LOCAL  w, l, s AS STRING
    END MACRO
    '
    SUB Fonts_Setup
      common_locals
             DIM Comic(2 TO 72), Consolas(2 TO 72)
             FOR ctr = 2 TO 72
               FONT NEW "Comic Sans MS", ctr TO Comic(ctr)
               FONT NEW "Consolas", ctr TO Consolas(ctr)
             NEXT ctr
    END SUB
    '
    MACRO Show_Time = DIALOG SET TEXT ghDlg, USING$("##:##:##  #, ", hrs, mins, secs, Secs_To_Run)
    '
    MACRO Redraw_Textboxes
      n = g_Secs_to_go
      hrs = n \ 3600
        n = n - (Hrs * 60)
      Mins = (n  \ 60)
       Secs = n - (mins * 60)
      idd = %Hours_tb: CONTROL SET TEXT ghDlg, idd, RIGHT$(STR$(hrs), 2): CONTROL REDRAW  ghDlg, idd
      idd = %Minutes_tb: CONTROL SET TEXT ghDlg, idd, RIGHT$(STR$(mins), 2): CONTROL REDRAW  ghDlg, idd
      idd = %Seconds_tb: CONTROL SET TEXT ghDlg, idd, RIGHT$(STR$(Secs), 2): CONTROL REDRAW  ghDlg, idd
      'control set focus ghDlg, idd 'Attempt to keep dialog updating
    END MACRO
    '
    SUB Disable_Buttons
      common_locals
       idd = %Start_Timer_Btn: l$ = " ": Face_color = %Neutral_Color: Text_Color = %Neutral_Color: GOSUB Color_Btn
       idd = %Reset_Timer_Btn: l$ = " ": Face_color = %Neutral_Color:  Text_Color = %Neutral_Color: GOSUB Color_Btn
       idd = %Stop_Timer_Btn : l$ = "Stop ": Face_color = %RED: Text_Color = %WHITE: GOSUB Color_Btn
       idd = %Id_Exit_Btn: l$ = "Press Any Key to Stop": Face_color = %WHITE: Text_Color = %BLACK: GOSUB Color_Btn
      CONTROL ENABLE ghDlg, %Stop_Timer_Btn
     EXIT SUB
    '
    Color_Btn:
      CONTROL DISABLE ghDlg, idd
      CONTROL SET TEXT ghDlg, idd, l$
      #IF %ButtonPlus_Loaded = 1
        z_Btn_Set_Face_Color(ghDlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(ghDlg, Idd, Text_Color)
      #ENDIF
      CONTROL REDRAW ghDlg, idd
    RETURN
    END SUB
    '
    '
    SUB Enable_Buttons
      common_locals
       idd = %Start_Timer_Btn: l$ = "&Start": Face_color = %GREEN: Text_Color = %BLACK: GOSUB Color_Btn
       idd = %Reset_Timer_Btn: l$ = "&Reset": Face_color = %BLUE:  Text_Color = %WHITE: GOSUB Color_Btn
       idd = %Stop_Timer_Btn : l$ = "Unknown": Face_color = %Neutral_Color: Text_Color = %Neutral_Color: GOSUB Color_Btn
       idd = %Id_Exit_Btn: l$ = "Abandon Ship": Face_color = %WHITE : Text_Color = %BLACK: GOSUB Color_Btn
      CONTROL DISABLE ghDlg, %Stop_Timer_Btn
     EXIT SUB
    '
    Color_Btn:
      CONTROL ENABLE ghDlg, idd
      CONTROL SET TEXT ghDlg, idd, l$
      #IF %ButtonPlus_Loaded = 1
        z_Btn_Set_Face_Color(ghDlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(ghDlg, Idd, Text_Color)
      #ENDIF
      CONTROL REDRAW ghDlg, idd
    RETURN
    END SUB
    '
    ' *******************************************************
    '
    FUNCTION WorkerThread(BYVAL x AS LONG) AS LONG
      FUNCTION = Timer_Start()
    END FUNCTION
    '
    ' *******************************************************
    '
    '
    FUNCTION Time_Left AS LONG
      common_Locals
      idd = %Hours_tb: CONTROL GET TEXT ghDlg, idd TO s$
       hrs = VAL(s$)
       Secs_To_Run = hrs * 60 * 60
      idd = %Minutes_tb: CONTROL GET TEXT ghDlg, idd TO s$
       mins = VAL(s$)
       Secs_To_Run = Secs_To_Run + (mins * 60)
      idd = %Seconds_tb: CONTROL GET TEXT ghDlg, idd TO s$
       secs = VAL(s$)
       Secs_To_Run = Secs_To_Run + secs
       FUNCTION = Secs_To_Run
    END FUNCTION
    '
    FUNCTION Timer_Start() AS LONG
      common_locals
      LOCAL hwin AS DWORD
      LOCAL Time_to_Elapse AS LONG
      g_Secs_to_go = Time_Left 'calculates from textboxes
      IF g_Secs_to_go = < 0 THEN
         ? "Timer not set yet", %Top, TRIM$($Title)
         EXIT FUNCTION
      END IF
    '
      Time_to_Elapse = TIMER + g_Secs_to_go
      GRAPHIC WINDOW "", 1, 1, 1,  1 TO hWin 'set dummy graphic window
      GRAPHIC ATTACH hwin, 0
      CSET g_Title$ = "Timer At Work": DIALOG SET TEXT ghDlg, g_Title$
      Disable_Buttons
      flag = 0
    '
    'start loop *********************
      DO
       IF g_Start_Stop_Flag = 1 THEN EXIT LOOP 'sent from Stop button
    '
         g_Secs_to_go = Time_to_Elapse - TIMER
       '  Show_Time 'dialog header
       '  Graphic instat To n '<<< doesn't work?
         GRAPHIC INKEY$ TO w$
         n = LEN(w$)
         SELECT CASE n
           CASE 0
           '
           CASE 1 'key pressed
               CSET g_Title$ = "Timer Stopped by key": DIALOG SET TEXT ghDlg, g_Title$
               Flag = 1
              EXIT LOOP 'GoTo TRExit 'Exit Loop
           CASE 2 'extended key pressed  '<<< Never gets hit
             ?"extended"
             EXIT LOOP
         END SELECT
    '
       IF TIMER => tmr + 1 THEN 'only once a second
          Redraw_Textboxes  'redraw tb's
          IF g_Secs_to_go  < 11 THEN winbeep 100, 10 'only last 10 seconds
          tmr = TIMER
       END IF
      LOOP WHILE g_Secs_to_go > 0
    'end loop '***********************
    '
    trexit:
      GRAPHIC DETACH
      Redraw_Textboxes  'redraw tb's
      IF flag + g_Start_Stop_Flag = 0 THEN 'else no alarm
         FOR ctr = 1 TO 10
            winbeep 2000, 1
            SLEEP 100
         NEXT ctr
         ? "Timer expired", %Top, $title
         'SetWindowPos ghDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE
     
         
         DIALOG SHOW STATE ghDlg, %SW_SHOWNORMAL   'restore if minimized after seeing Rodney Hicks post
         CONTROL SET FOCUS ghDlg, %Start_Timer_Btn      'brings to foreground
     
     
      END IF
      Enable_Buttons
    END FUNCTION
    '
    '
    CALLBACK FUNCTION Dialog_Processor
      Common_Locals
      LOCAL h_thread, dwres AS DWORD
      '
      SELECT CASE CBMSG     'This is TO determine the message TYPE
         '
         CASE %WM_INITDIALOG'<- Initialiaton when the program loads
           Enable_Buttons
         '
         CASE %WM_SYSCOMMAND 'Traps Any Alt key but only F4 closes
    '
         CASE %WM_NOTIFY: 'Spinner_Macro   'for spinners
            pnmud = CB.LPARAM
              IF @pnmud.hdr.Code = 
    n_deltapos THEN  '+1 or -1
                 ctr =  @pnmud.idelta * -1 'change sign to match arrows
             END IF
             tctl = CB.CTL - 2 ' -2 to match to textboxes id's
             SELECT CASE CB.CTL
               CASE %Hour_Spinner   '
                 CONTROL GET TEXT ghDlg, tctl TO s$
                   ctr = VAL(s$) + ctr
                   IF ctr > 24 THEN ctr = 0
                   IF ctr < 0 THEN ctr = 24
                  CONTROL SET TEXT ghDlg, CB.CTL - 2,  RIGHT$(STR$(ctr), 2)
               '
               CASE %Minute_Spinner, %Second_Spinner
                 CONTROL GET TEXT ghDlg, tCtl TO s$
                   ctr = VAL(s$) + ctr
                   IF ctr > 60 THEN ctr = 0
                   IF ctr < 0 THEN ctr = 60
                  CONTROL SET TEXT ghDlg, CB.CTL - 2,  RIGHT$(STR$(ctr), 2)
             END SELECT
         '
         CASE %WM_COMMAND  'This processes command messages
           SELECT CASE CBCTL
             CASE %Id_Exit_Btn
               SELECT CASE CBCTLMSG
                  CASE 0
                    DIALOG END CBHNDL 'Applikation beenden
               END SELECT
         '
         CASE %Start_Timer_Btn
            g_Start_Stop_Flag = 0
            THREAD CREATE WorkerThread(0)  TO h_Thread
            THREAD CLOSE h_thread TO dwres
             CSET g_Title$ = "Time Elapsed": DIALOG SET TEXT ghDlg, g_Title$
         '
         CASE %Stop_Timer_Btn
            g_Start_Stop_Flag = 1
            Timer_start
             CSET g_Title$ = "Timer Stopped": DIALOG SET TEXT ghDlg, g_Title$
    '        WorkerThread(1)
         '
         CASE %Reset_Timer_Btn
            idd = %Hours_tb: CONTROL SET TEXT ghDlg, idd, "0"
            idd = %Minutes_tb: CONTROL SET TEXT ghDlg, idd, "0"
            idd = %Seconds_tb: CONTROL SET TEXT ghDlg, idd, "0"
            DIALOG SET TEXT ghDlg, $Title
         '
           END SELECT
      END SELECT
    END FUNCTION
    FUNCTION PBMAIN
      Common_Locals
      Fonts_Setup
       Stile = Stile OR %WS_CAPTION
       Stile = Stile OR %WS_SYSMENU
       Stile = Stile OR %WS_THICKFRAME
       Stile = Stile OR %WM_HELP
       Stile = Stile OR %WS_BORDER  'doesn't do anything
      Dlg_ht = 250
      Dlg_Wd = 415
    '  Dialog Font "Consolas", 60 ' Big Unicodes
      DIALOG NEW PIXELS, ghDlg, $Title, , , Dlg_Wd, Dlg_Ht, Stile TO ghDlg 'centered
      Row = 10
      col = 10
      Wd = 100
      Ht = 50
      Stile = %SS_RIGHT
      idd = %Hours_tb: idd1 = %Hour_Spinner: l$ = "Hours": GOSUB Draw_tb
      idd = %Minutes_tb: idd1 = %Minute_Spinner: l$ = "Mins": GOSUB Draw_tb
      idd = %Seconds_tb: idd1 = %Second_Spinner: l$ = "Secs": GOSUB Draw_tb
      '
      Row = Row + (ht *3) + 5
      col = 20 '+(wd / 2)
      spcr = 30 'wd
       idd = %Start_Timer_Btn: l$ = "&Start": Face_color = %GREEN: Text_Color = %BLACK: GOSUB Draw_Btn
       idd = %Reset_Timer_Btn: l$ = "Reset": : Face_color = %BLUE: Text_Color = %WHITE: GOSUB Draw_Btn
       idd = %Stop_Timer_Btn: l$ = "Stop": : Face_color = %RED: Text_Color = %WHITE: GOSUB Draw_Btn
    '
       ht = 25
       Wd = dlg_wd - 20
       Col = 10
       Row = Dlg_ht - Ht - 2 'Just off bottom
       idd = %Id_Exit_Btn: l$ = "Abandon Ship": : Face_color = %WHITE: Text_Color = %BLUE: GOSUB Draw_Btn
    '
         DIALOG SHOW MODAL ghDlg   CALL Dialog_Processor
    EXIT FUNCTION
    ''''''''''''''''''''''
    Draw_Tb:
      spcr = 24
      CONTROL ADD LABEL, ghDlg, idd + 1, l$ & " ", Col, Row, Wd, Ht, %SS_CENTER
       CONTROL SET FONT ghDlg, idd + 1, Comic(24)
      CONTROL ADD TEXTBOX, ghDlg, idd, "OO", Col, Row + ht + 2, Wd, Ht, stile
       CONTROL SET FONT ghDlg, idd, Consolas(60)
       CONTROL REDRAW ghDlg, idd
        CONTROL ADD $updown_class, ghDlg, idd1, "", Col + wd + 6, Row + ht + (ht / 2), 24, 48, %spinner_style
      Col = Col + Wd + spcr + 10 'just past label
    RETURN
    Draw_Btn:
      CONTROL ADD BUTTON, ghDlg, idd, l$, col, row, wd, ht
      CONTROL SET FONT ghDlg, idd, Comic(14)
      #IF %ButtonPlus_Loaded = 1
        z_Btn_Set_Face_Color(ghDlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(ghDlg, Idd, Text_Color)
      #ENDIF
      col = Col + wd + spcr
    RETURN
    END FUNCTION  'Applikation befurschtunkenspielenden
    Last edited by Mike Doty; 20 Oct 2009, 02:28 AM.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Back in business. Dell replaced motherboard and co-processor. Replaced graphic board on first visit (last Wed). I bet there was nothing wrong with it but tech just left new one in in there after he tried rebooting. Oh well, on Dell, not me. {shrug).

    Okay, tried Threads in program and now it updates every second, like it's supposed to. Found an excellent Thread example here: 'http://www.powerbasic.com/support/pbforums/showthread.php?t=24991&highlight=thread

    Buuuutttttt ... it still acts funny. Dunno if it's my system (XPS inherent) or not. It creates an additional instance after it's been running about 5 seconds. And if it's stopped/restarted before time runs out, it creates additional instances as well. Really peculiar. Otherwise is pretty neat.

    What I would like to do is to force the Dialog to the top when the timer runs out but I dont know how to do that. I fooled with Dialog styles but no go.


    '
    Code:
    'PBWIN 9.02 - Win32Api 10/2009 - XP Pro SP
    '1} force on top when time is done
    #Dim All 
    #Compile Exe  
    #Optimize SPEED
    '#Debug Display On'off for production code
     
    #Include "WIN32API.INC" '10/2009
    #Include "COMDLG32.INC" '08/2008
    #Include "InitCtrl.inc" '08/2008
    '
    %ButtonPlus_Loaded = 1 'Note set to 0 if you don't have ButtonPlus, rem  Include &
                           'lines within functions beginning with z_ (should be line numbers in the 70's)
                           ' if you still get errors
       #Include "C:\Only_My_Programs\Include Files\ButtonPlus.bas"      
    #If Not %ButtonPlus_Loaded    
       %BP_TEXT_COLOR    = 1
       %BP_ICON_ID       = 2
       %BP_ICON_WIDTH    = 3
       %BP_ICON_HEIGHT   = 4
       %BP_ICON_POS      = 5
       %BP_FACE_COLOR    = 6
       %BP_FACE_BLEND    = 7
       %BP_SPOT_COLOR    = 8
       %BP_SPOT_BLEND    = 9
       %BP_SPOT_WIDTH    = 10
       %BP_SPOT_HEIGHT   = 11
       %BP_SPOT_POS      = 12     
    ' #Else 
    '   #Include "C:\Only_My_Programs\Include Files\ButtonPlus.bas"      
    #EndIf  
    '
    %Id_Exit_Btn = 999
    %Hours_tb = 1000
    %Hour_Spinner = 1002
    %Minutes_tb = 1010
    %Minute_Spinner = 1012
    %Seconds_tb = 1020
    %Second_Spinner = 1022
    %Start_Timer_Btn = 1100
    %Stop_Timer_Btn  = 1110
    %Reset_Timer_Btn  = 1120
    %Graphic_Target = 1200
    '
    %Top = %MB_SYSTEMMODAL
    '
    %Btn_Color = &he75718
    %Neutral_Color = &hd8e9ec
    '
    $Title = Space$(20) & "Timer"
    '
    ' *******************************************************
    '
        'keep consistent style wherever used
    %spinner_style = %ws_child Or _  
                     %ws_visible 'Or _
                    ' %uds_wrap Or _
                    ' %uds_arrowkeys 
    '
    ' *******************************************************
    '
      Global hdlg As Dword                
      Global Comic(), Consolas() As Dword
      Global g_Secs_to_go, Dlg_ht, Dlg_Wd As Long 'Global in case want to use in Controls
      Global pnmud As nm_updown Ptr     'pointer to structure used by spinner     
      Global g_Title As String * 50
      Global g_Start_Stop_Flag, g_Button_Plus1, g_Button_Plus2, g_Button_Plus3 As Long 
    '
    ' *******************************************************
    '
    '  
    Function  z_Btn_Set_Face_Color(ddlg As Dword, dId As Long, Btn_Color As Long) As Long
       ButtonPlus  ddlg, dId, %BP_FACE_BLEND, 255 'true color
       ButtonPlus dDlg, dId, %BP_FACE_COLOR, Btn_Color ' &H008FDF8F 
    End Function 
    '
    Function z_Btn_Set_Text_Color(ddlg As Dword, Id As Long, Btn_Color As Long) As Long
       ButtonPlus dDlg, Id, %BP_Text_COLOR, Btn_Color ' &H008FDF8F 
    End Function 
    ' 
    Macro Common_Locals 'Macro easier than retyping and maintains coding consistency
      Local Stile, Row, col, ht, wd, Longest,ctr, ln, ln1, i As Long
      Local text_Color, Face_color, tctl, spcr, idd, idd1 As Long
      Local flag, n, hrs, secs, mins, tmr, tmr1, Secs_To_Run As Long
    '
      Local  w, l, s As String
    End Macro  
    '
    Sub Fonts_Setup
      common_locals
             Dim Comic(2 To 72), Consolas(2 To 72)
             For ctr = 2 To 72
               Font New "Comic Sans MS", ctr To Comic(ctr)
               Font New "Consolas", ctr To Consolas(ctr)
             Next ctr  
    End Sub
    ' 
    Macro Show_Time = Dialog Set Text hdlg, Using$("##:##:##  #, ", hrs, mins, secs, Secs_To_Run)
    ' 
    Macro Redraw_Textboxes
      n = g_Secs_to_go
      hrs = n \ 3600        
        n = n - (Hrs * 60)
      Mins = (n  \ 60)
       Secs = n - (mins * 60)
      idd = %Hours_tb: Control Set Text hdlg, idd, Right$(Str$(hrs), 2): Control ReDraw  hdlg, idd
      idd = %Minutes_tb: Control Set Text hdlg, idd, Right$(Str$(mins), 2): Control ReDraw  hdlg, idd
      idd = %Seconds_tb: Control Set Text hdlg, idd, Right$(Str$(Secs), 2): Control ReDraw  hdlg, idd
      'control set focus hdlg, idd 'Attempt to keep dialog updating
    End Macro
    '                
    Sub Disable_Buttons
      common_locals
       idd = %Start_Timer_Btn: l$ = " ": Face_color = %Neutral_Color: Text_Color = %Neutral_Color: GoSub Color_Btn
       idd = %Reset_Timer_Btn: l$ = " ": Face_color = %Neutral_Color:  Text_Color = %Neutral_Color: GoSub Color_Btn
       idd = %Stop_Timer_Btn : l$ = "Stop ": Face_color = %Red: Text_Color = %White: GoSub Color_Btn 
       idd = %Id_Exit_Btn: l$ = "Press Any Key to Stop": Face_color = %White: Text_Color = %Black: GoSub Color_Btn 
      Control Enable hdlg, %Stop_Timer_Btn
     Exit Sub
    '
    Color_Btn:
      Control Disable hdlg, idd
      Control Set Text hdlg, idd, l$
      If %ButtonPlus_Loaded = 1 Then              
        z_Btn_Set_Face_Color(hdlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(hdlg, Idd, Text_Color)
      End If
      Control ReDraw hdlg, idd
    Return 
    End Sub       
    '              
    '  
    Sub Enable_Buttons          
      common_locals   
       idd = %Start_Timer_Btn: l$ = "&Start": Face_color = %Green: Text_Color = %Black: GoSub Color_Btn
       idd = %Reset_Timer_Btn: l$ = "&Reset": Face_color = %Blue:  Text_Color = %White: GoSub Color_Btn
       idd = %Stop_Timer_Btn : l$ = " ": Face_color = %Neutral_Color: Text_Color = %Neutral_Color: GoSub Color_Btn 
       idd = %Id_Exit_Btn: l$ = "Abandon Ship": Face_color = %White : Text_Color = %Black: GoSub Color_Btn 
      Control Disable hdlg, %Stop_Timer_Btn
     Exit Sub
    ' 
    Color_Btn:
      Control Enable hdlg, idd
      Control Set Text hdlg, idd, l$
      If %ButtonPlus_Loaded = 1 Then              
        z_Btn_Set_Face_Color(hdlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(hdlg, Idd, Text_Color)
      End If
      Control ReDraw hdlg, idd
    Return 
    End Sub       
    '
    ' *******************************************************
    '
    Function WorkerThread(ByVal x As Long) As Long
      Function = Timer_Start()
    End Function
    '
    ' *******************************************************
    '
    '
    Function Time_Left As Long
      common_Locals
      idd = %Hours_tb: Control Get Text hdlg, idd To s$
       hrs = Val(s$)
       Secs_To_Run = hrs * 60 * 60
      idd = %Minutes_tb: Control Get Text hdlg, idd To s$
       mins = Val(s$)
       Secs_To_Run = Secs_To_Run + (mins * 60)
      idd = %Seconds_tb: Control Get Text hdlg, idd To s$
       secs = Val(s$)
       Secs_To_Run = Secs_To_Run + secs
       Function = Secs_To_Run
    End Function               
    '
    Function Timer_Start() As Long
      common_locals                                                
      Local hwin As Dword
      Local Time_to_Elapse As Long
      g_Secs_to_go = Time_Left 'calculates from textboxes
      If g_Secs_to_go = < 0 Then
         ? "Timer not set yet", %Top, Trim$($Title)
         Exit Function
      End If                       
    '  
      Time_to_Elapse = Timer + g_Secs_to_go 
      Graphic Window "", 1, 1, 1,  1 To hWin 'set dummy graphic window
      Graphic Attach hwin, 0 
      CSet g_Title$ = "Timer At Work": Dialog Set Text hdlg, g_Title$
      Disable_Buttons
      flag = 0
    '
    'start loop *********************
      Do
       If g_Start_Stop_Flag = 1 Then Exit Loop 'sent from Stop button
    '
         g_Secs_to_go = Time_to_Elapse - Timer
       '  Show_Time 'dialog header
       '  Graphic instat To n '<<< doesn't work?
         Graphic inkey$ To w$
         n = Len(w$)
         Select Case n
           Case 0  
           '
           Case 1 'key pressed  
               CSet g_Title$ = "Timer Stopped by key": Dialog Set Text hdlg, g_Title$
               Flag = 1
              Exit Loop 'GoTo TRExit 'Exit Loop
           Case 2 'extended key pressed  '<<< Never gets hit
             ?"extended"
             Exit Loop
         End Select
    ' 
       If Timer => tmr + 1 Then 'only once a second
          Redraw_Textboxes  'redraw tb's          
          If g_Secs_to_go  < 11 Then winbeep 100, 10 'only last 10 seconds
          tmr = Timer
       End If 
      Loop While g_Secs_to_go > 0 
    'end loop '*********************** 
    '
    trexit:
      Graphic Detach
      Redraw_Textboxes  'redraw tb's          
      If flag + g_Start_Stop_Flag = 0 Then 'else no alarm
         For ctr = 1 To 10
            winbeep 2000, 1             
            Sleep 100
         Next ctr        
         ? "Timer expired", %Top, $title
      End If       
      Enable_Buttons
    End Function     
    '
    '
    CallBack Function Dialog_Processor              
      Common_Locals                                           
      Local h_thread, dwres As Dword
      '
      Select Case CbMsg     'This is TO determine the message TYPE 
         '       
         Case %WM_INITDIALOG'<- Initialiaton when the program loads 
           Enable_Buttons
         '
         Case %WM_SYSCOMMAND 'Traps Any Alt key but only F4 closes              
    '
         Case %wm_notify: 'Spinner_Macro   'for spinners
            pnmud = CB.lParam          
              If @pnmud.hdr.Code = %udn_deltapos Then  '+1 or -1 
                 ctr =  @pnmud.idelta * -1 'change sign to match arrows
             End If
             tctl = CB.Ctl - 2 ' -2 to match to textboxes id's
             Select Case CB.Ctl 
               Case %Hour_Spinner   '
                 Control Get Text hdlg, tctl To s$
                   ctr = Val(s$) + ctr                
                   If ctr > 24 Then ctr = 0
                   If ctr < 0 Then ctr = 24
                  Control Set Text hdlg, CB.Ctl - 2,  Right$(Str$(ctr), 2)
               '
               Case %Minute_Spinner, %Second_Spinner
                 Control Get Text hdlg, tCtl To s$
                   ctr = Val(s$) + ctr                
                   If ctr > 60 Then ctr = 0
                   If ctr < 0 Then ctr = 60
                  Control Set Text hdlg, CB.Ctl - 2,  Right$(Str$(ctr), 2)
             End Select
         '
         Case %WM_COMMAND  'This processes command messages
           Select Case CbCtl
             Case %Id_Exit_Btn
               Select Case CbCtlMsg        
                  Case 0
                    Dialog End CbHndl 'Applikation beenden
               End Select
         '
         Case %Start_Timer_Btn
            g_Start_Stop_Flag = 0
            Thread Create WorkerThread(0)  To h_Thread
            Thread Close h_thread To dwres
             CSet g_Title$ = "Time Elapsed": Dialog Set Text hdlg, g_Title$
         '
         Case %Stop_Timer_Btn  
            g_Start_Stop_Flag = 1
            Timer_start
             CSet g_Title$ = "Timer Stopped": Dialog Set Text hdlg, g_Title$
    '        WorkerThread(1)
         '
         Case %Reset_Timer_Btn 
            idd = %Hours_tb: Control Set Text hdlg, idd, "0"
            idd = %Minutes_tb: Control Set Text hdlg, idd, "0"
            idd = %Seconds_tb: Control Set Text hdlg, idd, "0"
            Dialog Set Text hdlg, $Title
         '
           End Select
      End Select
    End Function
    '
    '
    '
    ' *******************************************************
    '
     'http://www.powerbasic.com/support/pbforums/showthread.php?t=40472
     'Mike Doty
    Function Sleeper(milliseconds As Dword) As Long
       Local hThread As Dword
       If Len(Command$) Then                'override passed value
         milliseconds = Abs(Val(Command$))  'use value in COMMAND$
       End If
      Thread Create TimedMessageBoxThread(milliseconds) To hThread
       Sleep 50
      WaitForSingleObject hThread, milliseconds
      Thread Close hThread To hThread
    End Function
    '
    Thread Function TimedMessageBoxThread(ByVal milliseconds As Dword) As Long
     #If %Def(%Pb_Cc32)
      ? "Press ENTER to continue or WAIT" + Using$(".# Seconds", milliseconds / 1000) 
      WAITKEY$
     #Else             
     #EndIf
    End Function    
    '
    ' *******************************************************
    '
    '
    ' *******************************************************
    '
    Function PBMain
      Common_Locals
      Fonts_Setup
       Stile = Stile Or %WS_CAPTION
       Stile = Stile Or %WS_SYSMENU
       Stile = Stile Or %WS_THICKFRAME 
       Stile = Stile Or %WM_HELP 
       Stile = Stile Or %WS_Border  'doesn't do anything
      Dlg_ht = 250
      Dlg_Wd = 415
    '  Dialog Font "Consolas", 60 ' Big Unicodes
      Dialog New Pixels, hdlg, $Title, , , Dlg_Wd, Dlg_Ht, Stile To hdlg 'centered
      Row = 10
      col = 10
      Wd = 100
      Ht = 50                                       
      Stile = %SS_Right
      idd = %Hours_tb: idd1 = %Hour_Spinner: l$ = "Hours": GoSub Draw_tb
      idd = %Minutes_tb: idd1 = %Minute_Spinner: l$ = "Mins": GoSub Draw_tb
      idd = %Seconds_tb: idd1 = %Second_Spinner: l$ = "Secs": GoSub Draw_tb
      ' 
      Row = Row + (ht *3) + 5
      col = 20 '+(wd / 2)     
      spcr = 30 'wd
       idd = %Start_Timer_Btn: l$ = "&Start": Face_color = %Green: Text_Color = %Black: GoSub Draw_Btn 
       idd = %Reset_Timer_Btn: l$ = "Reset": : Face_color = %Blue: Text_Color = %White: GoSub Draw_Btn 
       idd = %Stop_Timer_Btn: l$ = "Stop": : Face_color = %Red: Text_Color = %White: GoSub Draw_Btn 
    '
       ht = 25   
       Wd = dlg_wd - 20
       Col = 10 
       Row = Dlg_ht - Ht - 2 'Just off bottom
       idd = %Id_Exit_Btn: l$ = "Abandon Ship": : Face_color = %White: Text_Color = %Blue: GoSub Draw_Btn 
    '
         Dialog Show Modal hDlg   Call Dialog_Processor
    Exit Function
    ''''''''''''''''''''''
    Draw_Tb:
      spcr = 24
      Control Add Label, hdlg, idd + 1, l$ & " ", Col, Row, Wd, Ht, %ss_center
       Control Set Font hdlg, idd + 1, Comic(24) 
      Control Add TextBox, hdlg, idd, "OO", Col, Row + ht + 2, Wd, Ht, stile
       Control Set Font hdlg, idd, Consolas(60)
       Control ReDraw hdlg, idd
        Control Add $updown_class, Hdlg, idd1, "", Col + wd + 6, Row + ht + (ht / 2), 24, 48, %spinner_style
      Col = Col + Wd + spcr + 10 'just past label 
    Return     
    Draw_Btn:  
      Control Add Button, hdlg, idd, l$, col, row, wd, ht
      Control Set Font hdlg, idd, Comic(14)
      If %ButtonPlus_Loaded = 1 Then              
        z_Btn_Set_Face_Color(hdlg, Idd, Face_Color)
        z_Btn_Set_Text_Color(hdlg, Idd, Text_Color)
      End If
      col = Col + wd + spcr    
    Return  
    End Function  'Applikation befurschtunkenspielenden
    '
    ' *******************************************************
    '
    '
    And to see it in Homey's In Living Color: http://www.swedesdock.com/powerbasic/Digital_Timer.exe

    =========================================
    Never let the future disturb you.
    You will meet it, if you have to,
    with the same weapons of reason
    which today arm you against the present.
    Marcus Aurelius Antoninus (121-180 A.D.)
    =========================================

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Rodney Hicks View Post
    I ran your timer in my portrait goodie, and the two bmp are as it starts(1) and after clicking reset(2) I have no idea if the third button is supposed to have text or not.
    That *looks* right Rod. Still on Mom's computer. the 3rd button is supposed to be a STOP when clock is running, but I haven't gotten that far yet. Still on Mom's computer so it'll be a couple days.

    Did you notice if it created a second instance when running down (has to be set to run for more than 10 seconds to see.)? The timer runs out (rings the bell) but does not enable (or redraw) the buttons.

    Thanks for looking. I'll get back to it when computer gets reenergized (hopefully tomorrow).

    Leave a comment:


  • Rodney Hicks
    replied
    I ran your timer in my portrait goodie, and the two bmp are as it starts(1) and after clicking reset(2) I have no idea if the third button is supposed to have text or not.
    Attached Files

    Leave a comment:


  • Jeff Blakeney
    replied
    I haven't tried you timer program but as to the font and text box sizes, I know with my current monitor and resolution the pixels aren't quite square. The aspect ratio of my resolution is 1280 / 1024 or 1.25 but the aspect ratio of my 19" monitor is approximately 14.5 / 11 or 1.32. I get 1280 / 14.5 or 88.276 pixels per inch horizontally and 1024 / 11 = 93.091 pixels per inch vertically so my pixels are actually wider than they are tall. If I were to turn my monitor on its side, then my pixels would be taller than they are wide so things would look different.

    These values all depend on your resolution and monitor's viewing area but not many people adjust their systems to have square pixels.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Tech won't be able to get here until Monday. I only can hope he has the right part then.{sigh}. So stuck using Mom's machine. Has anyone run the Digital Timer (http://www.swedesdock.com/powerbasic/Digital_Timer.exe) to see if the same behavior occurs (launches another instance, etc.)? One thing I noticed is the font is way too big on a landscape monitor but is perfect on a portrait. Either the font size changes depending on video setup or the Textboxe sizes do. The textboxes only look to be half high enough. I wonder why that is.

    Leave a comment:


  • Rodney Hicks
    replied
    Gösta
    You have my deepest sympathy!!

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Mmmm... Back on Topic ... Couple days ago while working the Digital Timer, my computer froze up solid. Died dead. Wouldn't boot up. Called Dell (XPS 710, couple years old). Have maintenance contract so went over whole troubleshooting deal with tech over phone.

    He determined it was the video card. Not so, I thought, didn't act like video at all but he said it was. "Trust him". Okay. The next day (yesteday)at noon, there was a tech at the door wih a new video card.

    The tech chgd card and of course it didn't make any dif. He said according to the lights (there at least 5 diagnostic lights on on the front), it was most likely the motherboard or the coprocessor. Which makes more sense (to me) as the program was accessing the timer frequently in the program (only updating the screen once a second but checking the timer for elapsed time 100's, 1,000's per second).

    At any rate am still waiting for new whatever. Probably not until tomorrow. In the meantime, am on wife's computer with archaic landscape monitor (Hi Rodney {grin}).

    My point is the program was acting strangely and that may have been due to faulty motherboard or co-proc. (Just ran exe (http://www.swedesdock.com/powerbasic/Digital_Timer.exe) but it still acted the same (went into bg after 4-5 secs and doesn't update main screen after alarm fininshes.) so i guess it's not my computer after all.

    GHL

    Leave a comment:


  • Mike Doty
    replied
    Is there another kind of timer that works when called from our process?
    I assume (ouch) everyone elses timers are not effected by our timer.
    http://msdn.microsoft.com/en-us/libr...07(VS.85).aspx
    There seems to be another call for everything in the api.
    And another:
    http://msdn.microsoft.com/en-us/libr...92(VS.85).aspx
    Not to mention timer queues
    http://msdn.microsoft.com/en-us/libr...03(VS.85).aspx
    Last edited by Mike Doty; 13 Oct 2009, 05:37 PM.

    Leave a comment:


  • Michael Mattias
    replied
    I don't assume everybody knows this. I assume you do.

    I also assume anyone who ever TRIED 'TCP OPEN' tried it with an invalid address just to see what would happen. This may be a bad assumption, but it's how I try everything, with both 'good' values and 'bad' values.

    MCM

    Leave a comment:


  • Mike Doty
    replied
    Why would you assume everyone knows this?

    Leave a comment:

Working...
X