|
// MenuHelpers.cpp
//
// Author : David Shepherd
// Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MenuHelpers.h"
CMenuHandle CreateEmptyPopupMenu(DWORD EmptyTextId)
{
USES_CONVERSION;
// create the empty popup menu
CMenu Menu;
if(Menu.CreatePopupMenu()==FALSE)
{
throw std::exception();
}
// insert the empty menu item
CComBSTR Text;
if(Text.LoadString(EmptyTextId)==FALSE)
{
throw std::exception();
}
if(Menu.AppendMenu(
MF_STRING|MF_GRAYED,0,W2CT(BSTR2W(Text)))==FALSE)
{
throw std::exception();
}
return Menu.Detach();
}
void SetPopupMenu(CMenuHandle hParent,long ItemId,CMenuHandle hPopup)
{
// check parameters
if(hParent==NULL)
{
throw std::exception();
}
if(hPopup==NULL)
{
throw std::exception();
}
// get the menu item text length
long TextLength=hParent.GetMenuStringLen(ItemId,MF_BYCOMMAND);
if(TextLength==0)
{
throw std::exception();
}
// get the menu item text
std::auto_ptr<TCHAR> pText(new TCHAR[TextLength+1]);
if(hParent.GetMenuString(ItemId,pText.get(),TextLength+1,MF_BYCOMMAND)==0)
{
throw std::exception();
}
// set the popup menu
if(hParent.ModifyMenu(ItemId,MF_BYCOMMAND|MF_STRING|MF_POPUP,
(UINT)(HMENU)hPopup,pText.get())==FALSE)
{
throw std::exception();
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.