How to add custom menu upon right click on file / folder programmatically in c++ / QT?

我怕爱的太早我们不能终老 提交于 2020-01-10 20:09:31

问题


We have an app which syncs files and folder like the way dropbox does. This is an c++ / QT based installer.

We would like add custom menu in the right click context menu of a file or folder like the way dropbox does in the below screen shot.

We are targeting both windows & Mac platforms. Can anyone suggest me how to start with it?


回答1:


On Mac, you're going to have problems as adding to the general Finder Context Menu has been deprecated.

So, you may be thinking, if it's deprecated, then how do Dropbox do this? From what I've researched in the past, I believe they use code injection to inject into the running Finder application's address space and then an Objective-C feature known as method swizzling to change calling a method to one of their own, which is located in the injected code.

This is all fairly hardcore and very low level, but if you're going to go on that journey, you can start by looking into a library called mach_inject and googling about it. The source code can be found here: -

https://github.com/rentzsch/mach_inject

However, be aware that there are those that believe code-injection is wrong and won't install Dropbox or any other software that uses it. In addition, if you're planning on releasing a product in the Mac Store, I wouldn't expect any application that performs code injection to be allowed.




回答2:


For windows, I could find a complete Shell extension example over here.

http://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens?fid=519&select=3236397&fr=76&df=90&mpp=25&noise=3&prof=True&sort=Position&view=None&spc=Relaxed



来源:https://stackoverflow.com/questions/16516732/how-to-add-custom-menu-upon-right-click-on-file-folder-programmatically-in-c

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