Article View: borland.public.cppbuilder.nativeapi
Article #9177Problems with InsertMenu
From: MortZ
Date: Thu, 29 Jul 2004 21:03
Date: Thu, 29 Jul 2004 21:03
105 lines
4419 bytes
4419 bytes
Hi...
Im trying to extend the default Shell's context menu by inserting an popup
menu. So far I have been able to create the menu and insert it to the shell,
however the GetCommandString and InvokeCommand are not working. I have
revisted the documentation on several API functions
(GetCommandString,InvokeCommand,InsertMenu,QueryContextMenu,SetMenuItemBitma
ps) but I cant figure out what is going on. Can anyone help me?...
My best regards...
<MortZ>
By the way... ActiveX is registered and ClassID is already in the registry
here is the code...
//On constructor, create the menu from a file
//--------------------------------------------------------------------------
-
TMyContextMenuExtensionImpl::TMyContextMenuExtensionImpl()
{
sphereNumber=0;//member of TMyContextMenuExtensionImpl
tempMenu=CreatePopupMenu();//member of TMyContextMenuExtensionImpl
//...opens files, assigns memory to pointers...
while(!feof(ptrFile))
{
dataPtr->LoadFromFile(ptrFile);
InsertMenu(tempMenu,sphereNumber,MF_STRING|MF_BYPOSITION,sphereNumber,dataPt
r->SystemString().c_str());
sphereNumber++;
}
//...deletes pointers, closes file, etc
}
//--------------------------------------------------------------------------
--
STDMETHODIMP TMyContextMenuExtensionImpl::QueryContextMenu(HMENU hmenu, UINT
indexMenu, UINT idFirstCmd,
UINT idLastCmd, UINT uFlags)
{
HBITMAP m_Bmp;
UINT cmd = idFirstCmd;
if (uFlags & CMF_DEFAULTONLY)
return MAKE_HRESULT(SEVERITY_SUCCESS,FACILITY_NULL,0);
m_Bmp = LoadBitmap (_Module.GetModuleInstance(),"MENUIMAGE");
tempMenuIndex=indexMenu;
InsertMenu (hmenu,indexMenu,MF_BYPOSITION|MF_POPUP,(UINT)tempMenu,"Send
to an e-Sphere"); //not sure how to get its cmdID for the GetCommandString
due to the fact that its a PopUp
SetMenuItemBitmaps (hmenu, indexMenu, MF_BYPOSITION, m_Bmp, m_Bmp);
return MAKE_HRESULT(SEVERITY_SUCCESS,FACILITY_NULL,2);
};
//--------------------------------------------------------------------------
--
STDMETHODIMP TMyContextMenuExtensionImpl::GetCommandString(UINT idCmd, UINT
uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax )
{
HRESULT hResult;
USES_CONVERSION;
if (idCmd > sphereNumber+1) //not sure if this sentence is correct
return E_INVALIDARG;
//Text is never copied, don't know why....
switch(uFlags)
{
case GCS_HELPTEXT:
{
LPCTSTR HelpMessage;
if(idCmd < sphereNumber)
HelpMessage = "Sends the document to an e-Sphere";
// We need to be able to handle either ASCII and Unicode text.
if (uFlags & GCS_UNICODE )
// Cast to LPWSTR and handle Unicode text
lstrcpynW((LPWSTR)pszName,T2CW(HelpMessage),cchMax);
else
// Handle ANSI text
lstrcpynA(pszName,T2CA(HelpMessage),cchMax);
hResult = S_OK;
}
break;
}
return hResult;
}
//--------------------------------------------------------------------------
-
STDMETHODIMP
TMyContextMenuExtensionImpl::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
{
HRESULT hResult;
WORD cmdId;
if(HIWORD(pCmdInfo->lpVerb)==0)
cmdId = LOWORD(pCmdInfo->lpVerb);
if(cmdId > sphereNumber) //not sure if thisone is correct
return E_INVALIDARG;
AnsiString Operation = cmdId;
if(Operation == "Send to an e-Sphere")
{
MessageBox (pCmdInfo->hwnd, "Command
Invoked","Example",MB_ICONINFORMATION );
hResult = S_OK;
}
return hResult;
}
Technical Details
Message-ID:
<41096618$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a95d7ac252ea4241,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "MortZ" <rmorteo@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Problems with InsertMenu Date: Thu, 29 Jul 2004 14:03:24 -0700 Lines: 107 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 158.97.22.182 Message-ID: <41096618$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1091135000 158.97.22.182 (29 Jul 2004 14:03:20 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail