_____________________________________________________________________________
#pragma once
class CMyBtn : public CButton
{
DECLARE_DYNAMIC(CMyBtn)
public:
CMyBtn();
virtual ~CMyBtn();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
};
_____________________________________________________________________________
// MyBtn.cpp : 구현 파일입니다.
//
#include "stdafx.h"
#include "My.h"
#include "MyBtn.h"
IMPLEMENT_DYNAMIC(CMyBtn, CButton)
CMyBtn::CMyBtn()
{
}
CMyBtn::~CMyBtn()
{
}
BEGIN_MESSAGE_MAP(CMyBtn, CButton)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
void CMyBtn::OnMouseMove(UINT nFlags, CPoint point)
{
CDC* pDC;
CWnd* pParent;
pParent = GetParent();
pDC = pParent->GetDC(); // <---- 부모윈도우, 즉 CChildView를 화면출력 기준으로 삼는다.
CString strPos;
strPos.Format(L"%04d %04d", point.x, point.y);
pDC->TextOutW(0, 0, strPos);
pParent->ReleaseDC(pDC);
CButton::OnMouseMove(nFlags, point);
}
_____________________________________________________________________________
// ChildView.h : CChildView 클래스의 인터페이스
//
#pragma once
// CChildView 창
class CMyBtn;
class CChildView : public CWnd
{
// 생성입니다.
public:
CChildView();
// 특성입니다.
public:
CMyBtn* m_pBtn;
// 작업입니다.
public:
// 재정의입니다.
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 구현입니다.
public:
virtual ~CChildView();
// 생성된 메시지 맵 함수
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};
_____________________________________________________________________________
// ChildView.cpp : CChildView 클래스의 구현
//
#include "stdafx.h"
#include "My.h"
#include "ChildView.h"
#include "MyBtn.h"
// CChildView
CChildView::CChildView()
{
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView, CWnd)
ON_WM_PAINT()
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()를 호출하지 마십시오.
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_pBtn = new CMyBtn();
m_pBtn->Create(L"CMyBtn", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
CRect(100, 0, 200, 200), this, 999);
return 0;
}
_____________________________________________________________________________
댓글 없음:
댓글 쓰기