banner despecable me2

วันพฤหัสบดีที่ 4 กรกฎาคม พ.ศ. 2556

lab9 การเขียนโปรแกรม MFC #6



-----------------------------------------h---------------------------------------
#include "afxwin.h"
#define IDC_PAD 100
#define IDC_CLSBUTTON 101
#define IDC_COPYBUTTON 102
#define IDC_PASTEBUTTON 103
#define IDC_EXITBUTTON 104

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

class CWin:public CFrameWnd{
 int response;
 CEdit *EditPad;
 CButton *CLSButton;
 CButton *CopyButton;
 CButton *PasteButton;
 CButton *ExitButton;

public: CWin();
  ~CWin();
  afx_msg void onExit();
  afx_msg void onCopy();
  afx_msg void onPaste();
  afx_msg void onCLS();
  DECLARE_MESSAGE_MAP();
};
__________________________________cpp__________________________________

#include "lab9.h"

CApp app;

BEGIN_MESSAGE_MAP(CWin, CFrameWnd)
 ON_BN_CLICKED(IDC_EXITBUTTON, onExit)
 ON_BN_CLICKED(IDC_COPYBUTTON, onCopy)
 ON_BN_CLICKED(IDC_PASTEBUTTON, onPaste)
 ON_BN_CLICKED(IDC_CLSBUTTON, onCLS)
END_MESSAGE_MAP();

void CWin::onExit(){
 response=MessageBox("Do you want to quit!!\n Yes or No?",
  "Lab9: Little note pad", MB_ICONQUESTION|MB_YESNO);
 if (response==IDYES) DestroyWindow();
}

void CWin::onCopy(){
 EditPad->SetSel(0,-1,TRUE);
 EditPad->Copy();
 EditPad->SetFocus();
}

void CWin::onCLS(){
 EditPad->SetSel(0,-1,TRUE);
 EditPad->Copy();
 EditPad->SetFocus();
}

void CWin::onPaste(){
 EditPad->SetSel(0,-1,TRUE);
 EditPad->Copy();
 EditPad->SetFocus();
}

BOOL CApp::InitInstance(){
 m_pMainWnd=new CWin();
 m_pMainWnd->ShowWindow(m_nCmdShow);
 m_pMainWnd->UpdateWindow();
 return TRUE;
}
CWin::CWin(){
 Create(NULL,"Little note pad",
  WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX, CRect(0,0,290,245));
 EditPad=new CEdit();
 CLSButton=new CButton();
 CopyButton=new CButton();
 PasteButton=new CButton();
 ExitButton=new CButton();
 EditPad->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP| \
  ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_MULTILINE,
  CRect(10,10,270,140), this, IDC_PAD);
 CLSButton->Create("Clear",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(10,145,90,170), this, IDC_CLSBUTTON);
 CopyButton->Create("Copy",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(100,145,180,170), this, IDC_COPYBUTTON);
 PasteButton->Create("Paste",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(190,145,270,170), this, IDC_PASTEBUTTON);
 ExitButton->Create("Exit",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(10,175,270,200), this, IDC_EXITBUTTON);
}

CWin::~CWin(){
 delete EditPad;
 delete CLSButton;
 delete CopyButton;
 delete PasteButton;
 delete ExitButton;

}

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

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