MFC 响应自创按扭的消息

// ButtonView.cpp : implementation of the CButtonView class
//

#include "stdafx.h"
#include "Button.h"

#include "ButtonDoc.h"
#include "ButtonView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CButtonView

IMPLEMENT_DYNCREATE(CButtonView, CView)

BEGIN_MESSAGE_MAP(CButtonView, CView)
 //{{AFX_MSG_MAP(CButtonView)
 ON_WM_CREATE()
 //}}AFX_MSG_MAP
 // Standard printing commands
    ON_COMMAND(123, CButtonView::LButtonDown)  //先要在这儿添加消息声明,及响应函数。
 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()

/
// CButtonView construction/destruction

CButtonView::CButtonView()
{
 // TODO: add construction code here

}

CButtonView::~CButtonView()
{
}

BOOL CButtonView::PreCreateWindow(CREATESTRUCT& cs)
{
 // TODO: Modify the Window class or styles here by modifying
 //  the CREATESTRUCT cs

 return CView::PreCreateWindow(cs);
}

/
// CButtonView drawing

void CButtonView::OnDraw(CDC* pDC)
{
 CButtonDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: add draw code for native data here
}

/
// CButtonView printing

BOOL CButtonView::OnPreparePrinting(CPrintInfo* pInfo)
{
 // default preparation
 return DoPreparePrinting(pInfo);
}

void CButtonView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
 // TODO: add extra initialization before printing
}

void CButtonView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
 // TODO: add cleanup after printing
}

/
// CButtonView diagnostics

#ifdef _DEBUG
void CButtonView::AssertValid() const
{
 CView::AssertValid();
}

void CButtonView::Dump(CDumpContext& dc) const
{
 CView::Dump(dc);
}

CButtonDoc* CButtonView::GetDocument() // non-debug version is inline
{
 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CButtonDoc)));
 return (CButtonDoc*)m_pDocument;
}
#endif //_DEBUG

/
// CButtonView message handlers

int CButtonView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CView::OnCreate(lpCreateStruct) == -1)
  return -1;
 
 // TODO: Add your specialized creation code here
 MyButton.Create("MyButton",WS_CHILD,CRect(0,0,100,100),this,123); //然后是创建按扭,以及显示按扭。
 MyButton.ShowWindow(SW_SHOWNORMAL);
 

 return 0;
}

//DEL void CButtonView::OnLButtonDown(UINT nFlags, CPoint point)
//DEL {
//DEL  // TODO: Add your message handler code here and/or call default
//DEL  if(nFlags==123)
//DEL   MessageBox("OK");
//DEL  CView::OnLButtonDown(nFlags, point);
//DEL }

int CButtonView::LButtonDown() //这是消息响应函数实体
{
MessageBox("我被按下来了");
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值