Solved

Subclassed CFileDialog - Double click?

Posted on 1998-09-15
6
865 Views
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...
0
Comment
Question by:Blondie050798
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:jstolan
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.
0
 
LVL 1

Author Comment

by:Blondie050798
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)



0
 
LVL 2

Expert Comment

by:jstolan
ID: 1322145
Hmmm

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.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:Blondie050798
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 :-(
0
 
LVL 2

Accepted Solution

by:
jstolan earned 100 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.
 
CDN_FOLDERCHANGE
 The user opened a new folder or directory.
 
CDN_HELP
 The user clicked the Help button.
 
CDN_INITDONE
 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).
 
CDN_SELCHANGE
 The user selected a new file or folder from the file list.
 
CDN_SHAREVIOLATION
 The common dialog box encountered a sharing violation on the file about to be returned.
 
CDN_TYPECHANGE
 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.
 
CDM_GETFOLDERIDLIST
 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.
 
CDM_GETFOLDERPATH
 Retrieves the path of the current folder or directory for the dialog box.
 
CDM_GETSPEC
 Retrieves the filename (not including the path) of the file currently selected in the dialog box.
 
CDM_HIDECONTROL
 Hides the specified control.
 
CDM_SETCONTROLTEXT
 Sets the text in the specified control.
 
CDM_SETDEFEXT
 Sets the default filename extension for the dialog box.
 


0
 
LVL 1

Author Comment

by:Blondie050798
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 :-)

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now