Subclassed CFileDialog - Double click?

I have a subclassed cfiledialog which displays an image preview window.  When a file is selected, the window displays it.  Trouble is, when dealing with large files (15MB+) this obviously takes a while, and is annoying when you know which file you want, and simply want to double click on it to load it, without the OnFileNameChange()getting called to display the preview.

I guess what I am saying is that I need to be able to tell when I have a single click or double click in the edit, so that when OnFileNameChange() is called I can either display the preview or ignore it...
Who is Participating?
jstolanConnect With a Mentor Commented:
Ok here it is, but you might not like it

I looked through the CFileDialog documentation and found this.  Fundamentally it says that if you want the WM_NOTIFY messages you have to use a hook procedure to get them.  It shouldn't be too hard if you follow the guidelines carefully.

Explorer-Style Hook Procedures
You can customize an Explorer-style Open or Save As dialog box by providing a hook procedure, a custom template, or both. If you provide a hook procedure for an Explorer-style dialog box, the system creates a dialog box that is a child of the default dialog box. The hook procedure acts as the dialog procedure for the child dialog box. This child dialog box is based on the custom template, or on a default template if none is provided. For more information, see Explorer-Style Custom Templates.To enable a hook procedure for an Explorer-style Open or Save As dialog box, use the OPENFILENAME structure when you create the dialog box. Set the OFN_ENABLEHOOK and OFN_EXPLORER flags in the Flags member and specify the address of an OFNHookProc hook procedure in the lpfnHook member. If you provide a hook procedure and omit the OFN_EXPLORER flag, you must use an OFNHookProcOldStyle hook procedure and you will get the old-style user-interface. For more information, see Customizing Old-Style Dialog Boxes.

An Explorer-style hook procedure receives a variety of messages while the dialog box is open. These include the following:

· The WM_INITDIALOG message and other standard dialog box messages such as the WM_CTLCOLORDLG control color message.

· A set of WM_NOTIFY notification messages indicating actions taken by the user or other dialog box events.

· Messages for any additional controls that you defined by specifying a child dialog template.

In addition, there is a set of messages that you can send to an Explorer-style dialog box to get information or to control the behavior and appearance of the dialog box.

If you provide a hook procedure for an Explorer-style dialog box, the default dialog box procedure creates a child dialog box when the default dialog procedure is processing its WM_INITDIALOG message. The hook procedure acts as the dialog procedure for the child dialog box. At this time, the hook procedure receives its own WM_INITDIALOG message with the lParam parameter set to the address of the OPENFILENAME structure used to initialize the dialog box. After the child dialog finishes processing its own WM_INITDIALOG message, the default dialog procedure moves the standard controls, if necessary, to make room for any additional controls of the child dialog box. The default dialog procedure then sends the CDN_INITDONE notification message to the hook procedure.

The hook procedure receives WM_NOTIFY notification messages indicating actions taken by the user in the dialog box. You can use some of these messages to control the behavior of the dialog box. For example, the hook procedure receives the CDN_FILEOK message when the user chooses a filename and clicks the OK button. In response to this message, the hook procedure can use the SetWindowLong function to reject the selected name and force the dialog box to remain open.

The lParam parameter for each WM_NOTIFY message is a pointer to an OFNOTIFY structure that defines the action. The code member in the header for the OFNOTIFY structure contains one of the following notification codes. CDN_FILEOK
 The user clicked the OK button; the dialog box is about to close.
 The user opened a new folder or directory.
 The user clicked the Help button.
 The system has finished initializing the dialog box, and the dialog box has finished processing the WM_INITDIALOG message. Also, the system has finished arranging controls in the common dialog box to make room for the controls of the child dialog box (if any).
 The user selected a new file or folder from the file list.
 The common dialog box encountered a sharing violation on the file about to be returned.
 The user selected a new file type from the list of file types.

These WM_NOTIFY messages supersede the FILEOKSTRING, LBSELCHSTRING, SHAREVISTRING, and HELPMSGSTRING registered messages used by previous versions of the Open and Save As dialog boxes. However, the hook procedure also receives the superseded message after the WM_NOTIFY message if the WM_NOTIFY processing does not use SetWindowLong to set a nonzero DWL_MSGRESULT value.

To retrieve information about the status of the dialog box or to control the behavior and appearance of the dialog box, the hook procedure can send the following messages to the dialog box. CDM_GETFILEPATH
 Retrieves the path and filename of the selected file.
 Retrieves the item identifier list corresponding to the current folder that the dialog box has open. For more information about item identifier lists, see Item Identifiers and Identifier Lists.
 Retrieves the path of the current folder or directory for the dialog box.
 Retrieves the filename (not including the path) of the file currently selected in the dialog box.
 Hides the specified control.
 Sets the text in the specified control.
 Sets the default filename extension for the dialog box.

If I'm not mistaken the window is actually a list control and not an edit.  I think the message you want to look at is the WM_NOTIFY class which passes messages to the parent from the child control.  Take a look at NM_CLICK and NM_DBLCLICK.
Blondie050798Author Commented:
Rather short answer, but jolted me in the correct direction..
Trouble is the messages never get there..?
I put the following in my message map...

ON_NOTIFY(NM_CLICK, lst2, OnSingleClick)
ON_NOTIFY(NM_DBLCLK, lst2, OnDoubleClick)

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!


I'm not sure why that message wouldn't be received.  I looked back at the documentation and didn't see anything obvious.  I suspect that the CFileDialog base class is handling the message and you may need to override an existing function.

I suppose you've tried overriding OnFileNameChange?

By the way sorry about the short answer, but I haven't tried this exact thing myself.  As you said, I was just trying to point you in the right direction.
Blondie050798Author Commented:
OnFileNameChange() is overridden and being called..but gets called each time a click once for the single click and twice for the double...

I would like to get the click messages (cos it would make my life easy...)  Otherwise I guess I would need to create a thread or timer to check the duration between successive calls to OnFileNameChange()...and based on the duration I can predict that a single click or double click has occurred...seems rather nasty though :-(
Blondie050798Author Commented:
You're right...I don't like it...I've had to write a hock for a filedialog before...I didn't like it then, and I still don't...guess I was looking for a nice clean simple answer that doesn't exist... :-(  Still, 'an answer' is better than none...
Thanks for your help :-)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.