It is currently Thu Mar 28, 2024 10:10 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sat Apr 25, 2015 6:57 am 
Offline

Joined: Sat Apr 25, 2015 6:33 am
Posts: 5
I am a big fan of classic shell; I am developing a tool and am trying to replicate a little of what classic shell is able to do via right-click context menus. (Specifically, I am merging dnGrep with VoidSoft's "Everything" instant hard drive search.) Have spent a few days reading and researching everything, and have looked through shell code as well, but not finding a solution; hoping for a pointer.

Specifically, I can create a context menu on an item much as explorer does, the context menu appears and operates via code like this:

if (SUCCEEDED(GetUIObjectOfFile(hwnd, L"C:\\temp\\somefile.txt",
IID_IContextMenu, (void**)&pcm))) {
HMENU hmenu = CreatePopupMenu();
if (hmenu) {
if (SUCCEEDED(pcm->QueryContextMenu(hmenu, 0,
SCRATCH_QCM_FIRST, SCRATCH_QCM_LAST,
CMF_NORMAL))) {
int iCmd = TrackPopupMenuEx(



This works, but the menu I get is minimal. I notice that I do not get any of the menu items for any shell extensions that are in the ContextMenuHandler area of the registry. In short, when you right click on items in Explorer or Classic shell, you get my minimal menu, but also the installed ShellExtension items (like 7-Zip, winzip, toirtoise GIT, etc.). What am I missing such that I can not bring these items up in my context menu?


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 7:15 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5333
I don't know why you are not getting the rest of the verbs. Maybe you are not initializing COM correctly for the thread, so they can't be created?

Also, you may be getting them but they may not display correctly. For that to work you need to forward the messages to IContextMenu2. http://blogs.msdn.com/b/oldnewthing/arc ... 34739.aspx

To be sure, look at the number of menu items using GetMenuItemCount(hmenu) to see if it matches what you see on screen. If you have fewer items on screen then in hmenu, then some items just don't draw.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 7:55 am 
Offline

Joined: Sat Apr 25, 2015 6:33 am
Posts: 5
Yeah, count is returning 10 items, I actually have 11 on the menu (perhaps one of the items is special, maybe "properties"). I have about 3 or 4 different implementations of this menu code from different open source projects, tutorials, etc. And most these are using IContextMenu3 and 4 as I understand these are important for processing messages and owner draw. But in every case, sample and approach, all applications just popup the smaller menu. I noticed the things that are missing in my menu are all thins that are all in */ContextMenuHandlers in the registry..3rd party shell extensions. So maybe these are shortcut extensions and property sheet extensions, but I would still think these should popup. So it is a real mystery...tried on multiple machines, always the same.

Could it have something to do with the parent of the item maybe? I notice all the shell functions are very focused on the parent folder of the object. In my case, I have isolated files and am not getting to them recursively from the parent. I

Classic Shell DOES bring up the entire menu. When you search in classic shell,the files and objects are assembled,and right-clicking them does bring up the full menu. But I have not isolated the exact chain of events in classic shell yet. So far I don't see much of a difference. Really stumped on this.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 7:58 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5333
How are you initializing COM?


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 8:00 am 
Offline

Joined: Sat Apr 25, 2015 6:33 am
Posts: 5
I'd add that Raymond Chen's blog (that you link to) is the original source I am using. That also brings up just the truncated menu. I've been back and forth through his 11 part tutorial.

I think what is happening is that I am supposed to "compose" the different menus together, ie, cocreate all the exentsions, query their context menu and merge them all. Raymond mentioned this. Perhaps I should be going through the registry and doing that...I think that'd work, however I don't see any other examples or samples every doing this.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 8:02 am 
Offline

Joined: Sat Apr 25, 2015 6:33 am
Posts: 5
Initializing COM with CoInitialize(0); Not good?

Interesting behavior when I play around there, though...If I call CoInitializeEx(0, COINIT_MULTITHREADED) instead of APARTMENT, one of the menu items (a third party one) doesn't appear. So Maybe it has something to do with COM initialization...but there are only two ways to initialize things that I know of.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 8:18 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5333
Yeah, my guess was that you are running in multithreaded apartment, which would trip some of the shell extensions which are designed to run single-threaded.
But if you do CoInitialize(NULL) it should be fine.

I don't know what else to tell you. There is nothing more to it, nothing to concatenate manually. Take a look at the Classic Shell sources and try to isolate the context menu code from MenuCommands.cpp.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2015 8:26 am 
Offline

Joined: Sat Apr 25, 2015 6:33 am
Posts: 5
Yeah, I will really go through MenuCommands and see if I can isolate anything. I bet it has to do with the PIDL or object. I am starting from a string filename, getting the PIDL, using SHParseDisplayName, and then pulling up a context on that. I bet that that PIDL is somehow different (relative vs absolute) or something subtle like that. I really appreciate the help here. If I get this figured out, I will post the result.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group, Almsamim WYSIWYG Classic Shell © 2010-2016, Ivo Beltchev.
All right reserved.