Thread: MFC Bring up a dialog.

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    MFC Bring up a dialog.

    Hello,

    I already have a basic MFC Application created (with the default dialog and the about box, and another one I made called IDC_DIALOG1) using the standard MFC library. My question is how do I make a dialog pop up?

    is it like IDC_DIALOG1.PaintDialog() or something?

    Thanks,

    Guitarist809
    ~guitarist809~

  2. #2
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    anybody?
    ~guitarist809~

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    How you show the dialog depends on the type of dialog it is and how you are using it.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    What type of dialog, modal or modeless?

    Basic steps;
    1. Create a class based on the dialog.
    How you do this depends on the version of MSVC you are using.
    Try double clicking on the dialog in the resource viewer.

    2. Include the header file for the new dialog's class in the main dialog.

    3. Create instance of dlg class (a variable)

    4. Call DoModal()

    Code:
    //create a class CMyDlg from IDD_DIALOG1
    
    //include the class in the parent dialog
    #include "MyDlg.h"
    
    //in the method you want the dialog to appear
    //create the dialog class
    CMyDlg       MyDlg;
    
    //create modal, 
    //does not return from the dialog until the dialog is closed
    int             iReturn=0;
    //catch the button the user clicked to close the dialog
    iReturn = MyDlg.DoModal();
    
    
    //now the IDD_DIALOG1 code will run,
    //until the user finishes and closes the dialog
    
    
    //what did the user do
    if(iReturn == IDOK)//user clicked the OK button
    {
    //do stuff
    {
    else if (iReturn == IDCANCEL)//user canceled the dlg
    {
    Post if you need a modeless dlg, which runs at the same time as your app.
    Last edited by novacain; 07-28-2007 at 12:47 AM.
    "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

  5. #5
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    I honestly don't know the difference between a modeless dialog and a model dialog =\

    i did the DoModal() and it automatically put two buttons (OK, CANCEL) and a text message (TODO: PUT YOUR CONTROLS HERE) even when the dialog was empty.

    I'm assuming that's not supposed to happen...
    ~guitarist809~

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by guitarist809 View Post
    I honestly don't know the difference between a modeless dialog and a model dialog =\
    It is important and you need to know the difference.

    I could tell you.....but I won't.

    Google it....

    Quote Originally Posted by guitarist809 View Post
    i did the DoModal() and it automatically put two buttons (OK, CANCEL) and a text message (TODO: PUT YOUR CONTROLS HERE) even when the dialog was empty.

    I'm assuming that's not supposed to happen...
    Sounds like you used a brand new dlg, not the one you made. New MFC dlgs are made with two buttons and a static (telling you to place controls).

    So it is somewhat expected. Shows that you have it mostly correct.



    Are you using the resource editor?

    What version of MSVC are you using, v6 or 2003 or 2005? If you have 2002 then upgrade/patch to 2003.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 04-27-2004, 08:02 PM
  2. Document Class and Dialog Windows :: MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 12-01-2002, 12:27 AM
  3. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM
  4. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM