MFC GUI
-
Dear All, I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons. Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times. Many thanks in advance.
-
Dear All, I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons. Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times. Many thanks in advance.
-
It is strange that a dialog uses this much memory... :( What operation is done to use this much memory? Are you freeing them proper?
- ns ami -
I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is :
//in button1 Dialog1 dlg1 = new Dialog1(); OnCancel();//to close the current dialog dlg1->DoModal(); //in button2 Dialog2 dlg2 = new Dialog2(); OnCancel();//to close the current dialog dlg2->DoModal(); //in button3 Dialog3 dlg3 = new Dialog3(); OnCancel();//to close the current dialog dlg3->DoModal(); //in button4 Dialog4 dlg4 = new Dialog4(); OnCancel();//to close the current dialog dlg4->DoModal();
-
I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is :
//in button1 Dialog1 dlg1 = new Dialog1(); OnCancel();//to close the current dialog dlg1->DoModal(); //in button2 Dialog2 dlg2 = new Dialog2(); OnCancel();//to close the current dialog dlg2->DoModal(); //in button3 Dialog3 dlg3 = new Dialog3(); OnCancel();//to close the current dialog dlg3->DoModal(); //in button4 Dialog4 dlg4 = new Dialog4(); OnCancel();//to close the current dialog dlg4->DoModal();
bhanu_8509 wrote:
new Dialog1();
If you are creating dialog using new, then in each button click, a new instance of dialog will be created. It might be the reason of memory leak. I think you need to create them once, and reuse it again and again.
- ns ami -
-
bhanu_8509 wrote:
new Dialog1();
If you are creating dialog using new, then in each button click, a new instance of dialog will be created. It might be the reason of memory leak. I think you need to create them once, and reuse it again and again.
- ns ami -
please tell me how to do this. i cannot create a global object to each and every dialog. frankly I dont know how to create global objects which can be accessed in other dialogs. thanks.
-
Dear All, I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons. Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times. Many thanks in advance.
I'm not certain I understand correctly what you want to achieve. I don't have iTunes in front of me; and I don't see what you mean by "clicks on a button at the right panel". Me think it's quite moronic to call DoModal() recursively. If you want to create and display N dialogs M number of times, you'd better use modeless dialogs and be conscious about managing the memory (when you create and destroy the dialogs).
-
I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is :
//in button1 Dialog1 dlg1 = new Dialog1(); OnCancel();//to close the current dialog dlg1->DoModal(); //in button2 Dialog2 dlg2 = new Dialog2(); OnCancel();//to close the current dialog dlg2->DoModal(); //in button3 Dialog3 dlg3 = new Dialog3(); OnCancel();//to close the current dialog dlg3->DoModal(); //in button4 Dialog4 dlg4 = new Dialog4(); OnCancel();//to close the current dialog dlg4->DoModal();
Why not...
void CMyFirstDialog::OnButtonOne ()
{
EndDialog (ID_BUTTON1); // CMyFirstDialog::DoModal () now returns ID_BUTTON1.
}....
...
CDialog *pDlg = new CMyFirstDialog ();
int nReturn = 0;
while (pDlg)
{
nReturn = pDlg->DoModal ();delete pDlg; // tidy up pDlg = NULL; switch (nReturn) { case ID\_BUTTON1: pDlg = new CFirstDlg; break; case ID\_BUTTON2: pDlg = new CSecondDlg; break;
....
}
}
ASSERT(!pDlg);OK, that was very quick and hacky - with no real error checking, but I hope it gives you an idea. The main difference is you wait till one dialog is finished and tidied up, *then* move on to the next one. Other wise, they just stack one on top of the other... Iain. switch (
Codeproject MVP for C++, I can't believe it's for my lounge posts...
modified on Tuesday, January 27, 2009 9:54 AM
-
I'm not certain I understand correctly what you want to achieve. I don't have iTunes in front of me; and I don't see what you mean by "clicks on a button at the right panel". Me think it's quite moronic to call DoModal() recursively. If you want to create and display N dialogs M number of times, you'd better use modeless dialogs and be conscious about managing the memory (when you create and destroy the dialogs).
No I dont want to use modeless dialogs. I will try with Ian suggestion and get back to you all. Thanks.
-
please tell me how to do this. i cannot create a global object to each and every dialog. frankly I dont know how to create global objects which can be accessed in other dialogs. thanks.
For such an application a main dialog/window should be there to track these button selections... So that these kind of recursive DoModal can be avoided. A sample... not perfect but only to get the idea.
void CMainDlg::ShowDlgs() // my own function
{
for( ;; )
{
int nNextDlg = 1;
switch( nNextDlg )
{
case 1:
{
Dialog1 dlg;
nNextDlg = dlg.DoModal();
}
case 2:
{
Dialog2 dlg;
nNextDlg = dlg.DoModal();
}
// and so on...
// ...
case ID_EXIT: // = 100 or something else... (ID for exit the application/loop)
return;
}
}
}Better is to make the use of user/registered message communication between parent (main dialog/window) and child dialogs (Dialog1, Dialog2, etc.), but I don't know exactly what you are trying to do.
- ns ami -