From: <dd...@us...> - 2003-06-12 22:17:54
|
Update of /cvsroot/babylonlib/_SrcPool/Cpp/Samples/Timer In directory sc8-pr-cvs1:/tmp/cvs-serv11218/Cpp/Samples/Timer Added Files: resource.h StdAfx.cpp StdAfx.h Timer.cpp Timer.dsp Timer.dsw Timer.h Timer.rc TimerDlg.cpp TimerDlg.h TimerProc.cpp Log Message: Win resizble dlg. sample --- NEW FILE: resource.h --- //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by Timer.rc // #define ID_TIMER1 3 #define ID_TIMER2 4 #define IDM_ABOUTBOX 0x0010 #define IDD_ABOUTBOX 100 #define IDS_ABOUTBOX 101 #define IDD_TIMER_DIALOG 102 #define IDS_ELAPSEDTIME 102 #define IDR_MAINFRAME 128 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 129 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif --- NEW FILE: StdAfx.cpp --- // stdafx.cpp : source file that includes just the standard includes // Timer.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "StdAfx.h" #include "KTimer.h" //CTimer class /////////////////////////////////////////////////////////////////////////////// // Globals CTimer* g_pctTimer1 = NULL; CTimer* g_pctTimer2 = NULL; --- NEW FILE: StdAfx.h --- // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_STDAFX_H__383E4A3F_64E2_11D5_AB38_000103BE4653__INCLUDED_) #define AFX_STDAFX_H__383E4A3F_64E2_11D5_AB38_000103BE4653__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #include <afxwin.h> // MFC core and standard components #include <afxext.h> // MFC extensions #include <afxdisp.h> // MFC Automation classes #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__383E4A3F_64E2_11D5_AB38_000103BE4653__INCLUDED_) --- NEW FILE: Timer.cpp --- // Timer.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "Timer.h" #include "TimerDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTimerApp BEGIN_MESSAGE_MAP(CTimerApp, CWinApp) //{{AFX_MSG_MAP(CTimerApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTimerApp construction //##ModelId=3ECE70890304 CTimerApp::CTimerApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CTimerApp object CTimerApp theApp; ///////////////////////////////////////////////////////////////////////////// // CTimerApp initialization //##ModelId=3ECE70890305 BOOL CTimerApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CTimerDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; } --- NEW FILE: Timer.dsp --- # Microsoft Developer Studio Project File - Name="Timer" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Application" 0x0101 CFG=Timer - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "Timer.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "Timer.mak" CFG="Timer - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "Timer - Win32 Release" (based on "Win32 (x86) Application") !MESSAGE "Timer - Win32 Debug" (based on "Win32 (x86) Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "Timer - Win32 Release" # PROP BASE Use_MFC 6 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 6 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Obj\Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" # ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 # ADD LINK32 /nologo /subsystem:windows /machine:I386 !ELSEIF "$(CFG)" == "Timer - Win32 Debug" # PROP BASE Use_MFC 6 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 6 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Obj\Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL" # ADD RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept # ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "Timer - Win32 Release" # Name "Timer - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\KTaskIco.cpp !IF "$(CFG)" == "Timer - Win32 Release" !ELSEIF "$(CFG)" == "Timer - Win32 Debug" # SUBTRACT CPP /YX /Yc /Yu !ENDIF # End Source File # Begin Source File SOURCE=..\..\KTimer.cpp !IF "$(CFG)" == "Timer - Win32 Release" !ELSEIF "$(CFG)" == "Timer - Win32 Debug" # SUBTRACT CPP /YX /Yc /Yu !ENDIF # End Source File # Begin Source File SOURCE=..\..\KTimerW.cpp !IF "$(CFG)" == "Timer - Win32 Release" !ELSEIF "$(CFG)" == "Timer - Win32 Debug" # SUBTRACT CPP /YX /Yc /Yu !ENDIF # End Source File # Begin Source File SOURCE=.\StdAfx.cpp # ADD CPP /Yc"stdafx.h" # End Source File # Begin Source File SOURCE=.\Timer.cpp # End Source File # Begin Source File SOURCE=.\Timer.rc # End Source File # Begin Source File SOURCE=.\TimerDlg.cpp # End Source File # Begin Source File SOURCE=.\TimerProc.cpp # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE=..\..\KTaskIco.h # End Source File # Begin Source File SOURCE=..\..\KTimer.h # End Source File # Begin Source File SOURCE=..\..\KTimerW.h # End Source File # Begin Source File SOURCE=.\Resource.h # End Source File # Begin Source File SOURCE=.\StdAfx.h # End Source File # Begin Source File SOURCE=.\Timer.h # End Source File # Begin Source File SOURCE=.\TimerDlg.h # End Source File # End Group # Begin Group "Resource Files" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" # Begin Source File SOURCE=.\res\Timer.ico # End Source File # Begin Source File SOURCE=.\res\Timer.rc2 # End Source File # End Group # Begin Source File SOURCE=.\ReadMe.txt # End Source File # End Target # End Project --- NEW FILE: Timer.dsw --- Microsoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "Timer"=.\Timer.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### --- NEW FILE: Timer.h --- // Timer.h : main header file for the TIMER application // #if !defined(AFX_TIMER_H__383E4A3B_64E2_11D5_AB38_000103BE4653__INCLUDED_) #define AFX_TIMER_H__383E4A3B_64E2_11D5_AB38_000103BE4653__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols ///////////////////////////////////////////////////////////////////////////// // CTimerApp: // See Timer.cpp for the implementation of this class // //##ModelId=3ECE708902E6 class CTimerApp : public CWinApp { public: //##ModelId=3ECE70890304 CTimerApp(); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CTimerApp) public: //##ModelId=3ECE70890305 virtual BOOL InitInstance(); //}}AFX_VIRTUAL // Implementation //{{AFX_MSG(CTimerApp) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_TIMER_H__383E4A3B_64E2_11D5_AB38_000103BE4653__INCLUDED_) --- NEW FILE: Timer.rc --- //Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "#define _AFX_NO_SPLITTER_RESOURCES\r\n" "#define _AFX_NO_OLE_RESOURCES\r\n" "#define _AFX_NO_TRACKER_RESOURCES\r\n" "#define _AFX_NO_PROPERTY_RESOURCES\r\n" "\r\n" "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" "#ifdef _WIN32\r\n" "LANGUAGE 9, 1\r\n" "#pragma code_page(1252)\r\n" "#endif //_WIN32\r\n" "#include ""res\\Timer.rc2"" // non-Microsoft Visual C++ edited resources\r\n" "#include ""afxres.rc"" // Standard components\r\n" "#endif\r\n" "\0" END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Icon // // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDR_MAINFRAME ICON DISCARDABLE "res\\Timer.ico" ///////////////////////////////////////////////////////////////////////////// // // Dialog // IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "About Timer" FONT 8, "MS Sans Serif" BEGIN ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 LTEXT "Timer Version 1.0",IDC_STATIC,40,10,119,8,SS_NOPREFIX LTEXT "Copyright (C) 2001",IDC_STATIC,40,25,119,8 DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP END IDD_TIMER_DIALOG DIALOGEX 0, 0, 219, 58 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "Timer" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "Start Timer",IDOK,7,7,50,14 PUSHBUTTON "Cancel",IDCANCEL,162,38,50,14 DEFPUSHBUTTON "Timer 1",ID_TIMER1,7,23,102,14 DEFPUSHBUTTON "Timer 2",ID_TIMER2,7,37,102,14 END #ifndef _MAC ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x4L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904B0" BEGIN VALUE "CompanyName", "\0" VALUE "FileDescription", "Timer MFC Application\0" VALUE "FileVersion", "1, 0, 0, 1\0" VALUE "InternalName", "Timer\0" VALUE "LegalCopyright", "Copyright (C) 2001\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "Timer.EXE\0" VALUE "ProductName", "Timer Application\0" VALUE "ProductVersion", "1, 0, 0, 1\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END #endif // !_MAC ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO // #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO DISCARDABLE BEGIN IDD_ABOUTBOX, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 228 TOPMARGIN, 7 BOTTOMMARGIN, 48 END IDD_TIMER_DIALOG, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 212 TOPMARGIN, 7 BOTTOMMARGIN, 51 END END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // String Table // STRINGTABLE DISCARDABLE BEGIN IDS_ABOUTBOX "&About Timer..." IDS_ELAPSEDTIME "elapsed time = %f [s]" END #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // #define _AFX_NO_SPLITTER_RESOURCES #define _AFX_NO_OLE_RESOURCES #define _AFX_NO_TRACKER_RESOURCES #define _AFX_NO_PROPERTY_RESOURCES #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE 9, 1 #pragma code_page(1252) #endif //_WIN32 #include "res\Timer.rc2" // non-Microsoft Visual C++ edited resources #include "afxres.rc" // Standard components #endif ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED --- NEW FILE: TimerDlg.cpp --- // TimerDlg.cpp : implementation file // #include "StdAfx.h" #include "Timer.h" #include "TimerDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About //##ModelId=3ECE708B01DA class CAboutDlg : public CDialog { public: //##ModelId=3ECE708B01F8 CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: //##ModelId=3ECE708B0202 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //##ModelId=3ECE708B01F8 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } //##ModelId=3ECE708B0202 void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } /////////////////////////////////////////////////////////////////////////////// const int TIME_OUT = 1000;//time interval [ms] BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTimerDlg dialog //##ModelId=3ECE708901CD CTimerDlg::CTimerDlg(CWnd* pParent /*=NULL*/) : CDialog(CTimerDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTimerDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } //##ModelId=3ECE708901D7 void CTimerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTimerDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTimerDlg, CDialog) //{{AFX_MSG_MAP(CTimerDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(ID_TIMER1, OnTimer1) ON_BN_CLICKED(ID_TIMER2, OnTimer2) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTimerDlg message handlers //CTimerW* pTimer = NULL; //##ModelId=3ECE7089023B BOOL CTimerDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon m_ctwTimer1.Start(2*TIME_OUT, GetSafeHwnd(), CTimerDlg::IDD); m_ctwTimer2.Start(3*TIME_OUT, GetSafeHwnd(), CTimerDlg::IDD+1); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } //##ModelId=3ECE70890250 void CTimerDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. //##ModelId=3ECE70890265 void CTimerDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. //##ModelId=3ECE70890278 HCURSOR CTimerDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } //::OnOK()--------------------------------------------------------------------- #include "KTimer.h" //CTimer class /*Called when the user clicks the OK button (the button with an ID of IDOK). Creates new timers. */ //##ModelId=3ECE70890282 void CTimerDlg::OnOK() { TRACE0("CTimerDlg::OnOK()\n"); CreateCallbackTimer(); } //::CreateCallbackTimer()-------------------------------------------------------------- /*Testing creation of new timers. The timers are using callback function. System uses DWORD value to pass time elapsed since it was started and will wrap to zero after 49.7 days. */ //##ModelId=3ECE70890231 void CTimerDlg::CreateCallbackTimer() { TRACE0("CTimerDlg::CreateCallbackTimer()\n"); //Create simple timers with assigned callback function extern VOID CALLBACK MyTimerProc(HWND hWnd,UINT uMsg,UINT nTimerID,DWORD dwTime); extern CTimer* g_pctTimer1; extern CTimer* g_pctTimer2; //Initialize timers if (g_pctTimer1 == NULL) g_pctTimer1 = new CTimer(); if (g_pctTimer2 == NULL) { g_pctTimer2 = new CTimer(MyTimerProc); g_pctTimer1->SetTimerProc(MyTimerProc); } //Run timers g_pctTimer1->Start(TIME_OUT); g_pctTimer2->Start(4*TIME_OUT); } //::OnCancel()----------------------------------------------------------------- /*Called when the user clicks the Cancel button (the button with an ID of IDCANCEL). Deletes timers. */ //##ModelId=3ECE7089028D void CTimerDlg::OnCancel() { TRACE0("CTimerDlg::OnCancel()\n"); extern CTimer* g_pctTimer1; extern CTimer* g_pctTimer2; if (g_pctTimer1 != NULL) { #ifdef _DEBUG g_pctTimer1->Dump(); #endif delete g_pctTimer1; g_pctTimer1 = NULL; } if (g_pctTimer2 != NULL) { #ifdef _DEBUG g_pctTimer2->Dump(); #endif delete g_pctTimer2; g_pctTimer2 = NULL; } m_ctwTimer1.Stop(); m_ctwTimer2.Stop(); CDialog::OnCancel(); } //::OnTimer1()----------------------------------------------------------------- /*Called when the user clicks the Timer 1 button (the button with an ID of ID_TIMER1). Stops or starts first callback timer. */ //##ModelId=3ECE708902A0 void CTimerDlg::OnTimer1() { extern CTimer* g_pctTimer1; if (g_pctTimer1 != NULL) { if(g_pctTimer1->IsStarted()) g_pctTimer1->Stop(); else g_pctTimer1->Start(TIME_OUT); } } //::OnTimer2()----------------------------------------------------------------- /*Called when the user clicks the Timer 2 button (the button with an ID of ID_TIMER2). Stops or starts second callback timer. */ //##ModelId=3ECE708902AA void CTimerDlg::OnTimer2() { extern CTimer* g_pctTimer2; if (g_pctTimer2 != NULL) { if(g_pctTimer2->IsStarted()) g_pctTimer2->Stop(); else g_pctTimer2->Start(4*TIME_OUT); } } //::OnTimer()-------------------------------------------------------- /*Handles WM_TIMER messages sent by m_ctwTimer2. */ //##ModelId=3ECE708902B5 void CTimerDlg::OnTimer(UINT nIDEvent) { TRACE1("CTimerDlg::OnTimer(ID = %d)\n",nIDEvent); switch(nIDEvent) { case CTimerDlg::IDD: break; case (CTimerDlg::IDD +1): break; } CDialog::OnTimer(nIDEvent); } --- NEW FILE: TimerDlg.h --- // TimerDlg.h : header file // #if !defined(AFX_TIMERDLG_H__383E4A3D_64E2_11D5_AB38_000103BE4653__INCLUDED_) #define AFX_TIMERDLG_H__383E4A3D_64E2_11D5_AB38_000103BE4653__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "KTimerW.h" //CTimerW class ///////////////////////////////////////////////////////////////////////////// // CTimerDlg dialog //##ModelId=3ECE708901B0 class CTimerDlg : public CDialog { // Construction public: //##ModelId=3ECE708901CD CTimerDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CTimerDlg) enum { IDD = IDD_TIMER_DIALOG }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CTimerDlg) protected: //##ModelId=3ECE708901D7 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //##ModelId=3ECE708901EB HICON m_hIcon; //##ModelId=3ECE70890200 CTimerW m_ctwTimer1; //first timer with private message loop //##ModelId=3ECE7089021E CTimerW m_ctwTimer2; //second timer //##ModelId=3ECE70890231 void CreateCallbackTimer(); // Generated message map functions //{{AFX_MSG(CTimerDlg) //##ModelId=3ECE7089023B virtual BOOL OnInitDialog(); //##ModelId=3ECE70890250 afx_msg void OnSysCommand(UINT nID, LPARAM lParam); //##ModelId=3ECE70890265 afx_msg void OnPaint(); //##ModelId=3ECE70890278 afx_msg HCURSOR OnQueryDragIcon(); //##ModelId=3ECE70890282 virtual void OnOK(); //##ModelId=3ECE7089028D virtual void OnCancel(); //##ModelId=3ECE708902A0 afx_msg void OnTimer1(); //##ModelId=3ECE708902AA afx_msg void OnTimer2(); //##ModelId=3ECE708902B5 afx_msg void OnTimer(UINT nIDEvent); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_TIMERDLG_H__383E4A3D_64E2_11D5_AB38_000103BE4653__INCLUDED_) --- NEW FILE: TimerProc.cpp --- // TimerProc.cpp : implementation file // #include "StdAfx.h" #include "KTimer.h" //CTimer class #include "Resource.h" #include "TimerDlg.h" //CTimerDlg class #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /*Timer procedure used as an example for timer callaback function. The timer procedure is an application-defined callback function that processes WM_TIMER messages. Note: The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. See also: TIMERPROC */ VOID CALLBACK MyTimerProc(HWND hWnd, //handle of window processing timer messages UINT uMsg, //WM_TIMER message UINT nTimerID, //timer identifier DWORD dwTime //number of milliseconds that have //elapsed since the system was started ) { TRACE2("MyTimerProc(hWnd = %x, ID = %d, elapsed time = ",hWnd,nTimerID); extern CTimer* g_pctTimer1; extern CTimer* g_pctTimer2; CTimerDlg* pMainWnd = (CTimerDlg*)AfxGetMainWnd(); ASSERT(pMainWnd != NULL); DWORD dwElapsedTime; //elapsed time [ms] CString strOutput; //output text CWnd* pWnd; //output control if (nTimerID == g_pctTimer1->GetID()) { dwElapsedTime = g_pctTimer1->GetElapsedTime(dwTime); pWnd = pMainWnd->GetDlgItem(ID_TIMER1); TRACE1("%u [ms])\n",dwElapsedTime); } else if (nTimerID == g_pctTimer2->GetID()) { dwElapsedTime = g_pctTimer2->GetElapsedTime(dwTime); pWnd = pMainWnd->GetDlgItem(ID_TIMER2); TRACE1("%u [ms])\n",dwElapsedTime); MessageBeep(MB_OK); } strOutput.Format(IDS_ELAPSEDTIME,(double)dwElapsedTime/1000.); pWnd->SetWindowText((LPCTSTR)strOutput); } |