home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dtime / data.1 / dateDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-08  |  3.6 KB  |  124 lines

  1. // datentryDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "dtime.h"
  6. #include "resource.h"
  7. #include "dateDlg.h"
  8.  
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. CDatentryDlg::CDatentryDlg(CWnd* pParent /*=NULL*/)
  17.   : CDialog(CDatentryDlg::IDD, pParent)
  18. {
  19.   //{{AFX_DATA_INIT(CDatentryDlg)
  20.     // NOTE: the ClassWizard will add member initialization here
  21.   //}}AFX_DATA_INIT
  22.   // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  23.   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  24.  
  25.   m_CDate = CDate::CurrentDate();
  26.   m_CLTimeSpan = CLTimeSpan(1, 2, 3, 4, 5);
  27.   m_CLTimeOfDay = CLTimeOfDay(1, 2, 3, 4);
  28.   m_CLDate = CLDate::CurrentTime(LOCAL);
  29. }
  30.  
  31. void CDatentryDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33.   CDialog::DoDataExchange(pDX);
  34.   //{{AFX_DATA_MAP(CDatentryDlg)
  35.   //}}AFX_DATA_MAP
  36.  
  37.   //connect to the controls, using a selection of flags for 
  38.   //demonstration purposes, you can change the flags to suit the way you
  39.   //prefer to display the dialogs
  40.   DDX_CDateControl(pDX, IDC_CDATE, m_ctrlCDate, DT_NODRAG | DT_MODAL);
  41.   DDX_CLTimeSpanControl(pDX, IDC_CLTIMESPAN, m_ctrlCLTimeSpan, DT_MODAL);
  42.   DDX_CLTimeOfDayControl(pDX, IDC_CLTIMEOFDAY, m_ctrlCLTimeOfDay, DT_ONLYVALID | DT_PUSHPIN | DT_MODELESS);
  43.   DDX_CLDateControl(pDX, IDC_CLDATE, m_ctrlCLDate, DT_MODELESS);
  44.  
  45.   //retreive / set the actual values 
  46.   DDX_CDate(pDX, m_ctrlCDate, m_CDate);
  47.   DDX_CLTimeSpan(pDX, m_ctrlCLTimeSpan, m_CLTimeSpan);
  48.   DDX_CLTimeOfDay(pDX, m_ctrlCLTimeOfDay, m_CLTimeOfDay);
  49.   DDX_CLDate(pDX, m_ctrlCLDate, m_CLDate);
  50. }
  51.  
  52. BEGIN_MESSAGE_MAP(CDatentryDlg, CDialog)
  53.   //{{AFX_MSG_MAP(CDatentryDlg)
  54.   ON_WM_PAINT()
  55.   ON_WM_QUERYDRAGICON()
  56.   //}}AFX_MSG_MAP
  57.   #ifndef _WIN32
  58.   ON_COMMAND(DTIME_EDIT_CONTROL_ID, OnEditButton)
  59.   #endif
  60. END_MESSAGE_MAP()
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CDatentryDlg message handlers
  64.  
  65. BOOL CDatentryDlg::OnInitDialog()
  66. {
  67.   CDialog::OnInitDialog();
  68.  
  69.   // Set the icon for this dialog.  The framework does this automatically
  70.   //  when the application's main window is not a dialog
  71.   #ifdef _WIN32
  72.     SetIcon(m_hIcon, TRUE);     // Set big icon
  73.     SetIcon(m_hIcon, FALSE);    // Set small icon
  74.   #endif
  75.   
  76.   return TRUE;  // return TRUE  unless you set the focus to a control
  77. }
  78.  
  79. // If you add a minimize button to your dialog, you will need the code below
  80. //  to draw the icon.  For MFC applications using the document/view model,
  81. //  this is automatically done for you by the framework.
  82.  
  83. void CDatentryDlg::OnPaint() 
  84. {
  85.   if (IsIconic())
  86.   {
  87.     CPaintDC dc(this); // device context for painting
  88.  
  89.     SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  90.  
  91.     // Center icon in client rectangle
  92.     int cxIcon = GetSystemMetrics(SM_CXICON);
  93.     int cyIcon = GetSystemMetrics(SM_CYICON);
  94.     CRect rect;
  95.     GetClientRect(&rect);
  96.     int x = (rect.Width() - cxIcon + 1) / 2;
  97.     int y = (rect.Height() - cyIcon + 1) / 2;
  98.  
  99.     // Draw the icon
  100.     dc.DrawIcon(x, y, m_hIcon);
  101.   }
  102.   else
  103.   {
  104.     CDialog::OnPaint();
  105.   }
  106. }
  107.  
  108. // The system calls this to obtain the cursor to display while the user drags
  109. //  the minimized window.
  110. HCURSOR CDatentryDlg::OnQueryDragIcon()
  111. {
  112.   return (HCURSOR) m_hIcon;
  113. }
  114.  
  115. #ifndef _WIN32
  116. void CDatentryDlg::OnEditButton()
  117. {                       
  118.   //reflect the message back down to the window which sent it to us
  119.   const MSG* pMsg = GetCurrentMessage( ); 
  120.   HWND hButton = (HWND) LOWORD(pMsg->lParam);
  121.   ::SendMessage(hButton, UWM_BN_CLICKED, 0, 0L);
  122. }
  123. #endif
  124.