Click here to Skip to main content
15,893,814 members
Articles / Mobile Apps / Windows Mobile

CmenuModifier - An Owner Draw Image Menu

Rate me:
Please Sign up or sign in to vote.
3.92/5 (10 votes)
3 Jun 2008CPOL6 min read 48.9K   1.8K   23  
CmenuModifier - an owner draw image menu
// ZFrm.cpp : implementation of the ZFrm class
//

#include "stdafx.h"
#include "SDIView.h"

#include "ZFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// ZFrm

IMPLEMENT_DYNCREATE(ZFrm, CFrameWnd)

BEGIN_MESSAGE_MAP(ZFrm, CFrameWnd)
	//{{AFX_MSG_MAP(ZFrm)
	ON_WM_CREATE()
	ON_WM_DRAWITEM()
	ON_WM_MEASUREITEM()
	//}}AFX_MSG_MAP
	ON_COMMAND_RANGE(M0_OPEN, M0_SELECTALL, On_MenuClick)
	ON_UPDATE_COMMAND_UI_RANGE(M0_OPEN, M0_SELECTALL, On_UpdateMenuClick)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// ZFrm construction/destruction

ZFrm::ZFrm()
{
	i_CurMenu=M0_CUT;
}

ZFrm::~ZFrm()
{
}

int ZFrm::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	if (!bar_Img.CreateEx(this, TBSTYLE_FLAT,WS_CHILD |CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!bar_Img.LoadToolBar(BAR_IMG))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	COLORREF clrVertBar=RGB(220,220,220);

	CMenu*pMenu=GetMenu();
	md_Main.SetOwnerDraw(pMenu,1,&bar_Img,CMenuModifier::RAISED_BOTH,0,&clrVertBar);
	return 0;
}

BOOL ZFrm::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// ZFrm diagnostics

#ifdef _DEBUG
void ZFrm::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void ZFrm::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// ZFrm message handlers

void ZFrm::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	md_Main.OnMeasureItem(nIDCtl,lpMeasureItemStruct);
	
	CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

void ZFrm::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	md_Main.OnDrawItem(nIDCtl,lpDrawItemStruct);
	
	CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
}

//========================================= check a menu

void ZFrm::On_MenuClick(UINT uID)
{
	i_CurMenu=uID;
}

void ZFrm::On_UpdateMenuClick(CCmdUI* pCmdUI)
{
	pCmdUI->SetCheck(pCmdUI->m_nID==i_CurMenu);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia

Please visit our Download Home to obtain many interesting software for free ...


Comments and Discussions