Extending windows explorer context menu

孤者浪人 提交于 2019-12-23 03:41:51

问题


I'm having hard times figuring out why this doesn't work on my computer. I've read this article http://msdn.microsoft.com/en-us/library/bb776820.aspx and tried it, and it works for an unknown file type, but for know such as .bmp it doesn't - I've also deleted other keys under .bmp - didn't help. I've tried this in HKEY_CLASSES_ROOT.bmp and in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bmp I need to implement this in my program so it has custom context menu items on some file types like bmp. btw. I've tried ContextEdit (a freeware program) - also didn't work - any ideas? Maybe something not refreshing (I've tried to reboot - didn't make any changes)?

edit: One update - if I go under Set Default Programs and Windows Photo Viewer for some reason I can't disable it for some file types like .jpg, .bmp, .gif. That's strange...

edit no. 2: now it started working and I have determined the problem - the file associations didn't refresh even after restarting my computer. After I had associated a txt file to a different editor my .bmp menus, icon and default program have changed. So the main question now is - how do I manually refresh file associations using C#?


回答1:


I think I've found a solution for this one, and it goes like this - define:

    [DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);

    const uint SHCNF_IDLIST = 0x0;
    const uint SHCNE_ASSOCCHANGED = 0x08000000;

Then do your code stuff with associations when needed, and after it execute:

    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);

Also if mentioned registry keys don't work try:

    HKEY_CLASSES_ROOT\SystemFileAssociations\extension\Shell\yourcommand


来源:https://stackoverflow.com/questions/8058971/extending-windows-explorer-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!