home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Using Visual C++ 4 (Special Edition)
/
Using_Visual_C_4_Special_Edition_QUE_1996.iso
/
ch03
/
ch3_menu
/
ch3mview.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-23
|
4KB
|
191 lines
// ch3mView.cpp : implementation of the CChapter03MenuView class
//
#include "stdafx.h"
#include "ch3_menu.h"
#include "ch3mDoc.h"
#include "ch3mView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChapter03MenuView
IMPLEMENT_DYNCREATE(CChapter03MenuView, CView)
BEGIN_MESSAGE_MAP(CChapter03MenuView, CView)
//{{AFX_MSG_MAP(CChapter03MenuView)
ON_COMMAND(ID_TIME_DATETIME, OnTimeDateTime)
ON_COMMAND(ID_TIME_STARTTIMER, OnTimeStartTimer)
ON_COMMAND(ID_TIME_STOPTIMER, OnTimeStopTimer)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_CHAR()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChapter03MenuView construction/destruction
CChapter03MenuView::CChapter03MenuView()
{
// TODO: add construction code here
}
CChapter03MenuView::~CChapter03MenuView()
{
}
BOOL CChapter03MenuView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CChapter03MenuView drawing
void CChapter03MenuView::OnDraw(CDC* pDC)
{
CChapter03MenuDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CChapter03MenuView printing
BOOL CChapter03MenuView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CChapter03MenuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CChapter03MenuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CChapter03MenuView diagnostics
#ifdef _DEBUG
void CChapter03MenuView::AssertValid() const
{
CView::AssertValid();
}
void CChapter03MenuView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CChapter03MenuDoc* CChapter03MenuView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChapter03MenuDoc)));
return (CChapter03MenuDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChapter03MenuView message handlers
void CChapter03MenuView::OnTimeDateTime()
{
// display current date/time in long format
CClientDC dc(this);
dc.TextOut(10, 40, CTime::GetCurrentTime().Format("%#c"));
}
void CChapter03MenuView::OnTimeStartTimer()
{
// trigger a timer every second
SetTimer(1, 1000, NULL);
}
void CChapter03MenuView::OnTimeStopTimer()
{
// just shut it down
KillTimer(1);
}
void CChapter03MenuView::OnLButtonDown(UINT nFlags, CPoint point)
{
// display current date/time in standard format
CClientDC dc(this);
dc.TextOut(10, 20, CTime::GetCurrentTime().Format("%c"));
}
void CChapter03MenuView::OnRButtonDown(UINT nFlags, CPoint point)
{
// display current date/time in long format
OnTimeDateTime();
}
void CChapter03MenuView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CClientDC dc(this);
char buffer[200];
sprintf(buffer,
"Char: %c Repeat Count: %2d Flags: %08x ",
(char)nChar,
nRepCnt,
nFlags);
dc.TextOut(10, 60, buffer);
}
void CChapter03MenuView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
char buffer[200];
sprintf(buffer,
"Mouse: %4d,%4d Flags: %08x ",
point.x,
point.y,
nFlags);
dc.TextOut(10, 80, buffer);
}
void CChapter03MenuView::OnTimer(UINT nIDEvent)
{
static int count = 0;
count++;
CClientDC dc(this);
char buffer[200];
sprintf(buffer,
"Total Timer Count: %4d",
count);
dc.TextOut(10, 100, buffer);
OnLButtonDown(0,0);
OnRButtonDown(0,0);
}