MFC app: problem with OnOK OnCancel
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?
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();}
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.
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!
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.
If you prevent closing dialog from OnOK() and OnCancel() finctions, you also mast handle WM_CLOSE message, and from it handler call DestroyWindow()
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement