Thread: Create a window from a dialogbox ?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    11

    Angry Create a window from a dialogbox ?

    In a dialogbox I want to create a window, after a button is pushed, in which I need to display some data.

    Apart from assertion failures and crashes, I could not manage
    to create this window.

    I am using VC6.0

    Can anyone tell me the proper way to do this ?

    Thanks,

    Peter.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    instead of creating that window when the button is pressed
    create it as 'hidden' in the dialog template and when the button is pressed just show it.

  3. #3
    Lowas
    Guest
    If you are using MFC

    Make a dialog prog with the wizard ...add a second dialog
    as a resource

    rough example:

    class MyDlg1;
    class MyDlg2;

    class CMyDlg1 : public CDialog
    {
    //.....
    CMyDlg2 m_myDlg2; // make m_MyDlg2 a member of CMyDlg1
    CButton m_Push;
    void OnButtonPush();
    };

    void CMyDlg1::OnButtonPush()
    {
    m_MyDlg2.DoModal(); // This is where you do it
    }


    class CMyDlg2 : public CDialog
    {
    //.......
    };

    There are more ways to do it in both WIN32API and MFC but I think this example is easy to grasp

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    15
    Correction:

    class MyDlg1;
    class MyDlg2;

    should be:

    class CMyDlg1;
    class CMyDlg2;

    ...of course

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    11
    I am using MFC.

    Creating a new dialog from a dialog is not the problem.

    My question was how to create a new window from a dialog
    and display some data in it.

    peter

  6. #6
    Unregistered
    Guest
    I have to admit that I never created a window from a dialog box before so if I am wrong don't flame me to hot...

    I have to make a few assumptions on what you want to accomplish.

    1. The window that you want to open is a different architecture from the window that opened the dialog box.

    2. That you wish the dialog box to remain active after the new window is open.

    To accomplish this:

    1. Create the project with a multi-document/view architecture. You can create both windows at the beginning or wait on the second window until the dialog box calls it. It is necessary to register the second window.

    2. Use the resource editor to design your dialog box(or really use any method you wish).

    3. Write a CDialog derived class for the dialog box. Make sure you have a constructor and a MESSAGE_MAP. You will need at least one CButton for calling the new window. In the MESSAGE_MAP put an ON_BN_CLICKED() handler and create a function to be called by this handler.

    4. In the handler function put your code for calling the new window.

    5. In the main window you will need to call the dialog box as a modeless type on the free memory heap. This means you will need to write a PostNcDestroy() in the CDialog derived class and post a message to the framework to delete the pointer to this class or else you will have a memory leak.

    6. In the CDocument derived class for the new window put the information you wish to display. It is then just a matter of writing the code for the OnDraw() in the CView derived class to display the information to the screen.

    This should only take a few hundred lines of code. Easy uhhhh???

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    11
    Who said Windows programming was a piece of cake ?
    Thanks Mr. B.Gates !

    peter

  8. #8
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Haha, in MFC this may be somewhere around 1000 lines of code, but using the actual API, it's just (basically) a call to createwindow(ex)...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. how i create a window whith all it's elements
    By rasheed in forum Windows Programming
    Replies: 1
    Last Post: 05-31-2006, 06:53 PM
  3. Create a duplicate window?
    By om3ga in forum Windows Programming
    Replies: 10
    Last Post: 10-29-2005, 12:12 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM