Article View: borland.public.cppbuilder.nativeapi
Article #6425Re: IContextMenu for Explorer
From: Remy Lebeau (TeamB)
Date: Tue, 17 May 2005 00:50
Date: Tue, 17 May 2005 00:50
94 lines
4005 bytes
4005 bytes
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote in message
news:4289317d@newsgroups.borland.com...
> hMenu = CreatePopupMenu();
Don't forget to call DestroyMenu() when you are done with the menu.
> OleCheck(menu->QueryContextMenu(hMenu, 0, 0, 2, CMF_NORMAL));
You should not specify 0 as the starting menu ID. The minimum ID should be
at least 1. And you should make the last ID much higher than 2, since the
OS may need to add many items to the popup menu.
> however, now the call to GetCommandString() throws 'Not implemented'.
Some menu items simply don't have command strings available, so there is
nothing to retrieve for them.
Also, you need to pass menu item IDs, not indexes, when calling
GetCommandString(). If you need to access an item by index, use
GetMenuItemInfo() to retreive its ID before than calling GetCommandString().
For example, the following works fine for me:
#include <shlobj.h>
#include <utilcls.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TComInterface<IShellFolder> desktop;
ITEMIDLIST* pidl = NULL;
TComInterface<IShellFolder> folder;
TComInterface<IContextMenu> menu;
HMENU hMenu = CreatePopupMenu();
try
{
OleCheck(SHGetDesktopFolder(&desktop));
try
{
OleCheck(desktop->ParseDisplayName(NULL, NULL,
WideString("D:\\"), NULL, &pidl, 0));
OleCheck(desktop->GetUIObjectOf(NULL, 1,
(LPCITEMIDLIST*)&pidl, IID_IContextMenu, NULL, (void**)&menu));
HRESULT hRes = menu->QueryContextMenu(hMenu, 0, 100, 200,
CMF_NORMAL);
OleCheck(hRes);
WORD wLast = LOWORD(hRes);
for(WORD w = 0; w < wLast; ++w)
{
char buffer[50] = {0};
hRes = menu->GetCommandString(w, GCS_VERBA, NULL,
buffer, 49);
if( SUCCEEDED(hRes) )
ShowMessage(AnsiString(w) + ": " +
AnsiString(buffer));
else
{
wchar_t buffer2[50] = {0};
hRes = menu->GetCommandString(w, GCS_VERBW, NULL,
buffer2, 49);
if( SUCCEEDED(hRes) )
ShowMessage(AnsiString(w) + ": " +
AnsiString(buffer2));
}
}
}
__finally
{
if( pidl )
CoTaskMemFree(pidl);
}
}
catch(const Exception &e)
{
ShowMessage(e.Message);
}
if( hMenu )
DestroyMenu(hMenu);
}
> Also QueryContextMenu() requires parameters for first and last command.
> What should I specify when I don't know the number of available
> commands ahead?
That is why you need to call QueryContextMenu() with a larger range of IDs.
QueryContextMenu() returns the highest ID that it actually uses.
Gambit
Technical Details
Message-ID:
<42893f7b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4287f6c1@newsgroups.borland.com> <4288e58b$1@newsgroups.borland.com> <4289317d@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7e49abe43ea24b0d X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4287f6c1@newsgroups.borland.com> <4288e58b$1@newsgroups.borland.com> <4289317d@newsgroups.borland.com> Subject: Re: IContextMenu for Explorer Date: Mon, 16 May 2005 17:50:05 -0700 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <42893f7b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1116290939 68.69.17.41 (16 May 2005 17:48:59 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail