Make a dialog show up

This is a discussion on Make a dialog show up within the Windows Programming forums, part of the Platform Specific Boards category; Ok, this is as far as I have been able to get in VS2005 Right Click on Dialog->Insert Dialog. This ...

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

    Make a dialog show up

    Ok, this is as far as I have been able to get in VS2005

    Right Click on Dialog->Insert Dialog.

    This creates a new dialog in my project. My question is, how do I get it to show up and close when a button is pressed?

    Thanks,

    Matt N
    ~guitarist809~

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Add a handler function for the button. I believe you can do this by right clicking on the button and choose from the popup menu.

    In the handler function, declare an instance of your dialog class. Call DoModal for the dialog.

    Did you want the button to open and close the dialog? If you do you will have to make a modeless dialog. The above is for a modal dialog. A modal dialog will retain focus until it is closed. A modeless dialog allows you to switch back to the main app while the dialog is still open. For a modeless dialog you have to call Create and then ShowWindow. Also the modeless dialog can't be a local instance in the button handler function. It will have to be global or a member variable, if using MFC.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Thanks! It worked

    Now, how can I change variables in the first dialog from the second dialog? (like control variables for changing the text of buttons/etc...)
    ~guitarist809~

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    You can pass a pointer to the variables to the second dialog. Change the values when the second dialog is open, then if you are calling DoModal() to open the second dialog you can do something like this :

    Code:
    ... inside button handler of first dialog.
        // open second dialog
        CSecondDialog dlg;
    
        dlg.m_pSomeVariable = &m_FirstDialogVariable;
    
        if( dlg.DoModal() == IDOK )
        {
            // here you can use the updated value for m_FirstDialogVariable.
        }

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Quote Originally Posted by DaveH View Post
    Also the modeless dialog can't be a local instance in the button handler function. It will have to be global or a member variable, if using MFC.
    Admittedly, this is kind of no-no and perhaps a hack, but you can use a flag inside the dialog like bModeless, and if true, then add a "DestroyWindow" or similar inside OnClose and delete this inside OnDestroy (call the base class first!).
    Then you can allocate it via new and the modeless will take core of getting rid of its memory by itself when it closes.
    It may be risky. I haven't tested it, so I can't say if it works.

    But I would love to know if it DOES work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I can't make bmp image files show up in an SDL window
    By Lucas89 in forum Game Programming
    Replies: 5
    Last Post: 05-25-2009, 02:04 PM
  2. Need help With Scrolling Text - Wanna make Dialog Credits...
    By jekko in forum Windows Programming
    Replies: 10
    Last Post: 02-28-2004, 02:39 AM
  3. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 03:59 AM
  4. dialog
    By whban in forum C++ Programming
    Replies: 0
    Last Post: 09-08-2002, 12:31 AM
  5. Replies: 1
    Last Post: 03-12-2002, 06:31 AM

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