• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Example Timer program

Started by Chris Chancellor, November 10, 2018, 06:09:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

Hello All

Thanxx to Charles, Roland and Jose.
here is the Timer program example which displays the current date and time

the attached zip file contains everything you need to compile and run it


' Timer_example.o2bas
'  Uses the latest Dialogs.inc file from
'  https://www.oxygenbasic.org/forum/index.php?topic=1525.30
'  message #37    Thanxx to Roland

$ filename = "Timer_example_Mod.exe"
uses rtl64


              uses dialogs
              uses O2Common

SYSTEMTIME   myTime

'   Equates
% IDC_LABEL1       = 201
% IDC_LABEL2       = 202

'  Handle for the Main Dialog
// sys hDlg



'===========================
'  Call back function
FUNCTION Dlg_CB(sys hDlg,uint uMsg, sys wParam, lParam)  as sys CALLBACK

     string  TimeStr , DateStr
    sys hLabText1=GetDlgItem(hDlg, IDC_LABEL1)
    sys hLabText2=GetDlgItem(hDlg, IDC_LABEL2)
   
    sys hDC

   SELECT CASE uMsg
      CASE WM_INITDIALOG
        ' set the timer for 1 seconds timing
          SetTimer hDlg, 1, 1000,  NULL
               GetLocalTime   myTime
                DateStr  =  " Current Date  " + mytime.wDay + "-" + mytime.wMonth+ "-" + mytime.wYear
                SetWindowText (hLabText1, DateStr)
               TimeStr =  " Current time " + mytime.wHour + ":" + mytime.wMinute + ":" + mytime.wSecond 
               SetWindowText (hLabText2, TimeStr)


      CASE WM_TIMER
           '    when time changes (every 1 secs)
                GetLocalTime   myTime
                 DateStr  =  " Current Date :   " + mytime.wDay + "-" + mytime.wMonth+ "-" + mytime.wYear
                SetWindowText (hLabText1, DateStr)
                TimeStr =  " Current time :  " + mytime.wHour + ":" + mytime.wMinute + ":" + mytime.wSecond 
                SetWindowText (hLabText2, TimeStr)

' added to display background color for the main window
     CASE %WM_ERASEBKGND     
          hDC = wParam
  '       Pass the DC of the region to repaint
          DrawGradient hDC           
          FUNCTION = 1
          EXIT FUNCTION



        CASE WM_COMMAND
                   select case loword(wParam)
                              case IDCANCEL
                                    SendMessage(hDlg, WM_CLOSE,0,0)
                       end select


      CASE WM_Close
                 DestroyWindow( hDlg )


      CASE WM_DESTROY
            KillTimer hDlg, 1
            PostQuitMessage 0

   END SELECT
END FUNCTION



'===========================
FUNCTION O2MAIN() as sys
       
       MSG wMsg
       sys hDlg
    ' for light yellow background for main window
      MainWindBGColor = 1

       Dialog( 10,10,100,60, "Timer Display ",
                                    WS_CAPTION OR WS_SYSMENU or DS_CENTER or WS_VISIBLE,
                                    8,"Arial" )

       LText( "", IDC_LABEL1, 10, 20, 85, 10)
       LText( "", IDC_LABEL2, 10, 40, 85, 10)
       hDlg = CreateModelessDialog( null, @Dlg_CB, 0 )
         
     
       while GetMessage( @wMsg, null, 0, 0 ) <> 0
           if IsDialogMessage( hDlg,  @wMsg ) = 0 then
             TranslateMessage( @wMsg )
             DispatchMessage( @wMsg )
           end if
      wend

END FUNCTION     


     
'-------------------------------------
'  Start of program
  O2Main