วันศุกร์ที่ 28 มิถุนายน พ.ศ. 2556

LAB7 MFC


คลิ้กที่ปุ่ม Click me จะมีหน้าต่าง Lab7a Hello,I Love C++ โชว์


-------------------------------------------- สร้าง File.h --------------------------------------------
#include <afxwin.h>

#define IDC_MYBUTTON1 1001

class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};

class CWin : public CFrameWnd
{
public:
CWin();
~CWin();
CButton *myButton;

afx_msg void OnClick();
DECLARE_MESSAGE_MAP ();
};

-------------------------------------------- สร้าง File.cpp --------------------------------------------

#include "LAB7b.h"

CMyApp theApp; 

BEGIN_MESSAGE_MAP(CWin, CFrameWnd)
ON_BN_CLICKED(IDC_MYBUTTON1, OnClick)
END_MESSAGE_MAP()

void CWin::OnClick(){
MessageBox("Hello, I Love C++","Lab7a");
}

BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CWin(); 
m_pMainWnd->ShowWindow(m_nCmdShow);  
m_pMainWnd->UpdateWindow(); 
return TRUE;
}

CWin::CWin()
{
myButton = new CButton(); 
Create(NULL,"Hello Visual c++, Easy MFC 01",
WS_OVERLAPPEDWINDOW, CRect(100,100,500,300));
(*myButton).Create("Click me",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(10,10,100,50),this,IDC_MYBUTTON1);

}

CWin::~CWin()
{
delete myButton;
}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น