home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Buyer 1998 October
/
dpcb1098.iso
/
Business
/
Maxim
/
MAX5
/
data.z
/
DTCtrl.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-05-15
|
5KB
|
174 lines
//////////////////////////////////////////////////////////////////////////////
// NAME.......: DTCtrl.CPP
// PURPOSE....: new time windows common control,
// need Comctl32.lib and Commctrl.h
//
// WRITTEN....: 96/09/27 by Darko Juvan
//
// This code and information is provided "as is" without warranty of any
// kind, either expressed or implied, including but not limited to the
// implied warranties of merchantability and/or fitness for a particular
// purpose..
//
// Copyright (c) 1998 Multiactive Software Inc. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "commctrl.h"
#include "DTCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDTCtrl
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: CDTCtrl()
//
// DESCRIPTION: constructor
//
//////////////////////////////////////////////////////////////////////////////
CDTCtrl::CDTCtrl()
{
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: ~CDTCtrl()
//
// DESCRIPTION: destructor
//
//////////////////////////////////////////////////////////////////////////////
CDTCtrl::~CDTCtrl()
{
}
BEGIN_MESSAGE_MAP(CDTCtrl, CWnd)
//{{AFX_MSG_MAP(CDTCtrl)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDTCtrl message handlers
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: Create()
//
// DESCRIPTION: create time common ctrl
//
//////////////////////////////////////////////////////////////////////////////
BOOL CDTCtrl::Create(BOOL bDate, CWnd* pParentWnd, UINT nDlgID, UINT nCtrlID)
{
CRect rect;
pParentWnd->GetDlgItem(nDlgID)->GetWindowRect(rect);
pParentWnd->ScreenToClient(rect);
BOOL bRes = CWnd::Create(DATETIMEPICK_CLASS,
NULL,
WS_VISIBLE |
WS_CHILD |
WS_TABSTOP |
DTS_LONGDATEFORMAT |
(bDate ? 0 : DTS_TIMEFORMAT),
rect,
pParentWnd,
nCtrlID );
return bRes;
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: GetTime()
//
// DESCRIPTION: return time in string format
//
//////////////////////////////////////////////////////////////////////////////
CString CDTCtrl::GetTime(CTime* pTime)
{
SYSTEMTIME sys_time;
SendMessage(DTM_GETSYSTEMTIME, 0, (LPARAM)(&sys_time));
CTime time(sys_time);
*pTime = time;
CString t = time.Format("%I:%M %p");
if(t[0] == '0')
t.SetAt(0, ' ');
return t;
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: GetDate()
//
// DESCRIPTION: return date in string format
//
//////////////////////////////////////////////////////////////////////////////
CString CDTCtrl::GetDate()
{
SYSTEMTIME sys_time;
SendMessage(DTM_GETSYSTEMTIME, 0, (LPARAM)(&sys_time));
CTime time(sys_time);
return time.Format("%A, %B %d, %Y" );
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: SetDate()
//
// DESCRIPTION: set date in ctrl
//
//////////////////////////////////////////////////////////////////////////////
void CDTCtrl::SetDate(UINT year, UINT month, UINT day)
{
SYSTEMTIME sys_time;
sys_time.wYear = year;
sys_time.wMonth = month;
sys_time.wDayOfWeek = 0;
sys_time.wDay = day;
sys_time.wHour = 0;
sys_time.wMinute = 0;
sys_time.wSecond = 0;
sys_time.wMilliseconds = 0;
SendMessage(DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)(&sys_time));
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: SetTime()
//
// DESCRIPTION: set time in ctrl
//
//////////////////////////////////////////////////////////////////////////////
void CDTCtrl::SetTime(UINT hour, UINT min, UINT sec)
{
SYSTEMTIME sys_time;
sys_time.wYear = 1996;
sys_time.wMonth = 11;
sys_time.wDayOfWeek = 0;
sys_time.wDay = 9;
sys_time.wHour = hour;
sys_time.wMinute = min;
sys_time.wSecond = sec;
sys_time.wMilliseconds = 10;
SendMessage(DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)(&sys_time));
}