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

LAB9 MFC

พิมพ์ข้อความลงไป

กด Clear ข้อความหายไป
============================สร้างไฟล์ .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 OnCLS();
       afx_msg void OnCopy();
       afx_msg void OnPaste();
       afx_msg void OnExit();
       DECLARE_MESSAGE_MAP ();
};

============================สร้างไฟล์ .Cpp============================

#include "LAB9b.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 !!\nYes or No?",
              "lab9: Little notw pad", MB_ICONQUESTION|MB_YESNO);
       if (response==IDYES) DestroyWindow();
}

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

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

void CWin::OnPaste(){
       EditPad->Paste();
       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_TABSTOP,
                CRect(10,145,90,170), this,IDC_CLSBUTTON);
         CopyButton->Create("Copy",
                WS_CHILD|WS_VISIBLE|WS_TABSTOP,
                CRect(100,145,180,170), this,IDC_COPYBUTTON);
         PasteButton->Create("Paste",
                WS_CHILD|WS_VISIBLE|WS_TABSTOP,
                CRect(190,145,270,170), this,IDC_PASTEBUTTON);
         ExitButton->Create("Clear",
                WS_CHILD|WS_VISIBLE|WS_TABSTOP,
                CRect(10,175,270,200), this,IDC_EXITBUTTON);
}
CWin::~CWin()
{
       delete EditPad;
       delete CLSButton;
       delete CopyButton;
       delete PasteButton;
       delete ExitButton;
}



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

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