简体   繁体   中英

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:

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 . 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.

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 .

As mentioned by @remy-lebeau, you can do that using window subclassing as listed below:

  1. get hWnd of the File Open dialog
  2. replace WndProc via SetWindowLong(hWnd, GWL_WNDPROC, ..)
  3. after that you will be able to track mouse position and handle WM_RBUTTONDOWN

To get window handle, you can use FindWindowEx, EnumWindows or even SetWindowsHookEx. Don't forget to pass unhandled messages to the original window procedure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM