banner despecable me2

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

lab8 การเขียนโปรแกรม MFC #5

----------------------------------h----------------------------

#include <afxwin.h>

#define IDC_YES_BUTTON 100 // (1) define
#define IDC_NO_BUTTON 101
class CMyApp : public CWinApp // create application
{
public:
virtual BOOL  InitInstance();
};

class CMyFrame : public CFrameWnd //create window
{
public:
CMyFrame();
~CMyFrame();
CButton *myButton1;
CButton *myButton2;// (2) declare button control

afx_msg void YesClicked();
afx_msg void NoClicked();

DECLARE_MESSAGE_MAP();
};

___________________cpp__________________


#include "S1.h"


CMyApp theApp; // create application object

BEGIN_MESSAGE_MAP(CMyFrame , CFrameWnd)
ON_BN_CLICKED(IDC_YES_BUTTON,YesClicked)
ON_BN_CLICKED(IDC_NO_BUTTON,NoClicked)
END_MESSAGE_MAP()
void CMyFrame :: YesClicked()
MessageBox("YES");
}
void CMyFrame :: NoClicked()
MessageBox("No");
}


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();
myButton2 = 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("YES", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(10,10,100,50),this,IDC_YES_BUTTON);
myButton2 -> Create("NO", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(110,10,210,50),this,IDC_NO_BUTTON);
}

CMyFrame::~CMyFrame()
{
delete myButton1;
delete myButton2;
}

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

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