Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Subclassed CFileDialog - Double click?

Posted on 1998-09-15
Medium Priority
Last Modified: 2013-11-20
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...
Question by:Blondie050798
  • 3
  • 3

Expert Comment

ID: 1322143
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.

Author Comment

ID: 1322144
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)


Expert Comment

ID: 1322145

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.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 1322146
OnFileNameChange() is overridden and being called..but gets called each time a click occurs..ie. 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 :-(

Accepted Solution

jstolan earned 200 total points
ID: 1322147
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.


Author Comment

ID: 1322148
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 :-)


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question