简体   繁体   English

如何用我自己的文件打开对话框替换默认的右键单击上下文菜单

[英]How do I replace the default right click context menu in a file open dialog box with my own

I would like to create a custom File Open dialog where I can replace the default context menu options shown when the user right clicks one of the files in the list, with my own context menu.我想创建一个自定义文件打开对话框,我可以在其中用我自己的上下文菜单替换用户右键单击列表中的一个文件时显示的默认上下文菜单选项。

Based on articles such as this one, and this one, I tried adding:基于诸如this one和this之类的文章,我尝试添加:

UINT CALLBACK OfnHookProc(HWND hDlg, UINT uMsg, UINT wParam, LONG lParam)

and then refer to it using然后使用

ofn.lpfnHook = OfnHookProc;

I guess the ideal solution will be a class derived from OPENFILENAME .我想理想的解决方案是从OPENFILENAME派生的类。 Not sure how.不确定如何。

For the Explorer-style Open dialog box:对于资源管理器样式的打开对话框

  • The default templates are not available for modification .默认模板不可修改
  • The hook procedure does not receive messages intended for the standard controls in the dialog box.挂钩过程不会接收用于对话框中标准控件的消息

So there seems little possibility to replace the default context menu via editing or subclassing the open dialog itself.因此,通过编辑或子类化打开的对话框本身来替换默认上下文菜单的可能性似乎很小。

From the user's perspective, the chief benefit of the common dialog box is its consistent appearance and functionality from application to application.从用户的角度来看,通用对话框的主要好处是其从应用程序到应用程序的一致外观和功能。 Hiding original controls or otherwise changing the intended functionality of the original controls is a less appropriate customization.隐藏原始控件或以其他方式更改原始控件的预期功能是不太合适的自定义。

However, there is a workaround maybe help:但是,有一种解决方法可能会有所帮助:

Add your context menu item to the default one as an addition.将您的上下文菜单项添加到默认项作为附加项。 Like this:像这样:

在此处输入图片说明

Refer to " Creating Cascading Menus with the ExtendedSubCommandsKey Registry Entry " for more detailed information.有关更多详细信息,请参阅“ 使用 ExtendedSubCommandsKey 注册表项创建级联菜单”。

Note: Modifying registry will affect all application instead of only your own application.注意:修改注册表将影响所有应用程序,而不仅仅是您自己的应用程序。 So make sure keep this modification in a mini, required scope.因此,请确保将此修改保留在所需的小型范围内。 For example, if putting this change in HKEY_CURRENT_USER\\Software\\Classes is enough don't put it in HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes .例如,如果将此更改放在HKEY_CURRENT_USER\\Software\\Classes就足够了,请不要将其放在HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes

As mentioned by @remy-lebeau, you can do that using window subclassing as listed below:正如@remy-lebeau 所提到的,您可以使用窗口子类化来做到这一点,如下所示:

  1. get hWnd of the File Open dialog获取文件打开对话框的 hWnd
  2. replace WndProc via SetWindowLong(hWnd, GWL_WNDPROC, ..)通过 SetWindowLong(hWnd, GWL_WNDPROC, ..) 替换 WndProc
  3. after that you will be able to track mouse position and handle WM_RBUTTONDOWN之后,您将能够跟踪鼠标位置并处理 WM_RBUTTONDOWN

To get window handle, you can use FindWindowEx, EnumWindows or even SetWindowsHookEx.要获取窗口句柄,您可以使用 FindWindowEx、EnumWindows 甚至 SetWindowsHookEx。 Don't forget to pass unhandled messages to the original window procedure.不要忘记将未处理的消息传递给原始窗口过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将自己的文件关联添加到“打开方式”上下文菜单中? - How to add my own file association into the “Open with” context menu? 如何添加Windows右键单击上下文菜单项? - How can I add Windows right click context menu items? 如何修复OnRButtonDown()以检测对话框的右键单击? (使用MFC) - How do I fix my OnRButtonDown() to detect right click for my dialog? (using mfc) 如何在列表框上右键单击创建上下文菜单? - How to create a context menu on listbox right click? 如何在 QGraphicsView 中为右键单击创建上下文菜单 - How to create a context menu for right click in QGraphicsView 如何在列表控件中创建右键菜单? - How do I create a right-click menu in a list control? 如何在cimg显示窗口中显示右键菜单? - How do I display a right click menu in a cimg display window? 如何使用我自己的程序打开文件并让它调用另一个程序? - How do I open a file with my own program and have it invoke another program? 电子内部或外部方法来创建自己的右键单击上下文菜单-Windows - Electron internal or external method to create own right click context menu - Windows 如何显示 Windows 资源管理器上下文(右键单击)菜单? - How to show Windows Explorer context (right click) menu?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM