🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5886

Re: Shell popup menu

#5886
From: qyte
Date: Thu, 23 Jun 2005 01:42
112 lines
4569 bytes
i have made the following project based on your reply.

LPITEMIDLIST GetNextItemID(LPCITEMIDLIST pidl)
{
         if( pidl == NULL )
             return NULL;
         int cb = pidl->mkid.cb;
         if( cb == 0 )
             return NULL;
         pidl = (LPITEMIDLIST) (((LPBYTE) pidl) + cb);
         return (pidl->mkid.cb == 0) ? NULL : (LPITEMIDLIST) pidl;
}

UINT GetSize(LPCITEMIDLIST pidl)
{
         UINT cbTotal = 0;
         if( pidl != NULL )
         {
             cbTotal += sizeof(pidl->mkid.cb);
             while( pidl != NULL )
             {
                 cbTotal += pidl->mkid.cb;
                 pidl = GetNextItemID(pidl);
             }
         }
         return cbTotal;
}

LPITEMIDLIST MakeCopy(LPCITEMIDLIST pidl)
{
         LPITEMIDLIST pidlTemp = (LPITEMIDLIST) pidl;
         UINT cb = GetSize(pidl);
         LPITEMIDLIST pidlRet = (LPITEMIDLIST) CoTaskMemAlloc(cb);
         if( pidlRet != NULL )
             CopyMemory(pidlRet, pidl, cb);
         return pidlRet;
}

LPITEMIDLIST GetChildID(LPITEMIDLIST pidl)
{
         LPITEMIDLIST pidlRet = NULL;
         if( pidl != NULL )
         {
             if( pidl->mkid.cb )
             {
                 LPITEMIDLIST pidlNext = pidl;
                 while( pidlNext )
                 {
                     pidl = pidlNext;
                     pidlNext = GetNextItemID(pidl);
                 }
                 pidlRet = MakeCopy(pidl);
                 if( pidlRet == NULL )
                     return NULL;
                 pidl->mkid.cb = 0;
             }
         }
         return pidlRet;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
         if(OpenDialog1->Execute())
                 Label1->Caption=OpenDialog1->FileName;
         else
                 Label1->Caption="";
}



void __fastcall TForm1::Button2Click(TObject *Sender)
{
         if(Label1->Caption.IsEmpty())
                 return;
         IShellFolder *Desktop = NULL;
         if( SUCCEEDED(SHGetDesktopFolder(&Desktop)) )
         {
             LPITEMIDLIST pidl = NULL;
             ULONG ulEaten = 0;

             WideString Path = Label1->Caption;
             if( SUCCEEDED(Desktop->ParseDisplayName(NULL, NULL, 
Path,&ulEaten, &pidl, NULL)) )
             {
                 LPITEMIDLIST pidlChild = GetChildID(pidl);
                 if( pidlChild != NULL )
                 {
                     IShellFolder *ParentFolder = NULL;
                     if( SUCCEEDED(Desktop->BindToObject(pidl, 
NULL,IID_IShellFolder, (LPVOID*)&ParentFolder)) )
                     {
                         IContextMenu *menu = NULL;
                         if( SUCCEEDED(ParentFolder->GetUIObjectOf(NULL, 
1,(LPCITEMIDLIST*)&pidlChild, IID_IContextMenu, NULL, (LPVOID*)&menu)) )
                         {
                             Label1->Caption 
=menu->QueryContextMenu(PopupMenu->Handle, 0, 1, 100, CMF_NORMAL);
                             menu->Release();
                             PopupMenu->Popup(10, 10);
                         }
                     }
                     ParentFolder->Release();
                 }
             }
             CoTaskMemFree(pidl);
         }
         Desktop->Release();
}

the problem is that the popupmenu doesn't get any item in it at all.
there must be something wrong inside your code. the Label1 after i run 
button 2 takes the value 114. is it right???
Technical Details
Message-ID: <42ba1384@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.wiretrip.org!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42b77365@newsgroups.borland.com> <42b781a4@newsgroups.borland.com> <42b9471a$1@newsgroups.borland.com> <42b9c800$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,49d4c9bc0c0cea4b
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 23 Jun 2005 04:42:31 +0300
From: qyte <gyte@vivodinet.gr>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Shell popup menu
References: <42b77365@newsgroups.borland.com> <42b781a4@newsgroups.borland.com> <42b9471a$1@newsgroups.borland.com> <42b9c800$1@newsgroups.borland.com>
In-Reply-To: <42b9c800$1@newsgroups.borland.com>
Content-Type: text/plain; charset=windows-1253; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 83.171.210.195
Message-ID: <42ba1384@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1119490948 83.171.210.195 (22 Jun 2005 18:42:28 -0700)
Lines: 112
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.wiretrip.org!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail