Uwe Keim
Uwe Keim

Reputation: 40726

Hide a CDialogImpl dialog when user cancels

Using a CDialogImpl derived class as a dialog-based WTL/ATL app, I want to hide the main window when the user clicks the upper right "X" button (or presses Esc or Alt+F4).

Currently the "X" closes the dialog and ends the application.

enter image description here

I want to change this behaviour and only hide the dialog box instead of closing it. Is this possible?

Upvotes: 0

Views: 429

Answers (1)

Mike Kwan
Mike Kwan

Reputation: 24447

I'm not sure if ATL/WTL provides some wrapper for this but in WinAPI, the function you are looking for is ShowWindow, which you would invoke as so:

ShowWindow(hwnd, SW_HIDE);

If you want this to happen when the application is closed, the message you need to handle is WM_CLOSE.

After a quick search, MSDN reveals CWindow::ShowWindow, which is the wrapper I mentioned earlier.

Upvotes: 2

Related Questions