MFC dialog freezes when it looses focus
I am new to MFC so please bear with me. I have a Dialog that is displayed in full screen on a dual screen monitor. This dialog is instantiated inside another non-modal dialog (when a button is clicked). Something like:
void MyCParentDlg::OnBnClickedButton1()
{
dlg2 = new MyChildNonModalDlg();
dlg2->ShowWindow(SW_SHOW);
}
In the OnInitDialog()
of MyChildNonModalDlg
, ShowWindow(SW_MAXIMIZE)
is invoked to make it the dialog full-screen with no-border. Now, there is a button callback event inside MyChildNonModalDlg
:
void MyChildNonModalDlg::onBnClickedBut2() {
// Display images on the dialog one by one for a very long time
}
While onBnClickedBut2
is running and the dialog is being updated continuously, if I click with my mouse outside the dialog (say on the other screen) meaning when the dialog looses focus , it freezes!
I know this is something perhaps that can be fixed with multi-threading, where the process inside OnBnClickedBut2()
must run inside a thread, but as someone who knows very little about thread, can someone point me to the right direction or provide code examples that can do this?
Use AfxBeginThread
to create new thread inside onBnClickedBut2
. You are not supposed to block UI event handlers. Hope you got it by now.
上一篇: 使用对话框控件而不偷窃焦点
下一篇: MFC对话框失去焦点时会冻结