blog: riddles in programming
Moderators: fgagnon, nikos, Site Mods
thanks for the code Jim. It looks like you are adding a few extra keys like PerceivedType etc which must be vista only -- i can't find HKCR\FileSystemAssociations in XP
my hunch is that the type of menu commands and duplicates depend on the selection. If say you have selected a *.h and a *.cpp file, then you'll get some "duplicates" called OpenWithMSDEV but each belongs to a different filetype, so it is technically correct albeit lame!
I don't get crashes but some funny first chance exceptions errors in kernel32.dll on account of "invalid handles" when the IContextMenu is released. It looks like the magic number is 17: If i pass 17 registry keys or less to CDefFolderMenu_Create2 then all is fine, from 18 and up (ie more and diverse file types) I start getting these exceptions which can cause a crash too
this is regardless of using my "fake"/subclassed folder or not so it looks like a problem with CDefFolderMenu_Create2 which i'll report to m$ and see what they'll come up with
my hunch is that the type of menu commands and duplicates depend on the selection. If say you have selected a *.h and a *.cpp file, then you'll get some "duplicates" called OpenWithMSDEV but each belongs to a different filetype, so it is technically correct albeit lame!
I don't get crashes but some funny first chance exceptions errors in kernel32.dll on account of "invalid handles" when the IContextMenu is released. It looks like the magic number is 17: If i pass 17 registry keys or less to CDefFolderMenu_Create2 then all is fine, from 18 and up (ie more and diverse file types) I start getting these exceptions which can cause a crash too
this is regardless of using my "fake"/subclassed folder or not so it looks like a problem with CDefFolderMenu_Create2 which i'll report to m$ and see what they'll come up with
Is it really necessary to hook the desktop's IShellFolder and provide a custom data object? I just started to implement cross-namespace context menus, but so far I didn't came across the situation that the data object provided by the desktop doesn't contain correct CF_HDROP data. On the other hand I did not yet test on anything other than Windows XP SP2.
I plan to use SHCreateDefaultContextMenu on Vista, because according to the docs you can let this API search for the correct registry keys itself. Do you have any experience with it?
BTW, many thanks Jim and Nikos for sharing all these information.
I plan to use SHCreateDefaultContextMenu on Vista, because according to the docs you can let this API search for the correct registry keys itself. Do you have any experience with it?
BTW, many thanks Jim and Nikos for sharing all these information.
(German translator of xplorer² and editor²)
www.timosoft-software.de - the home of ExplorerTreeView
www.timosoft-software.de - the home of ExplorerTreeView
I took RegMon and checked which parts of the registry Explorer is accessing when I right-click a *.bas file and a *.txt file out of different folders in the search pane (XP SP2).
Case 1) The *.bas file is focused. The following keys were accessed (I picked the important ones):
My code, which is just Jims code translated to C++, accesses these keys:
1) If the file extension belongs to a file class (e. g. txtfile), the extension key (.txt) should NOT be passed to CDefFolderMenu_Create2.
2) The PerceivedType thing should be done before calling CDefFolderMenu_Create2 and the key should be passed. "application" might be a fallback perceived type. (I wonder why CDefFolderMenu_Create2 doesn't seem to try reading HKCR\.bas\PerceivedType)
I implemented both modifications and now I get exactly the same context menus like in search pane. Well, almost - the "rename" verb is missing for some reason.
Now let's hope the code also works for other combinations than *.bas/*.txt.
Case 1) The *.bas file is focused. The following keys were accessed (I picked the important ones):
- HKCR\.bas
- HKCR\VisualBasic.Module
- HKCR\VisualBasic.Module\CurVer
- HKCR\SystemFileAssociations\.bas <- not existing
- HKCR\SystemFileAssociations\application <- not existing
- HKCR\*
- HKCR\AllFileSystemObjects
- --- I think at this point CDefFolderMenu_Create2 is called ---
- HKCR\.txt
- HKCR\txtfile
- HKCR\txtfile\CurVer
- HKCR\txtfile\shell and subkeys
- HKCR\SystemFileAssociations\.txt
- HKCR\.txt\PerceivedType
- HKCR\SystemFileAssociations\text
- HKCR\SystemFileAssociations\text\shell and subkeys
My code, which is just Jims code translated to C++, accesses these keys:
- HKCR\.bas
- HKCR\VisualBasic.Module
- HKCR\VisualBasic.Module\CurVer
- HKCR\SystemFileAssociations\.bas <- not existing
- HKCR\*
- HKCR\AllFileSystemObjects
- --- at this point CDefFolderMenu_Create2 is called ---
- HKCR\SystemFileAssociations\.bas <- not existing
- HKCR\SystemFileAssociations\application <- not existing
- NOTE: For the *.txt file no key seems to be accessed.
- HKCR\.txt
- HKCR\txtfile
- HKCR\txtfile\CurVer
- HKCR\SystemFileAssociations\.txt <- not existing
- HKCR\.txt\PerceivedType <- fallback to extension key
- HKCR\SystemFileAssociations\text
- HKCR\*
- HKCR\AllFileSystemObjects
- --- I think at this point CDefFolderMenu_Create2 is called ---
- NOTE: For the *.bas file no key seems to be accessed.
- HKCR\.txt
- HKCR\txtfile
- HKCR\txtfile\CurVer
- HKCR\SystemFileAssociations\.txt
- HKCR\*
- HKCR\AllFileSystemObjects
- --- at this point CDefFolderMenu_Create2 is called ---
- HKCR\.txt\PerceivedType
- HKCR\SystemFileAssociations\text
- NOTE: For the *.bas file no key seems to be accessed.
1) If the file extension belongs to a file class (e. g. txtfile), the extension key (.txt) should NOT be passed to CDefFolderMenu_Create2.
2) The PerceivedType thing should be done before calling CDefFolderMenu_Create2 and the key should be passed. "application" might be a fallback perceived type. (I wonder why CDefFolderMenu_Create2 doesn't seem to try reading HKCR\.bas\PerceivedType)
I implemented both modifications and now I get exactly the same context menus like in search pane. Well, almost - the "rename" verb is missing for some reason.
Now let's hope the code also works for other combinations than *.bas/*.txt.
(German translator of xplorer² and editor²)
www.timosoft-software.de - the home of ExplorerTreeView
www.timosoft-software.de - the home of ExplorerTreeView
Actually this limit can't even be reached. As Jim said, only the filetype of the focused item is relevant, not all filetypes. E. g. if you have selected the following files:nikos wrote:the problem is that bug when you supply 16+ registry keys, so you should be striving to make the keys you need less, not more!
- Readme.txt
- stdafx.h
- Logfile.log
- Prices.pdf
- HKCR\txtfile
- HKCR\SystemFileAssociations\text
- HKCR\*
- HKCR\AllFileSystemObjects
Works for me, but I'll check on Windows 2000. I'll have to hook IShellFolder anyway, because GetAttributesOf doesn't handle full pIDLs well (that's the reason why I don't get the "rename" menu item).nikos wrote:regarding the CF_HDROP, i also sometimes saw it filled by the desktop's folder but try combining something from c:\ and something from d:\ !
(German translator of xplorer² and editor²)
www.timosoft-software.de - the home of ExplorerTreeView
www.timosoft-software.de - the home of ExplorerTreeView
-
- Member
- Posts: 13
- Joined: 2007 Aug 13, 04:40
I'm currently testing on Vista. So far SHCreateDefaultContextMenu seems to work as expected. I set the punkAssociationInfo, cKeys and aKeys members of DEFCONTEXTMENU to 0 and it looks like the API really does the ugly registry stuff itself.
BTW, currently I'm not hooking the desktop's IShellFolder. The problem with the rename verb turned out to have another reason.
In Debug mode of my app I'll verify that the IDataObject provided by the desktop contains correct CF_HDROP data and throw an assertion if it does not. If I ever come across the situation that the CF_HDROP data is not right, I'll activate the hooking, but so far it seems to be unnecessary.
BTW, currently I'm not hooking the desktop's IShellFolder. The problem with the rename verb turned out to have another reason.
In Debug mode of my app I'll verify that the IDataObject provided by the desktop contains correct CF_HDROP data and throw an assertion if it does not. If I ever come across the situation that the CF_HDROP data is not right, I'll activate the hooking, but so far it seems to be unnecessary.
(German translator of xplorer² and editor²)
www.timosoft-software.de - the home of ExplorerTreeView
www.timosoft-software.de - the home of ExplorerTreeView
-
- Member
- Posts: 13
- Joined: 2007 Aug 13, 04:40
Make sure you try what nikos mentioned. Get a file from two different volumes and make sure that works as well. That is one place is use to fail (I have not revisited this since Vista I was working on XP, Win2k and Win98).In Debug mode of my app I'll verify that the IDataObject provided by the desktop contains correct CF_HDROP data and throw an assertion if it does not. If I ever come across the situation that the CF_HDROP data is not right, I'll activate the hooking, but so far it seems to be unnecessary.
Jim
Strange... This afternoon I did test it with 2 files from different drives and it worked. Now, on another machine but also with XP SP2, it fails and the hook is required.
Jim, earlier in this thread you mentioned you had to override GetAttributesOf() because of SFGAO_CANMOVE and SFGAO_CANCOPY. Have you still implemented it this way or turned it out to be unnecessary meanwhile?
Jim, earlier in this thread you mentioned you had to override GetAttributesOf() because of SFGAO_CANMOVE and SFGAO_CANCOPY. Have you still implemented it this way or turned it out to be unnecessary meanwhile?
(German translator of xplorer² and editor²)
www.timosoft-software.de - the home of ExplorerTreeView
www.timosoft-software.de - the home of ExplorerTreeView
-
- Member
- Posts: 13
- Joined: 2007 Aug 13, 04:40
To make the TortoiseSVN context menu extension and SHMultiFileProperties happy, you also must add CFSTR_SHELLIDLIST data to the IDataObject returned in GetUIObjectOf.
Looks like everything is working now. Only the Send To sub menu seems to cause my IDataObject implementation run into an infinite loop.
(German translator of xplorer² and editor²)
www.timosoft-software.de - the home of ExplorerTreeView
www.timosoft-software.de - the home of ExplorerTreeView
-
- New Member
- Posts: 1
- Joined: 2011 Mar 28, 21:50
-
- New Member
- Posts: 1
- Joined: 2021 Aug 19, 06:45
Re: blog: riddles in programming
Could you may be please provide an actually working example code?nikos wrote: ↑2007 Jul 08, 08:46 here's the comment area for today's blog entry found at:
http://www.zabkat.com/blog/08Jul07.htm
as the comments says "... This is easier said than done but if you have an explorer type of application you most probably have such a class already. " and well I don't as I'm using a Qt based file system browser and want only to add the native windows menu, I'm quite far away and unexperienced with all that windows shell stuff.
Cheers
David X.
Re: blog: riddles in programming
have a look at SHCreateDataObject API. If you search for it in github i'm sure you'll find samples