Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top