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:reCreateWindow(CREATESTRUCT&
cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView:reCreateWindow(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:ump(CDumpContext&
dc) const
{
CView:ump(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);
}
但是程序运行的时候也不提示出错,就是小人的位置不刷新,一定要激活别的任务的窗口一下,让本程序的窗口失去焦点,在激活本程序,小人的位置才会更新,我在鼠标的双击代码中加入了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:reCreateWindow(CREATESTRUCT&
cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView:reCreateWindow(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:ump(CDumpContext&
dc) const
{
CView:ump(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);
}