___________________________________________________________________________
메세지: WM_LBUTTONDOWN
핸들러: OnLButtonDown(...)
맵핑매크로: ON_WM_LBUTTONDOWN()
메세지: WM_MOUSEMOVE
핸들러: OnMouseMove
맵핑매크로: ON_WM_MOUSEMOVE()
메세지: WM_CREATE
핸들러: OnCreate
맵핑매크로: ON_WM_CREATE()
메시지: WM_COMMAND
핸들러: OnXXX() <--- 사용자 정의
맵핑매크로: ON_COMMAND(사용자지정ID, OnXXX)
버튼윈도우 클래스: CButton
에딧윈도우 클래스: CEdit
노티피케이션코드: EN_CHANGE
핸들러: OnXXX()
맵핑매크로: ON_EN_CHANGE(사용자지정ID, OnXXX)
___________________________________________________________________________
메뉴추가: my.rc, IDR_MAINFRAME, ID_TEST_TEST
___________________________________________________________________________
소스코드: CChildView.H
//
#pragma once
// CChildView 창
class CChildView : public CWnd
{
// 생성입니다.
public:
CChildView();
CButton* m_pBtn;
CEdit* m_pEdt1;
CEdit* m_pEdt2;
// 특성입니다.
public:
// 작업입니다.
public:
// 재정의입니다.
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 구현입니다.
public:
virtual ~CChildView();
// 생성된 메시지 맵 함수
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlasg, CPoint pt);
afx_msg void OnTestTest();
afx_msg void OnBtn1();
afx_msg void OnEdt1();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};
___________________________________________________________________________
소스코드: CChildView.CPP
// ChildView.cpp : CChildView 클래스의 구현
//
#include "stdafx.h"
#include "My.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CChildView
CChildView::CChildView()
{
m_pBtn = NULL;
m_pEdt1 = 0;
m_pEdt2 = 0;
}
CChildView::~CChildView()
{
if (m_pBtn != NULL)
{
m_pBtn->DestroyWindow();
delete m_pBtn;
}
if (m_pEdt1 != NULL)
{
m_pEdt1->DestroyWindow();
delete m_pEdt1;
}
if (m_pEdt2 != NULL)
{
m_pEdt2->DestroyWindow();
delete m_pEdt2;
}
}
BEGIN_MESSAGE_MAP(CChildView, CWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_TEST_TEST, &CChildView::OnTestTest)
ON_BN_CLICKED(999, &CChildView::OnBtn1)
ON_EN_CHANGE(888, &CChildView::OnEdt1)
ON_WM_CREATE()
END_MESSAGE_MAP()
// CChildView 메시지 처리기
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다.
// TODO: 여기에 메시지 처리기 코드를 추가합니다.
// 그리기 메시지에 대해서는 CWnd::OnPaint()를 호출하지 마십시오.
}
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
this->MessageBox(L"안녕");
CWnd::OnLButtonDown(nFlags, point);
}
void CChildView::OnMouseMove(UINT nFlags, CPoint pt)
{
//HDC dc;
CDC* pDC;
//hdc = ::GetDC(m_hWnd);
pDC = GetDC();
//char szPos[128];
//sprintf(szPos, "%04d %04d", pt.x, pt.y);
//::TextOut(hdc, 0, 0, szPos, strlen(szPos));
CString strPos;
strPos.Format(L"%04d %04d", pt.x, pt.y);
//::TextOut(hdc, 0, 0, strPos, strPos.GetLength());
pDC->TextOutW(0, 0, strPos);
//::ReleaseDC(m_hWnd, hdc);
ReleaseDC(pDC);
CWnd::OnMouseMove(nFlags, pt);
}
void CChildView::OnTestTest()
{
// TODO: 여기에 명령 처리기 코드를 추가합니다.
MessageBox(L"메뉴클릭");
}
void CChildView::OnBtn1()
{
// TODO: 여기에 명령 처리기 코드를 추가합니다.
MessageBox(L"버튼클릭");
}
void CChildView::OnEdt1()
{
// TODO: 여기에 명령 처리기 코드를 추가합니다.
CString strMsg;
m_pEdt1->GetWindowTextW(strMsg);
m_pEdt2->SetWindowTextW(strMsg);
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 여기에 특수화된 작성 코드를 추가합니다.
if (m_pBtn == NULL)
{
m_pBtn = new CButton();
CRect rect;
rect.left = 100;
rect.top = 0;
rect.right = 200;
rect.bottom = 100;
m_pBtn->Create(L"click",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
rect, this, 999);
}
if (m_pEdt1 == 0)
{
m_pEdt1 = new CEdit();
m_pEdt1->Create(
WS_VISIBLE|WS_CHILD|WS_BORDER|
ES_MULTILINE,
CRect(0, 100, 200, 200), this, 888);
}
if (m_pEdt2 == 0)
{
m_pEdt2 = new CEdit();
m_pEdt2->Create(
WS_VISIBLE | WS_CHILD | WS_BORDER|
ES_MULTILINE,
CRect(0, 200, 200, 300), this, 777);
}
return 0;
}
소스코드: CChildView.CPP
// ChildView.cpp : CChildView 클래스의 구현
//
#include "stdafx.h"
#include "My.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CChildView
CChildView::CChildView()
{
m_pBtn = NULL;
m_pEdt1 = 0;
m_pEdt2 = 0;
}
CChildView::~CChildView()
{
if (m_pBtn != NULL)
{
m_pBtn->DestroyWindow();
delete m_pBtn;
}
if (m_pEdt1 != NULL)
{
m_pEdt1->DestroyWindow();
delete m_pEdt1;
}
if (m_pEdt2 != NULL)
{
m_pEdt2->DestroyWindow();
delete m_pEdt2;
}
}
BEGIN_MESSAGE_MAP(CChildView, CWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_TEST_TEST, &CChildView::OnTestTest)
ON_BN_CLICKED(999, &CChildView::OnBtn1)
ON_EN_CHANGE(888, &CChildView::OnEdt1)
ON_WM_CREATE()
END_MESSAGE_MAP()
// CChildView 메시지 처리기
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다.
// TODO: 여기에 메시지 처리기 코드를 추가합니다.
// 그리기 메시지에 대해서는 CWnd::OnPaint()를 호출하지 마십시오.
}
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
this->MessageBox(L"안녕");
CWnd::OnLButtonDown(nFlags, point);
}
void CChildView::OnMouseMove(UINT nFlags, CPoint pt)
{
//HDC dc;
CDC* pDC;
//hdc = ::GetDC(m_hWnd);
pDC = GetDC();
//char szPos[128];
//sprintf(szPos, "%04d %04d", pt.x, pt.y);
//::TextOut(hdc, 0, 0, szPos, strlen(szPos));
CString strPos;
strPos.Format(L"%04d %04d", pt.x, pt.y);
//::TextOut(hdc, 0, 0, strPos, strPos.GetLength());
pDC->TextOutW(0, 0, strPos);
//::ReleaseDC(m_hWnd, hdc);
ReleaseDC(pDC);
CWnd::OnMouseMove(nFlags, pt);
}
void CChildView::OnTestTest()
{
// TODO: 여기에 명령 처리기 코드를 추가합니다.
MessageBox(L"메뉴클릭");
}
void CChildView::OnBtn1()
{
// TODO: 여기에 명령 처리기 코드를 추가합니다.
MessageBox(L"버튼클릭");
}
void CChildView::OnEdt1()
{
// TODO: 여기에 명령 처리기 코드를 추가합니다.
CString strMsg;
m_pEdt1->GetWindowTextW(strMsg);
m_pEdt2->SetWindowTextW(strMsg);
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 여기에 특수화된 작성 코드를 추가합니다.
if (m_pBtn == NULL)
{
m_pBtn = new CButton();
CRect rect;
rect.left = 100;
rect.top = 0;
rect.right = 200;
rect.bottom = 100;
m_pBtn->Create(L"click",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
rect, this, 999);
}
if (m_pEdt1 == 0)
{
m_pEdt1 = new CEdit();
m_pEdt1->Create(
WS_VISIBLE|WS_CHILD|WS_BORDER|
ES_MULTILINE,
CRect(0, 100, 200, 200), this, 888);
}
if (m_pEdt2 == 0)
{
m_pEdt2 = new CEdit();
m_pEdt2->Create(
WS_VISIBLE | WS_CHILD | WS_BORDER|
ES_MULTILINE,
CRect(0, 200, 200, 300), this, 777);
}
return 0;
}
___________________________________________________________________________
댓글 없음:
댓글 쓰기