Solved

Overriding MFC's CFileDialog::OnOK...

Posted on 1998-03-08
6
1,551 Views
Last Modified: 2008-02-01
Hi,

I have created an exteded version of the CFileDialog by adding a template to the bottom of it. I now want to override the OnOK function for this dialog so that I can do some validation code in my program. I find that I cannot step into or hit the overridden OnOK function for some unknown reason. My definition of this funciton in the derived CFileDialog class is:

virtual void OnOK();

The implementaion is:

void CMyFileDialog::OnOK()
{
    // do something
    CFileDialog::OnOK();
}

Can anyone tell me how to properly overide the OnOK button for this dervied class ?
0
Comment
Question by:zafar030898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1183245
The function will get called if the dialog has a button control in it with the id of IDOK. Are you sure you did not change the id of the button in the template? What does calling GetDlgItem(IDOK) return in a member function of the dialog? Does it return a valid (non-null) value? If it does, then there could be something wrong with your message map for the class.

Another possibility is to look at your dialog with Spy++ which tells you the IDs of window as well as where and what messages are generated. Use that as a debugging tool.

0
 

Author Comment

by:zafar030898
ID: 1183246
Hi,

What I am trying to override is the Open button's OnOK function which is present on the File Open dialog box. I am not using anyother buttons on my customized template with the same ID. I also used to find the ID of the open button, which is given as 1 (=IDOK) by the Spy++.

I am still wondering why when the Open button is pressed, by derived class's OnOK member function doens't get hit...
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1183247
Have you verified that when you press the OK button that your dialog is getting the WM_COMMAND message?


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:zafar030898
ID: 1183248
Hi,

I used the classwizard to create a OnCommand function to see the messages passed from the dialog. When I hit a button on my child (i.e., the template added to the CFileDialog), the OnCommand function is hit. But when I Press the OK button present on the File Dialog itself, the OnCommand function is not hit. Any idea why ??
0
 

Author Comment

by:zafar030898
ID: 1183249
Hi,

I used the classwizard to create a OnCommand function to see the messages passed from the dialog. When I hit a button on my child (i.e., the template added to the CFileDialog), the OnCommand function is hit. But when I Press the OK button present on the File Dialog itself, the OnCommand function is not hit. Any idea why ??
0
 

Expert Comment

by:FranzReitner
ID: 5543302
Create a new class derived from CDialog and try to sublasswindow with the parent of your template dialog. Then your OnOK is called.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

751 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