Can´t access close button in a modeless cdialog
-
Hello I use a modeless CDialog to display some CProgessCtrl controls. It has a Close button which i want to use to abort a loop. The progress controls of the modeless dialog are updated during this loop. The constructor of the dialog is
CDialogVorgang::CDialogVorgang(CWnd* pParent /*=NULL*/) : CDialog() { Create(CDialogVorgang::IDD, pParent); //{{AFX_DATA_INIT(CDialogVorgang) //}}AFX_DATA_INIT }
and i initialize it with// Modeless dialog init CDialogVorgang* pDlgVorgang = new CDialogVorgang(); pDlgVorgang->SetWindowText("Datenbank Aktualisierung"); pDlgVorgang->m_cProgressVorgang.SetRange(0, 3); pDlgVorgang->m_cProgressGesamt.SetRange(0, v_oaV->GetSize()); // Show Dialog pDlgVorgang->ShowWindow(SW_SHOW); // is somehow necessary to display static text (??) pDlgVorgang->UpdateWindow(); // loop for (int nv = 0; nv < v_oaV->GetSize(); nv++) { pDlgVorgang->IncGesamt(); pDlgVorgang->ResetVorgang(); pDlgVorgang->IncVorgang(); ..... }
The dialog shows up, and the progess controls are adjusted correctly(in the functions IncGesamt, ResetVorgang etc), but i can´t press the cancel button during the loop. Only AFTER the loop has stopped i can close the dialog. It´s also strange that i had to include the UpdateWindow function. Without it static text would not have showed up, even the cancel button was invisible. I added for testing a windowproc message handling function to my modeless cdialog class, but during the loop it is never called. Is it possible that the loop - and thus the adjustment of the progess controls - starts to quickly before the window is registered? Do i have to wait a bit, and if so, how? Thank you for any help niklas -
Hello I use a modeless CDialog to display some CProgessCtrl controls. It has a Close button which i want to use to abort a loop. The progress controls of the modeless dialog are updated during this loop. The constructor of the dialog is
CDialogVorgang::CDialogVorgang(CWnd* pParent /*=NULL*/) : CDialog() { Create(CDialogVorgang::IDD, pParent); //{{AFX_DATA_INIT(CDialogVorgang) //}}AFX_DATA_INIT }
and i initialize it with// Modeless dialog init CDialogVorgang* pDlgVorgang = new CDialogVorgang(); pDlgVorgang->SetWindowText("Datenbank Aktualisierung"); pDlgVorgang->m_cProgressVorgang.SetRange(0, 3); pDlgVorgang->m_cProgressGesamt.SetRange(0, v_oaV->GetSize()); // Show Dialog pDlgVorgang->ShowWindow(SW_SHOW); // is somehow necessary to display static text (??) pDlgVorgang->UpdateWindow(); // loop for (int nv = 0; nv < v_oaV->GetSize(); nv++) { pDlgVorgang->IncGesamt(); pDlgVorgang->ResetVorgang(); pDlgVorgang->IncVorgang(); ..... }
The dialog shows up, and the progess controls are adjusted correctly(in the functions IncGesamt, ResetVorgang etc), but i can´t press the cancel button during the loop. Only AFTER the loop has stopped i can close the dialog. It´s also strange that i had to include the UpdateWindow function. Without it static text would not have showed up, even the cancel button was invisible. I added for testing a windowproc message handling function to my modeless cdialog class, but during the loop it is never called. Is it possible that the loop - and thus the adjustment of the progess controls - starts to quickly before the window is registered? Do i have to wait a bit, and if so, how? Thank you for any help niklasThe problem with the button is that you are getting all the CPU occupied with your loop (take a look at the task administrator) and then you can press the button but it won't be able to be processed until the exit of your loop. If you want to solve it think about creating a thread in order to be able to update the progress ctrls while you'll be able to cancel the process. Remember that if you want to handle multiple threads you must control the secondary effects. ----------------------------------------------------------- It's strange that the static text is not displayed... I can only think about you have any other control over it and that only when you repaint it it can be shown...
-
The problem with the button is that you are getting all the CPU occupied with your loop (take a look at the task administrator) and then you can press the button but it won't be able to be processed until the exit of your loop. If you want to solve it think about creating a thread in order to be able to update the progress ctrls while you'll be able to cancel the process. Remember that if you want to handle multiple threads you must control the secondary effects. ----------------------------------------------------------- It's strange that the static text is not displayed... I can only think about you have any other control over it and that only when you repaint it it can be shown...
But isn´t a modeless dialog a "standalone" thread? I mean doesn´t modeless mean that it runs independent from any parent as an individual thread? niklas
-
But isn´t a modeless dialog a "standalone" thread? I mean doesn´t modeless mean that it runs independent from any parent as an individual thread? niklas
-
But isn´t a modeless dialog a "standalone" thread? I mean doesn´t modeless mean that it runs independent from any parent as an individual thread? niklas