본문 바로가기

Windows/MFC

CMenuSubItem

// MenuSubItem.cpp : implementation file
//
//
// DATE        : May 02, 2007
// CODER    : aucd29
// ------------------------------------------------------
// NOTE
// ------------------------------------------------------
// * 메뉴를 꾸미기 위해서 생성하는 클래스
//

#include "stdafx.h"
#include "Main Unit Manager.h"
#include "MenuSubItem.h"
#include "common.h"
#include "Main Unit ManagerView.h"

// CMenuSubItem

// static variant
HCURSOR CMenuSubItem::m_hCursorHand        = 0;
CMenuSubItem* CMenuSubItem::m_pWndFocus = NULL;
extern CMainUnitManagerView* g_pView;

CMenuSubItem::CMenuSubItem(CString szName, UINT uiCommand)
    : m_szName(szName)
    , m_nHeight(-1)
    , m_uiCommand(uiCommand)
    , m_uiItemState(0)
{
    m_rtItem.SetRectEmpty();
    if (!m_hCursorHand) m_hCursorHand = AfxGetApp()->LoadCursor(IDC_MYHAND);
}

CMenuSubItem::~CMenuSubItem()
{

}

// CMenuSubItem member functions

int CMenuSubItem::GetItemHeight(void)
{
    if (m_nHeight == -1)
    {
        m_nHeight = 20;
    }
    return m_nHeight;
}

void CMenuSubItem::OnDraw(Graphics* pDC, CRect rcItem, int nOffsetY, CWnd* pParent, bool bType)
{
    SolidBrush* pBrush;
    SolidBrush* pBrushFont;
    m_rtItem = rcItem;

    if (m_pWndFocus == this)
    {
        pBrush     = g_GDIPlusObj.brConrflowerBlue;
        pBrushFont = g_GDIPlusObj.brRoyalBlue;
    }
    else
    {
        pBrushFont = g_GDIPlusObj.brWindowBlue;
        if (m_uiItemState & ODS_SELECTED)
        {
            pBrush = g_GDIPlusObj.brDarkCyan;
        }
        else
        {
            pBrush = g_GDIPlusObj.brWhite;
        }
    }

    if (bType)
    {
        ::FillRoundBottomRect(pDC, pBrush, static_cast<REAL>(rcItem.left), static_cast<REAL>(rcItem.top),
            static_cast<REAL>(rcItem.Width()), static_cast<REAL>(rcItem.Height()), 3.0f);
    }
    else
    {
        pDC->FillRectangle(pBrush, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height());
    }
    
    PointF MovePosition(rcItem.left + 15, rcItem.top + 2);
    pDC->DrawString(m_szName, -1, g_GDIPlusObj.fontTahoma10, MovePosition, g_GDIPlusObj.sfNearCenter, pBrushFont);
}

bool CMenuSubItem::HitTest(CPoint point)
{
    return PtInRect(m_rtItem, point) ? true : false;
}

bool CMenuSubItem::OnMouseOut(CPoint point, CPoint point2)
{
    m_uiItemState &= ~ODS_SELECTED;
    return true;
}

bool CMenuSubItem::OnMouseIn(CPoint point, CPoint point2)
{
    m_uiItemState |= ODS_SELECTED;
    return true;
}

bool CMenuSubItem::OnMouseLUp(CPoint point, CPoint point2)
{
    g_pView->PostMessage(WM_COMMAND, m_uiCommand, 0);
    SetFocusItem();    
    return true;
}

bool CMenuSubItem::OnMouseLDown(CPoint point, CPoint point2)
{
    return false;
}

void CMenuSubItem::SetFocusItem(void)
{
    m_pWndFocus = this;
}


//////////////////////////////////////////////////////////////

#pragma once

// CMenuSubItem command target

class CMenuSubItem : public CObject
{
public:
    CMenuSubItem(CString szName, UINT uiCommand);
    virtual ~CMenuSubItem();

protected:
    int m_nHeight;
    UINT m_uiCommand;
    UINT m_uiItemState;
    CRect m_rtItem;
    CString m_szName;
    static HCURSOR m_hCursorHand;
    static CMenuSubItem* m_pWndFocus;        // 현재 어떤 item이 focus되어 있는지 알기 위해!

public:
    int GetItemHeight(void);
    bool HitTest(CPoint point);
    bool OnMouseOut(CPoint point, CPoint point2);
    bool OnMouseIn(CPoint point, CPoint point2);
    bool OnMouseLUp(CPoint point, CPoint point2);
    bool OnMouseLDown(CPoint point, CPoint point2);
    void SetFocusItem(void);
    virtual void OnDraw(Graphics* pDC, CRect rcItem, int nOffsetY, CWnd* pParent, bool bType);
};

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////


'Windows > MFC' 카테고리의 다른 글

스크롤바 스킨 scrollbar  (0) 2013.10.02
CMuLeftMenu  (0) 2013.10.02
윈도우크기변경 WindowSizeChange  (0) 2013.10.02
CXMLFile - A Simple C++ XML Parser  (0) 2013.10.02
클라이언트 프로그램에서 Global IME를 구현하는 방법  (0) 2013.10.02