CDC::onpaint()不能paint,怎么回事???(50分)

  • 主题发起人 主题发起人 herald
  • 开始时间 开始时间
H

herald

Unregistered / Unconfirmed
GUEST, unregistred user!
学习VC++,想让鼠标左键双击一下主form,就显示一个绿色的小人,(小人在资源中以bmp方式定义过了),鼠标在什么坐标双击,小人就移动到哪里。
但是程序运行的时候也不提示出错,就是小人的位置不刷新,一定要激活别的任务的窗口一下,让本程序的窗口失去焦点,在激活本程序,小人的位置才会更新,我在鼠标的双击代码中加入了cview::onpaint();
还是不行,
请问各位VC大虾,我什么地方做错了?
需要看整个VC工程文件的的请mail到heraldsoft@netease.com
======================以下是主视图的代码================
// hex_jiamiView.cpp : implementation of the CHex_jiamiView class
//
#include "stdafx.h"
#include "hex_jiami.h"
#include "hex_jiamiDoc.h"
#include "hex_jiamiView.h"
#include "c_post_bitmap.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHex_jiamiView
IMPLEMENT_DYNCREATE(CHex_jiamiView, CView)
begin
_MESSAGE_MAP(CHex_jiamiView, CView)
//{{AFX_MSG_MAP(CHex_jiamiView)
ON_WM_LBUTTONDBLCLK()
ON_WM_CANCELMODE()
ON_WM_PAINT()
ON_WM_CAPTURECHANGED()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CHex_jiamiView construction/destruction
CHex_jiamiView::CHex_jiamiView()
{
//this->post_bmp.base_point.x=1;
}
CHex_jiamiView::~CHex_jiamiView()
{
}
BOOL CHex_jiamiView::PreCreateWindow(CREATESTRUCT&
cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHex_jiamiView drawing
void CHex_jiamiView::OnDraw(CDC* pDC)
{
CHex_jiamiDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CHex_jiamiView printing
BOOL CHex_jiamiView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
returndo
PreparePrinting(pInfo);
}
void CHex_jiamiView::Onbegin
Printing(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHex_jiamiView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHex_jiamiView diagnostics
#ifdef _DEBUG
void CHex_jiamiView::AssertValid() const
{
CView::AssertValid();
}
void CHex_jiamiView::Dump(CDumpContext&
dc) const
{
CView::Dump(dc);
}
CHex_jiamiDoc* CHex_jiamiView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHex_jiamiDoc)));
return (CHex_jiamiDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHex_jiamiView message handlers
[red]void CHex_jiamiView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CView::OnCancelMode();
post_bmp.base_point.x=point.x;
post_bmp.base_point.y=point.y;
CView::OnPaint();
//CView::OnLButtonDblClk(nFlags, point);
//sleep(100);
CView::OnPaint();
}[/red]
void CHex_jiamiView::OnCancelMode()
{
}
[red]
void CHex_jiamiView::OnPaint()
{int xx,yy;
CPaintDC dc(this);
// device context for painting

CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(this->post_bmp);
//////////////////
xx=post_bmp.base_point.x;
yy=post_bmp.base_point.y;
dc.BitBlt(xx,yy,89,132,&memDC,0,0,SRCCOPY);
//do
not call CView::OnPaint() for painting messages
}[/red]
void CHex_jiamiView::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here

CView::OnCaptureChanged(pWnd);
}
 
以上代码中的[red]和[/red]是原来代码中没有的,是这个该死的dfw给我加上去的
 
老兄你这样做当然不行,请用Invalidate(),使系统对窗口进行重画.
 
你调用的是基类的OnPaint,当然不行
用Invalidate(),如果视图闪烁的话用InvalidateRect(),
 
多人接受答案了。
 

Similar threads

H
回复
0
查看
172
herald
H
后退
顶部