banner despecable me2

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

lab7 การเขียนโปรแกรม MFC #4

---------------h--------------
#include <afxwin.h>

#define IDC_MYBUTTON1 1001 // (1) define

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

class CMyFrame : public CFrameWnd //create window
{
public:
CMyFrame();
~CMyFrame();
CButton *myButton1;

afx_msg void OnClick1();

DECLARE_MESSAGE_MAP();
};

-----------------------cpp-------------

#include "S1.h"


CMyApp theApp; // create application object

BEGIN_MESSAGE_MAP(CMyFrame , CFrameWnd)
ON_BN_CLICKED(IDC_MYBUTTON1,OnClick1)
END_MESSAGE_MAP()
void CMyFrame :: OnClick1()
MessageBox("Hello, I LOVE YOU");
}



BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame(); // create windows frame object and link to application
m_pMainWnd->ShowWindow(m_nCmdShow); //show frame windows

m_pMainWnd->UpdateWindow(); // update frame windows
return TRUE;
}

CMyFrame::CMyFrame()
{
myButton1 = new CButton();
// (3) memory allocation
Create(NULL,"Hello Visual c++, Easy MFC 01", 
WS_OVERLAPPEDWINDOW, CRect(100,100,500,300));
// (4) create control
myButton1 -> Create("Click me", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(10,10,100,50),this,IDC_MYBUTTON1);
}

CMyFrame::~CMyFrame()
{
delete myButton1;

}



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

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