วันเสาร์ที่ 29 มิถุนายน พ.ศ. 2556

LAB8 MFC


คลิ้กที่ปุ่ม button 1 จะมี บล้อก  Lab8a Hello1,buttom1 โชว์

คลิ้กที่ปุ่ม button 2 จะมี บล้อก  Lab8a Hello2,buttom2 โชว์

------------------------------------------- สร้างไฟล์ .h -------------------------------------------
#include <afxwin.h>

#define IDC_MYBUTTON1 1001
#define IDC_MYBUTTON2 1002

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

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

afx_msg void OnClick1();
afx_msg void OnClick2();
DECLARE_MESSAGE_MAP ();
};


------------------------------------------ สร้างไฟล์ .Cpp ---------------------------------------------
#include "LAB8b.h"
CMyApp theApp; 
BEGIN_MESSAGE_MAP(CWin, CFrameWnd)
ON_BN_CLICKED(IDC_MYBUTTON1 ,OnClick1)
ON_BN_CLICKED(IDC_MYBUTTON2 ,OnClick2)
END_MESSAGE_MAP()
void CWin::OnClick1(){
MessageBox("Hello1, button1","Lab8a");
}
void CWin::OnClick2(){
MessageBox("Hello2, button2","Lab8a");
}
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CWin(); 
m_pMainWnd->ShowWindow(m_nCmdShow); 
m_pMainWnd->UpdateWindow(); 
return TRUE;
}
CWin::CWin()
{
myButton1 = new CButton(); 
myButton2 = new CButton(); 
Create(NULL,"Hello Visual c++, Easy MFC 01",
WS_OVERLAPPEDWINDOW, CRect(100,100,500,300));

(*myButton1).Create("button 1",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(10,10,100,50),this,IDC_MYBUTTON1);
(*myButton2).Create("button 2",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(110,10,200,50),this,IDC_MYBUTTON2);
}
CWin::~CWin()
{
delete myButton1;
delete myButton2;
}



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

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