Hi, I have added a new dialog box to my MFC application, I am having trouble getting it to open up when pressing a button on my first Dialog, can anyone help me with this.
Thanks.
Hi, I have added a new dialog box to my MFC application, I am having trouble getting it to open up when pressing a button on my first Dialog, can anyone help me with this.
Thanks.
Compiler == Visual C++ 6.0"Come Out Fighting."
One solution is DoModal().
Kuphryn
I am not using MFC, so I don't know if this will help but here is how I am doing it. (doesn't quite work with full screen app though).
The DialogBox command opens the new dialog so just put that in your message handeling routine for the first dialog. Again I do not know about MFC so just ignore this if it doesn't apply.Code:if (KEY_DOWN(VK_BACK) || keyboard_state[DIK_BACK]) { if (!WINDOWED_APP) { ShowWindow(main_window_handle, SW_HIDE); DialogBox(main_instance,MAKEINTRESOURCE(IDD_DIALOGPEERTOPEER),main_window_handle,PeerToPeerDialogProc); ShowWindow(main_window_handle, SW_SHOW); SetFocus(main_window_handle); } else DialogBox(main_instance,MAKEINTRESOURCE(IDD_DIALOGPEERTOPEER),main_window_handle,PeerToPeerDialogProc); }
Last edited by curlious; 10-30-2003 at 11:28 AM.
Thanks Guys, I maybe should have explained better, thanks curlious for that detailed explanation but unfortunately its not what I was looking for, I actually meant a button on my original dialog but I will definitely keep your code in mind for future reference.
I am trying DoModal but I am getting it wrong.
Thanks again.Code:void CBoxDlg::OnButton3() { CDialog* PROPERTIES = (CDialog*) GetDlgItem(IDD_DIALOG1); PROPERTIES->DoModal(); // TODO: Add your control notification handler code here }
Compiler == Visual C++ 6.0"Come Out Fighting."
*Bump* (sorry its doing my head in)
Compiler == Visual C++ 6.0"Come Out Fighting."
Hi,
so, you have created a dialog box resource, and attached a class to it called PROPERTIES derived from CDialog?
If this is the case, I think the code should look like this:
CDialog::PROPERTIES propertiesObject;
propertiesObject.DoModal();
you should even be able to leave off the CDialog if you want to, and shorten the first line to:
PROPERTIES propertiesObject;
see if that will help.
C ya
static
Thanks Static, I just tried it, I see where you were going but it dint work, what I am doing is creating an object of the CDialog class called PROPERTIES and then pointing it to IDD_DIALOG1, that is what I think I am doing anyway but it aint working, any more thoughts?
Thanks again.
Compiler == Visual C++ 6.0"Come Out Fighting."
ok, check this out;
To open a dialog box from another dialog box:
right click on the dailog folder in the resource view and select 'add resource'. add a dialog resource that inherets from CDialog;
when the dialog templete opens up, double click on it to attach a class. give it a name (subBox in my example), and make sure that it inherets from CDialog;
include the header file for the child dialog box in the parent dialog box code. i.e. add #include "subBox.h" to Boxdlg.cpp.
then you open the dialog box when button 1 is clicked like this:
subBox is the class that describes your child box, and sBox is an instance of that class (the child dialog box object).Code:void CBoxDlg::OnBnClickedButton1() { subBox sBox; sBox.DoModal(); }
this should work for you, it worked in my example. If it still won't open, post up the error messages;
C ya;
Nice one static, that was bang right, this visual programming gets on top sometimes, I understand about classes and objects but thanks for your thorough explanation, it is greatly appreciated, no doubt I'll be asking for your help again at some time in the future.
Cheers mate.
Compiler == Visual C++ 6.0"Come Out Fighting."
Or for non modal (apps operation can continue WHILE dlg is open)
Create a member variable (in the same class header as the button) include the DLGs header.
ie
CMyDlg m_dlgMyNewDialog;
when the button is clicked
Code:if(m_dlgMyNewDialog.GetSafeHwnd())//is open { m_dlgMyNewDialog.ShowWindow( SW_SHOW); return 0;//no error } if(!m_dlgMyNewDialog.Create( MAKEINTRESOURCE(IDD_DLG), this)) { //error!
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
Cheers Novacaine, thats good for my soul, I will keep it in mind for future reference.
Compiler == Visual C++ 6.0"Come Out Fighting."