Solved

Overriding MFC's CFileDialog::OnOK...

Posted on 1998-03-08
6
1,540 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 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