Solved

Overriding MFC's CFileDialog::OnOK...

Posted on 1998-03-08
6
1,518 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
  • 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 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

13 Experts available now in Live!

Get 1:1 Help Now