您的位置:首页 > 编程语言 > C语言/C++

孙鑫VC++深入详解:Lesson3

2013-07-03 13:11 232 查看
问题: 如果创建2个button则会运行时出错.

在Win32中,直接用CreateWindow()创建2个buttons时,只要ID不同没有任何任何问题, 但是这里就是不行.

m_Btn.Create("按钮A",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,CRect(0,0,100,100),this,123); // 创建按钮123

m_Btn.Create("按钮B",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,CRect(100,100,200,200),this,12);//同时创建按钮12 Failed.

// Lesson3View.cpp : implementation of the CLesson3View class
//

#include "stdafx.h"
#include "Lesson3.h"

#include "Lesson3Doc.h"
#include "Lesson3View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLesson3View

IMPLEMENT_DYNCREATE(CLesson3View, CView)

BEGIN_MESSAGE_MAP(CLesson3View, CView)
//{{AFX_MSG_MAP(CLesson3View)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CLesson3View construction/destruction

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

}

CLesson3View::~CLesson3View()
{
}

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

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLesson3View drawing

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

/////////////////////////////////////////////////////////////////////////////
// CLesson3View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLesson3View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLesson3View message handlers
// 增加Create消息响应函数 OnCreate
int CLesson3View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
//	m_Btn.Create("按钮A",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,CRect(0,0,100,100),this,123); // 创建按钮123
m_Btn.Create("按钮B",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,CRect(100,100,200,200),this,12);//同时创建按钮12 Failed.

//	m_Btn.ShowWindow(SW_SHOWNORMAL);
//	m_Btn.UpdateData();
return 0;
}

// Size消息响应
void CLesson3View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
static int flag =0;
if(flag==0)
{
//	m_Btn.Create("按钮B",WS_CHILD|WS_VISIBLE|BS_GROUPBOX,CRect(100,100,200,200),this,1234);
flag =1;
}

}

// left button 消息响应
void CLesson3View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
static int flag =0;
if(flag==0)
{
//	m_Btn.Create("按钮C",WS_CHILD|WS_VISIBLE|BS_AUTO3STATE,CRect(210,210,300,300),this,12345);
flag =1;
}

CView::OnLButtonDown(nFlags, point);
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐