#include "stdafx.h"
#include "item.h"
#include "itemDoc.h"
#include "itemView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int g_nTimer = 0;//全局变量
IMPLEMENT_DYNCREATE(CItemView, CView)
BEGIN_MESSAGE_MAP(CItemView, CView)
//{{AFX_MSG_MAP(CItemView)
ON_WM_TIMER()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CItemView construction/destructionCItemView::CItemView()
{
// TODO: add construction code here}CItemView::~CItemView()
{
}BOOL CItemView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}void CItemView::OnDraw(CDC* pDC)
{
CItemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here }#ifdef _DEBUG
void CItemView::AssertValid() const
{
CView::AssertValid();
}void CItemView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CItemDoc* CItemView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CItemDoc)));
return (CItemDoc*)m_pDocument;
}
#endif //_DEBUGvoid CItemView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
g_nTimer++;
if (g_nTimer == 10) g_nTimer=0;
DrawPicture();
UpdateData();
CView::OnTimer(nIDEvent);
}void CItemView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// SetTimer(1,60000,NULL);
SetTimer(1,6000,0);}void CItemView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// DrawPicture();
// Do not call CView::OnPaint() for painting messages
}void CItemView::DrawPicture()
{
CDC *pDC = GetDC(); CItemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int xStep,yStep;
int i,k;
CString str;
CRect Rect(100,200,400,440);
xStep=(Rect.right-Rect.left-10)/5;
yStep=(Rect.bottom-Rect.top-10)/10;
CPen Pen(PS_SOLID,2,RGB(255,0,0));
CPen* oldpen=pDC->SelectObject(&Pen);
CClientDC dc(this);
CBrush Brush(RGB(0,0,0));
CBrush *poldbrush=dc.SelectObject(&Brush);
dc.FillRect(Rect,&Brush);
dc.SelectObject(poldbrush);
pDC->MoveTo(Rect.left,Rect.bottom);
pDC->LineTo(Rect.left,Rect.top);
pDC->MoveTo(Rect.left,Rect.bottom);
pDC->LineTo(Rect.right,Rect.bottom);
pDC->MoveTo(Rect.left,Rect.top);
pDC->LineTo(Rect.left-6,Rect.top+10);
pDC->MoveTo(Rect.left,Rect.top);
pDC->LineTo(Rect.left+6,Rect.top+10);
pDC->MoveTo(Rect.right,Rect.bottom);
pDC->LineTo(Rect.right-10,Rect.bottom-6);
pDC->MoveTo(Rect.right,Rect.bottom);
pDC->LineTo(Rect.right-10,Rect.bottom+6);
CPen Pen1(PS_SOLID,1,RGB(128,128,128));
pDC->SelectObject(&Pen1);
for(i=1;i<=5;i++)
{
pDC->MoveTo(Rect.left+xStep*i,Rect.bottom);
pDC->LineTo(Rect.left+xStep*i,Rect.top+10);
str.Format("%d",i);
pDC->TextOut(Rect.left+xStep*i,Rect.bottom+10,str);
}
for(k=1;k<=10;k++)
{
pDC->MoveTo(Rect.left,Rect.bottom-k*yStep);
pDC->LineTo(Rect.right-10,Rect.bottom-k*yStep);
str.Format("%d",k);
pDC->TextOut(Rect.left-20,Rect.bottom-k*yStep,str);
}
pDC->SelectObject(oldpen);
str.Format("Distance=%d",g_nTimer);
pDC->TextOut(450,300,str);
UpdateData();
}
怎么只有等待6秒钟才输出图形,我想开始就输出图形,然后每隔6秒钟Distance=变化一下。
#include "item.h"
#include "itemDoc.h"
#include "itemView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int g_nTimer = 0;//全局变量
IMPLEMENT_DYNCREATE(CItemView, CView)
BEGIN_MESSAGE_MAP(CItemView, CView)
//{{AFX_MSG_MAP(CItemView)
ON_WM_TIMER()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CItemView construction/destructionCItemView::CItemView()
{
// TODO: add construction code here}CItemView::~CItemView()
{
}BOOL CItemView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}void CItemView::OnDraw(CDC* pDC)
{
CItemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here }#ifdef _DEBUG
void CItemView::AssertValid() const
{
CView::AssertValid();
}void CItemView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CItemDoc* CItemView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CItemDoc)));
return (CItemDoc*)m_pDocument;
}
#endif //_DEBUGvoid CItemView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
g_nTimer++;
if (g_nTimer == 10) g_nTimer=0;
DrawPicture();
UpdateData();
CView::OnTimer(nIDEvent);
}void CItemView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// SetTimer(1,60000,NULL);
SetTimer(1,6000,0);}void CItemView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// DrawPicture();
// Do not call CView::OnPaint() for painting messages
}void CItemView::DrawPicture()
{
CDC *pDC = GetDC(); CItemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int xStep,yStep;
int i,k;
CString str;
CRect Rect(100,200,400,440);
xStep=(Rect.right-Rect.left-10)/5;
yStep=(Rect.bottom-Rect.top-10)/10;
CPen Pen(PS_SOLID,2,RGB(255,0,0));
CPen* oldpen=pDC->SelectObject(&Pen);
CClientDC dc(this);
CBrush Brush(RGB(0,0,0));
CBrush *poldbrush=dc.SelectObject(&Brush);
dc.FillRect(Rect,&Brush);
dc.SelectObject(poldbrush);
pDC->MoveTo(Rect.left,Rect.bottom);
pDC->LineTo(Rect.left,Rect.top);
pDC->MoveTo(Rect.left,Rect.bottom);
pDC->LineTo(Rect.right,Rect.bottom);
pDC->MoveTo(Rect.left,Rect.top);
pDC->LineTo(Rect.left-6,Rect.top+10);
pDC->MoveTo(Rect.left,Rect.top);
pDC->LineTo(Rect.left+6,Rect.top+10);
pDC->MoveTo(Rect.right,Rect.bottom);
pDC->LineTo(Rect.right-10,Rect.bottom-6);
pDC->MoveTo(Rect.right,Rect.bottom);
pDC->LineTo(Rect.right-10,Rect.bottom+6);
CPen Pen1(PS_SOLID,1,RGB(128,128,128));
pDC->SelectObject(&Pen1);
for(i=1;i<=5;i++)
{
pDC->MoveTo(Rect.left+xStep*i,Rect.bottom);
pDC->LineTo(Rect.left+xStep*i,Rect.top+10);
str.Format("%d",i);
pDC->TextOut(Rect.left+xStep*i,Rect.bottom+10,str);
}
for(k=1;k<=10;k++)
{
pDC->MoveTo(Rect.left,Rect.bottom-k*yStep);
pDC->LineTo(Rect.right-10,Rect.bottom-k*yStep);
str.Format("%d",k);
pDC->TextOut(Rect.left-20,Rect.bottom-k*yStep,str);
}
pDC->SelectObject(oldpen);
str.Format("Distance=%d",g_nTimer);
pDC->TextOut(450,300,str);
UpdateData();
}
怎么只有等待6秒钟才输出图形,我想开始就输出图形,然后每隔6秒钟Distance=变化一下。
解决方案 »
- directx和visual studio是什么关系?
- MFC界面问题
- iocp最大连接数实测能达到多少
- 为什么我的DHCP Client收不到DHCP_OFFER消息?请教高手
- 高分请教 hough变化检测圆形(其他方法也可以)
- 头要爆老,(关于ASP中用VBSCript,向自编COM传参数的问题??????)
- 为何CDAODatabase 的open()函数打不开access 2000的数据库
- 钩子函数里:GETMESSAGE????hook问题
- 要交作业了,急求帮助:怎样用close函数去关闭文件
- 菜鸟提问:怎么样建立无模式对话框?
- 程序异常终止
- 我已经屏蔽了CHtmlView点击右键弹出的菜单,可是怎么也屏蔽不了按下键盘上右边Win键旁边的那个键弹出的菜单!我该怎么办?
{
CItemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
DrawPicture(); //这是也加上才行。 }
{
// TODO: Add your message handler code here and/or call default
g_nTimer++;
if (g_nTimer == 10) g_nTimer=0;
Invalidate();//加上这句
CView::OnTimer(nIDEvent);
}void CItemView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
SetTimer(1,6000,NULL);
}
DrawPicture();