Thread: MFC Question

  1. #1
    Unregistered
    Guest

    MFC Question

    Okay.

    I have two Dialogs, lets call them IDD_DLG1 and IDD_DLG2.

    On IDD_DLG1 I have an array of CStrings(lets say 50). There is a CListBox control on IDD_DLG2. Why does this not work:


    IDD_DLG1 code:

    User clicks "View List of Names" button (the array of CStrings) on IDD_DLG1.

    Code:
    CDLG2 myDlg;
    
    myDlg.DoModal();
    
    for(int i = 0; i < 50; i++)
    {
        myDlg.ListBox.AddString(names[i]);
    }

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You call

    Code:
    myDlg.DoModal();
    and it does not return until the dialog ends.....therefore, by the time you run

    Code:
    for(int i = 0; i < 50; i++)
    {
        myDlg.ListBox.AddString(names[i]);
    }
    the dialog is gone.....therefore AddString will not operate...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC check box question
    By MyglyMP2 in forum Windows Programming
    Replies: 2
    Last Post: 03-09-2009, 05:47 PM
  2. MFC simple question
    By dole.doug in forum Windows Programming
    Replies: 5
    Last Post: 09-26-2008, 06:11 AM
  3. Window Resize question (MFC)
    By IfYouSaySo in forum Windows Programming
    Replies: 2
    Last Post: 11-16-2005, 12:34 PM
  4. MFC UI question
    By naruto in forum Windows Programming
    Replies: 1
    Last Post: 04-21-2005, 10:10 PM
  5. MFC Dialog App Screen Refresh Question
    By Scotth10 in forum Windows Programming
    Replies: 2
    Last Post: 10-18-2002, 02:07 PM