• Advertisement
Sign in to follow this  

MFC app: problem with OnOK OnCancel

This topic is 4877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My app is dialog based, and so the default action for pressing escape or enter is to close it. I overrode both functions to prevent this. Sooo, to close my app I put DestroyWindow in my menu's exit. But when I click on the 'X' of the window it does nothing. What do I need to add to get that to work as well?

Share this post


Link to post
Share on other sites
Advertisement
What I'm looking for is what function gets called when the 'X' is clicked. OnClose apparantly is not it, I just tried it.


void CImagePacker2Dlg::OnClose()
{
DestroyWindow();
}

Share this post


Link to post
Share on other sites
OnClose() is the handler for that. I just tested it by putting a breakpoint in, and it gets hit when I click the 'X'. Did you override DestroyWindow() to change the behaviour? Calling DestroyWindow() from my handler causes the dialog to close.

Share this post


Link to post
Share on other sites
Hrrm.. Does OnClose get called as a result of OnOK or OnCancel? That is the only way I can explain this behavior. My OnClose definitely is not getting hit. I just loaded up a dummy dialog app and I can't seem to figure out still how to make it so that escape and enter don't close the program. FRUSTRATING!

Share this post


Link to post
Share on other sites
OnOk and OnCancel both call EndDialog(), which calls OnDestroy(). OnClose() calls OnCancel() internally. I got an app working by overriding OnOK and OnCancel(), and doing nothing in the handlers, then adding a button which calls DestroyWindow() when clicked. It works fine.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I am facing the same problem. Do you have a solution?

Share this post


Link to post
Share on other sites
If you prevent closing dialog from OnOK() and OnCancel() finctions, you also mast handle WM_CLOSE message, and from it handler call DestroyWindow()

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement