Class(Child window )destructor not getting called - c++

I have created a window which has a toolbar with some icons, and I launch one more window clicking on the available icon from the main window.
First window is created using CreateWindowEx method.
the one I click using an icon is created using dialog resource.
So without closing dialog, I directly close the main window. I see that dialog window is not getting closed.
When I debug, control does not come to destructor of second window.
When I close them individually (i.e dialog first) and then main window next,then everything is fine.
Please help,that what might be missing when I close the main window.
I mean class desctructor is not getting called.

Handle your main window's message WM_CLOSE and check, whether the dialog window is open or not. If dialog window is open, just close it using the handle you got returned while loading it from resources.

Related

How to keep dialogs on top of main window always on top in Qt?

I modified a Qt application to set main window to always be on top using the setWindowFlags(Qt::WindowStaysOnTopHint);. Now all of the dialogs appear underneath the main window, and the app gets "locked", as you need to close the modal to continue, but the modal is behind the always on top window. I did fix the one dialog by using dialog->setWindowFlags(Qt::WindowStaysOnTopHint);. Does this mean I have to do the same for every dialog? Or is ther an easier or proper way to set the main window always on top?

Ghost Window/Bitmap lingers after closing window - MFC SDI

Environment: MFC frame based SDI application
Problem: After closing modal dialog boxes, the bitmap stays displayed/the window beneath doesn't repaint.
Dialog creation:
PortSettings Dlg;
Dlg.DoModal();
I've tried explicitly setting OnCancel() for the dialog class,
void PortSettings::OnCancel()
{CDialog::OnCancel();}
tried calling RedrawWindow from the parent window and the Dialog OnCancel.
This issue happens for all the dialog boxes, and other modal windows that open (Like a file browser) I assume because I am using MFC I've somehow interfered with the underlying Window Proc but I'm not sure how to investigate or what to try.
Solution was multifaceted:
Dialog Window Properties affect the image lingering - in my case, it was necessary to change the dialog frame to "thin" style.
After the Dlg.DoModal() call, call ParentWnd->RedrawWindow(). In the Parent Window's OnPaint, I added a fillSolidRect to repaint the background white. This section is controlled with Boolean logic to only repaint immediately after a dialog closes to avoid flickering.

Application-switching window as a modal window

It is possible to set application-switching window as a Modal window (see definition)?
I mean, this window appears when I press Alt+Ctrl+Tab button at the same time and allows me navigate between opened applications typing "tab" key.
The problem appears when I push/click outside the window (Application-switching window lost focus and disappears).
Are there any way to avoid this problem in C++ MFC? I have tried calling:
CWnd* appSwitchingWnd = GetTopWindow();
appSwitchingWnd .SetFocus();
But it doesn't works...
I will appreciate any kind of help.

When called ShowWindow(SW_HIDE) in OnClose method has painting issues MFC

I've created a Modaless dialog inside a dialog A which displays some content. I've overridden ONClose() event of Modalless dialog and hidden the modaless dialog inside it and sends the message to dialog A to load the content again. Now the problem is whenever I've launched the modaless dialog and moved that dialog inside the main dialog and then closed the dialog. The portion of the dialog displayed inside the dialog A is not re-painted.
In Debugging I found that Dialog A is actually painted after modaless dialog got closed in the client area of Dialog A and then after the On Close Event done in Modaless dialog, the portion of the modaless dialog which has painted is lost and that portion is background as white( I've handled EraseBackgroung to white).
Any suggestion would be helpful.
Thanks

Hide main MFC window while modal dialog is active?

I have a native C++ MFC app. It has a main window based on CWnd, and user action can create a modal dialog. While the dialog is active, I want the main window to disappear, the dialog to be visible, and the main window's icon to remain in the task bar.
How can I accomplish this?
If I hide the main window (ShowWindow(SW_HIDE)), the task bar icon disappears. If I minimize the main window (SW_MINIMIZE), the icon remains. However, since the dialog is owned by the main window, this also hides the dialog.
After the dialog is created, clicking on the task bar icon makes the dialog visible. Naturally, I do not want to require the user to do this.
Even if I insert ShowWindow(SW_SHOW) in the dialog's OnInit handler, the dialog remains not visible. Spy++ shows that its visible bit is set, though. Same is true if I add SetWindowActive to OnInit.
I am not interested in changing the UI design. While the dialog is active, the user interacts only with it, and is not interested in anything in the main window. Therefore, the main window should disappear.
Using Windows VS2005 under WinXP32.
Well, in the block of code where you create the dialog and show it modal, you can do whatever you want to the main window of your app (show/hide) as long as you make the desktop window the parent of your dialog. Usually, the constructor for CDialog and derivatives takes a default argument of NULL for the parent window in which the framework ends up substituting AfxGetMainWnd(). Instead pass CWnd::GetDesktopWindow() as the parent of your dialog and then you should probably be able to hide your main window. However, you still might have a problem with the taskbar--but I'll let someone else give hints since I know nothing offhand about it.
In OnInitDialog, add following codes
//Set windows size zero, the windows disappear.
MoveWindow(0,0,0,0);
//If you want it invisible on taskbar. add following codes.
DWORD dwStyle = GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
dwStyle &=~WS_EX_APPWINDOW;
dwStyle |= WS_EX_TOOLWINDOW;
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, dwStyle);
You're fighting the OS. A modal dialog, by definition, disables but does not hide the "main" (parent) window. If you wanted another window, make a second one, but don't tell the OS to treat it as a modal dialog over the first window.
Perhaps you can resize the main window to a really small size and always keep it behind the modal dialog.