[code]// CustomMenu.cpp : implementation file
//
#include "stdafx.h"
#include "CustomMenu.h"
// CCustomMenu
IMPLEMENT_DYNAMIC(CCustomMenu, CWnd)
CCustomMenu::CCustomMenu()
: m_nPadding(5)
, m_nButtonHeight(20)
, m_nButtonGap(2)
, m_bCustomSetting(false)
{
m_crBorderColor = RGB(127, 157, 185);
m_crBackground = RGB(255, 255, 255);
m_brBackground.CreateSolidBrush(m_crBackground);
m_brBorder.CreateSolidBrush(m_crBorderColor);
}
CCustomMenu::~CCustomMenu()
{
DeleteButton();
m_listMenu.RemoveAll();
m_brBackground.DeleteObject();
m_brBorder.DeleteObject();
mBitmap.DeleteObject();
}
BEGIN_MESSAGE_MAP(CCustomMenu, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
// CCustomMenu message handlers
void CCustomMenu::AddMenu(CString szMenu)
{
m_listMenu.AddTail(szMenu);
}
void CCustomMenu::OnPaint()
{
CPaintDC dc(this); // device context for painting
InitObject(&dc);
dc.BitBlt(0, 0, m_rect.Width(), m_rect.Height(), &mDC, 0, 0, SRCCOPY);
}
void CCustomMenu::SetRect(CRect rect)
{
TRACE(L"WindowPos: %d %d %d %d\n", rect.left, rect.top, rect.right, rect.bottom);
m_rect = rect;
m_rectBorder = rect;
TRACE(L"WindowPos: %d %d %d %d\n", m_rectBorder.left, m_rectBorder.top, m_rectBorder.right, m_rectBorder.bottom);
m_rectBorder.right -= m_rectBorder.left;
m_rectBorder.bottom -= m_rectBorder.top;
TRACE(L"WindowPos: %d %d %d %d\n", m_rectBorder.left, m_rectBorder.top, m_rectBorder.right, m_rectBorder.bottom);
}
BOOL CCustomMenu::Create(CWnd* pWnd)
{
return CWnd::Create(
AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
GetSysColorBrush(COLOR_3DFACE)),
_T("CustomMenu"),
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, m_rect, pWnd, 0xFFFF);
}
void CCustomMenu::SetStaticControl(void)
{
int nCount = static_cast<int>(m_listMenu.GetCount());
CRect rect;
int nID = 0;
POSITION pos = m_listMenu.GetHeadPosition();
// 버튼을 프로퍼티페이지 수에 맞게 끔 추가한다.
// 이곳에 추가적으로 넣을 만한건
// 자체 타이틀 같은거? 구분자 같은거 넣어주면
// 좋을듯 몇번 째 위치에 머를 넣어라 식으로 말이지
//
m_pstcControl = new CButtonExFlatProperty* [nCount];
rect.SetRect(m_rect.left + m_nPadding, m_rect.top + m_nPadding,
m_rect.Width() - m_nPadding, m_nButtonHeight + m_rect.top + m_nPadding);
while (pos)
{
m_pstcControl[nID] = new CButtonExFlatProperty(nID);
m_pstcControl[nID++]->Create(m_listMenu.GetNext(pos),WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,
rect, this, nID);
rect.top = rect.bottom + m_nButtonGap;
rect.bottom = rect.top + m_nButtonHeight + m_nButtonGap;
}
m_pstcControl[0]->SetCheck(BST_CHECKED);
}
void CCustomMenu::DeleteButton(void)
{
// 생성한 버튼을 지우도록 하자.
int nCount = static_cast<int>(m_listMenu.GetCount());
POSITION pos = m_listMenu.GetHeadPosition();
int i = 0;
for (i=0; i<nCount; ++i)
{
delete m_pstcControl[i];
}
if (nCount)
{
delete[] m_pstcControl;
}
}
void CCustomMenu::InitObject(CDC* pDC)
{
if (!m_bCustomSetting)
{
mDC.CreateCompatibleDC(pDC);
mBitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
mDC.SelectObject(&mBitmap);
CRect rect;
rect = m_rect;
rect.top = 0;
rect.left = 0;
mDC.FillSolidRect(rect, GetSysColor(COLOR_3DFACE));
mDC.FillRect(m_rect, &m_brBackground);
mDC.FrameRect(m_rectBorder, &m_brBorder);
m_bCustomSetting = true;
}
}
[/code]
[code]
#pragma once
#include "ButtonExFlatProperty.h"
// CCustomMenu
class CCustomMenu : public CWnd
{
DECLARE_DYNAMIC(CCustomMenu)
public:
CCustomMenu();
virtual ~CCustomMenu();
protected:
int m_nPadding;
int m_nButtonHeight;
int m_nButtonGap;
CDC mDC;
bool m_bCustomSetting;
CRect m_rect, m_rectBorder;
CBrush m_brBackground, m_brBorder;
CBitmap mBitmap;
COLORREF m_crBorderColor;
COLORREF m_crActiveBackground;
COLORREF m_crActiveBorder;
COLORREF m_crOverBackground;
COLORREF m_crOverBorder;
COLORREF m_crBackground;
CStringList m_listMenu;
CButtonExFlatProperty** m_pstcControl;
DECLARE_MESSAGE_MAP()
public:
void AddMenu(CString szMenu);
afx_msg void OnPaint();
void SetRect(CRect rect);
virtual BOOL Create(CWnd* pWnd);
void SetStaticControl(void);
void DeleteButton(void);
virtual void InitObject(CDC* pDC);
};
[/code]
//
#include "stdafx.h"
#include "CustomMenu.h"
// CCustomMenu
IMPLEMENT_DYNAMIC(CCustomMenu, CWnd)
CCustomMenu::CCustomMenu()
: m_nPadding(5)
, m_nButtonHeight(20)
, m_nButtonGap(2)
, m_bCustomSetting(false)
{
m_crBorderColor = RGB(127, 157, 185);
m_crBackground = RGB(255, 255, 255);
m_brBackground.CreateSolidBrush(m_crBackground);
m_brBorder.CreateSolidBrush(m_crBorderColor);
}
CCustomMenu::~CCustomMenu()
{
DeleteButton();
m_listMenu.RemoveAll();
m_brBackground.DeleteObject();
m_brBorder.DeleteObject();
mBitmap.DeleteObject();
}
BEGIN_MESSAGE_MAP(CCustomMenu, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
// CCustomMenu message handlers
void CCustomMenu::AddMenu(CString szMenu)
{
m_listMenu.AddTail(szMenu);
}
void CCustomMenu::OnPaint()
{
CPaintDC dc(this); // device context for painting
InitObject(&dc);
dc.BitBlt(0, 0, m_rect.Width(), m_rect.Height(), &mDC, 0, 0, SRCCOPY);
}
void CCustomMenu::SetRect(CRect rect)
{
TRACE(L"WindowPos: %d %d %d %d\n", rect.left, rect.top, rect.right, rect.bottom);
m_rect = rect;
m_rectBorder = rect;
TRACE(L"WindowPos: %d %d %d %d\n", m_rectBorder.left, m_rectBorder.top, m_rectBorder.right, m_rectBorder.bottom);
m_rectBorder.right -= m_rectBorder.left;
m_rectBorder.bottom -= m_rectBorder.top;
TRACE(L"WindowPos: %d %d %d %d\n", m_rectBorder.left, m_rectBorder.top, m_rectBorder.right, m_rectBorder.bottom);
}
BOOL CCustomMenu::Create(CWnd* pWnd)
{
return CWnd::Create(
AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
GetSysColorBrush(COLOR_3DFACE)),
_T("CustomMenu"),
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, m_rect, pWnd, 0xFFFF);
}
void CCustomMenu::SetStaticControl(void)
{
int nCount = static_cast<int>(m_listMenu.GetCount());
CRect rect;
int nID = 0;
POSITION pos = m_listMenu.GetHeadPosition();
// 버튼을 프로퍼티페이지 수에 맞게 끔 추가한다.
// 이곳에 추가적으로 넣을 만한건
// 자체 타이틀 같은거? 구분자 같은거 넣어주면
// 좋을듯 몇번 째 위치에 머를 넣어라 식으로 말이지
//
m_pstcControl = new CButtonExFlatProperty* [nCount];
rect.SetRect(m_rect.left + m_nPadding, m_rect.top + m_nPadding,
m_rect.Width() - m_nPadding, m_nButtonHeight + m_rect.top + m_nPadding);
while (pos)
{
m_pstcControl[nID] = new CButtonExFlatProperty(nID);
m_pstcControl[nID++]->Create(m_listMenu.GetNext(pos),WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,
rect, this, nID);
rect.top = rect.bottom + m_nButtonGap;
rect.bottom = rect.top + m_nButtonHeight + m_nButtonGap;
}
m_pstcControl[0]->SetCheck(BST_CHECKED);
}
void CCustomMenu::DeleteButton(void)
{
// 생성한 버튼을 지우도록 하자.
int nCount = static_cast<int>(m_listMenu.GetCount());
POSITION pos = m_listMenu.GetHeadPosition();
int i = 0;
for (i=0; i<nCount; ++i)
{
delete m_pstcControl[i];
}
if (nCount)
{
delete[] m_pstcControl;
}
}
void CCustomMenu::InitObject(CDC* pDC)
{
if (!m_bCustomSetting)
{
mDC.CreateCompatibleDC(pDC);
mBitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
mDC.SelectObject(&mBitmap);
CRect rect;
rect = m_rect;
rect.top = 0;
rect.left = 0;
mDC.FillSolidRect(rect, GetSysColor(COLOR_3DFACE));
mDC.FillRect(m_rect, &m_brBackground);
mDC.FrameRect(m_rectBorder, &m_brBorder);
m_bCustomSetting = true;
}
}
[/code]
[code]
#pragma once
#include "ButtonExFlatProperty.h"
// CCustomMenu
class CCustomMenu : public CWnd
{
DECLARE_DYNAMIC(CCustomMenu)
public:
CCustomMenu();
virtual ~CCustomMenu();
protected:
int m_nPadding;
int m_nButtonHeight;
int m_nButtonGap;
CDC mDC;
bool m_bCustomSetting;
CRect m_rect, m_rectBorder;
CBrush m_brBackground, m_brBorder;
CBitmap mBitmap;
COLORREF m_crBorderColor;
COLORREF m_crActiveBackground;
COLORREF m_crActiveBorder;
COLORREF m_crOverBackground;
COLORREF m_crOverBorder;
COLORREF m_crBackground;
CStringList m_listMenu;
CButtonExFlatProperty** m_pstcControl;
DECLARE_MESSAGE_MAP()
public:
void AddMenu(CString szMenu);
afx_msg void OnPaint();
void SetRect(CRect rect);
virtual BOOL Create(CWnd* pWnd);
void SetStaticControl(void);
void DeleteButton(void);
virtual void InitObject(CDC* pDC);
};
[/code]
'Windows > MFC' 카테고리의 다른 글
CDialogExThin (0) | 2013.10.02 |
---|---|
Create None Frame Dialog (프레임 없는 다이얼로그 생성하기) (0) | 2013.10.02 |
CPropertyFrame (0) | 2013.10.02 |
CPropertyPageExt (0) | 2013.10.02 |
CPropertySheetExt (0) | 2013.10.02 |