Click here to Skip to main content
15,746,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

What I have tried:


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.
Updated 9-Sep-20 13:45pm

1 solution

I don't have a specific solution but you are on the right track. Ages ago, I made a derived FileOpenDialog class or what ever MFC calls its version and made a custom dialog that included a bitmap preview. That has since been render obsolete but that is what I did for it - added a custom lpfnHook procedure and then I made made message handlers in it to handle things for the previewer. That's one way you can go with it.

I think the recommend method today is to add a shell extension. The open file dialog is calling into the Shell API so it uses the same stuff the Explorer shell does. There are articles here on this topic. I suspect that is it a little more generic than you want go so you have both options. I think.

Yet another option is to make your own fully custom file open dialog and I have done this too. There is a DlgDirList family of functions to help with that. This will give you full control over the right click menu.

Best of luck.
Share this answer
Michael Haephrati 10-Sep-20 7:14am    
DlgDirList - that's a good idea!
Michael Haephrati 10-Sep-20 7:49am    
Rick, if you happen to find some code snippet for hooking File Open dialog box, please let me know.
Rick York 10-Sep-20 13:50pm    
Here is one sample :

The article is lacking but the code is there. I think.
Michael Haephrati 10-Sep-20 14:12pm    
Adding controls is easy. Here is a better example: However, adding a Context Menu and hooking the Shell Extension options is tricky.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900