GUI/Skin

메뉴 - MFC

jjryu 2010. 6. 27. 14:02

#include "MenuEx.h"

class CToolBarAppView : public CView
{
// <
    CMenuEx    m_menuContext;
// >
protected: // create from serialization only
    CToolBarAppView();
...
// Generated message map functions
protected:
    //{{AFX_MSG(CToolBarAppView)
    afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
    afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
    afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
    afx_msg void OnPopupPen();
    ...
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};


BEGIN_MESSAGE_MAP(CToolBarAppView, CView)
    //{{AFX_MSG_MAP(CToolBarAppView)
    ON_WM_CONTEXTMENU()
    ON_WM_DRAWITEM()
    ON_WM_MEASUREITEM()
    ON_COMMAND(ID_POPUP_PEN, OnPopupPen)
    ...
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

CToolBarAppView::CToolBarAppView()
{
    // TODO: add construction code here
    m_menuContext.Initialize(IDR_POPUP, NULL);
}
...
void CToolBarAppView::OnContextMenu(CWnd* pWnd, CPoint point)
{
    // TODO: Add your message handler code here
    CMenu* pSubMenu = m_menuContext.GetSubMenu(0);

    pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);   
}

void CToolBarAppView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
    // TODO: Add your message handler code here and/or call default
// <
    m_menuContext.MeasureItem(this, lpMeasureItemStruct);
// >   
    CView::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

void CToolBarAppView::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    // TODO: Add your message handler code here and/or call default
// <
    m_menuContext.DrawItem(lpDrawItemStruct);
// >
    CView::OnDrawItem(nIDCtl, lpDrawItemStruct);
}

void CToolBarAppView::OnPopupPen()
{
    // TODO: Add your command handler code here
    ...
}
...


참조 사이트: