Calling New Dialog, VC++

This is a discussion on Calling New Dialog, VC++ within the C++ Programming forums, part of the General Programming Boards category; Hi, I have added a new dialog box to my MFC application, I am having trouble getting it to open ...

  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    Calling New Dialog, VC++

    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."

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is DoModal().

    Kuphryn

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    Here is how I do it in WinApi32

    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).

    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);
    	}
    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.
    Last edited by curlious; 10-30-2003 at 10:28 AM.

  4. #4
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    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.

    Code:
    void CBoxDlg::OnButton3() 
    {
    	CDialog* PROPERTIES = (CDialog*) GetDlgItem(IDD_DIALOG1);
    
    	PROPERTIES->DoModal();
    	// TODO: Add your control notification handler code here
    	
    }
    Thanks again.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  5. #5
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    *Bump* (sorry its doing my head in)
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  6. #6
    Registered User static's Avatar
    Join Date
    Nov 2003
    Posts
    3
    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

  7. #7
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    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."

  8. #8
    Registered User static's Avatar
    Join Date
    Nov 2003
    Posts
    3
    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:
    Code:
    void CBoxDlg::OnBnClickedButton1()
    {
    	subBox sBox;
    	sBox.DoModal();
    }
    subBox is the class that describes your child box, and sBox is an instance of that class (the child dialog box object).

    this should work for you, it worked in my example. If it still won't open, post up the error messages;

    C ya;

  9. #9
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    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."

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    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

  11. #11
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Cheers Novacaine, thats good for my soul, I will keep it in mind for future reference.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. Calling up a dialog from a dialog handler function
    By Welder in forum Windows Programming
    Replies: 2
    Last Post: 11-03-2007, 10:45 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  4. problem with calling dialog
    By stallion in forum Windows Programming
    Replies: 11
    Last Post: 12-11-2002, 07:02 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21