Setting an Icon on a Popup Menu

D

David Wendt

I am using the following code to add a popup menu under the "File" pulldown
in Office but I cannot seem to get an icon to show up next to the menu.

.....
VARIANT avtParms[5];

avtParms[0].vt = VT_BOOL;
avtParms[0].boolVal = VARIANT_TRUE;// makes menu 'temporary'
avtParms[1].vt = VT_I4;
avtParms[1].lVal = 7; // 7th position--just under "Save as
web-page"
avtParms[2].vt = VT_I4;
avtParms[2].lVal = 1; // not really sure what this is
avtParms[3].vt = VT_I4;
avtParms[3].lVal = 1; // id not used by anybody: leave it as 1
avtParms[4].vt = VT_I4;
avtParms[4].lVal = 10; // popup menu item control

hr = CallMethod( vtMenuCtrls.pdispVal, L"Add", &vtMine, 5,
avtParms );
if( SUCCEEDED(hr) )
{
HBITMAP hBmp = (HBITMAP)::LoadImage( g_hModule,
MAKEINTRESOURCE(IDB_BITMAP1),

IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS );
// put bitmap into Clipboard
::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
::CloseClipboard();
::DeleteObject(hBmp);

// get what we just added
hr = GetProperty( vtMine.pdispVal, L"Control", &vtMineCtl );

// set style before setting bitmap
vtParam.vt = VT_I4;
vtParam.lVal = 3; // msoButtonIconAndCaption
// both of the following calls return 0x80020006
hr = PutProperty(vtMineCtl.pdispVal, L"Style", &vtParam);
hr = CallMethod(vtMineCtl.pdispVal,L"PasteFace",NULL,0,NULL);

vtParam.vt = VT_BSTR;
vtParam.bstrVal = ::SysAllocString( L"Mine" );
hr = PutProperty( vtMineCtl.pdispVal, L"Caption", &vtParam );
if( SUCCEEDED(hr) )
{
hr = PutProperty( vtMineCtl.pdispVal, L"Tag", &vtParam );
VariantClear( &vtParam );

.....

The PutProperty for Style and the CallMethod for PasteFace return a
0x80020006 which means that the property and method do not exist on the
object. I have no trouble adding icons to non-popup menus.

Can someone tell me what I have to do to my code here in order to add an
icon to the popup?
 
L

Lokesh

Did you solve this problem. Can I get thesample code of
it. As i am not able to add even the menu item
 
D

David Wendt

No I never did find a solution to this. So please post one here if you find
one.
--David Wendt

Lokesh said:
Did you solve this problem. Can I get thesample code of
it. As i am not able to add even the menu item
-----Original Message-----
I am using the following code to add a popup menu under the "File" pulldown
in Office but I cannot seem to get an icon to show up next to the menu.

.....
VARIANT avtParms[5];

avtParms[0].vt = VT_BOOL;
avtParms[0].boolVal = VARIANT_TRUE;// makes menu 'temporary'
avtParms[1].vt = VT_I4;
avtParms[1].lVal = 7; // 7th position--just under "Save as
web-page"
avtParms[2].vt = VT_I4;
avtParms[2].lVal = 1; // not really sure what this is
avtParms[3].vt = VT_I4;
avtParms[3].lVal = 1; // id not used by anybody: leave it as 1
avtParms[4].vt = VT_I4;
avtParms[4].lVal = 10; // popup menu item control

hr = CallMethod( vtMenuCtrls.pdispVal, L"Add", &vtMine, 5,
avtParms );
if( SUCCEEDED(hr) )
{
HBITMAP hBmp = (HBITMAP)::LoadImage( g_hModule,
MAKEINTRESOURCE(IDB_BITMAP1),

IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS );
// put bitmap into Clipboard
::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
::CloseClipboard();
::DeleteObject(hBmp);

// get what we just added
hr = GetProperty( vtMine.pdispVal, L"Control", &vtMineCtl );

// set style before setting bitmap
vtParam.vt = VT_I4;
vtParam.lVal = 3; // msoButtonIconAndCaption
// both of the following calls return 0x80020006
hr = PutProperty(vtMineCtl.pdispVal, L"Style", &vtParam);
hr = CallMethod (vtMineCtl.pdispVal,L"PasteFace",NULL,0,NULL);

vtParam.vt = VT_BSTR;
vtParam.bstrVal = ::SysAllocString( L"Mine" );
hr = PutProperty( vtMineCtl.pdispVal, L"Caption", &vtParam );
if( SUCCEEDED(hr) )
{
hr = PutProperty( vtMineCtl.pdispVal, L"Tag", &vtParam );
VariantClear( &vtParam );

.....

The PutProperty for Style and the CallMethod for PasteFace return a
0x80020006 which means that the property and method do not exist on the
object. I have no trouble adding icons to non-popup menus.

Can someone tell me what I have to do to my code here in order to add an
icon to the popup?

--------------------
David Wendt


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top