Thread: Getting data from dialog box

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    224

    Getting data from dialog box

    Hello,
    I'm having trouble retreiving data from control variables in dialog box. My dialog box class has one control variable, CComboBox c_box. Here's some code:

    Code:
    void MyView::OnItemClick()
    {
     MyDialog dlg(this);
     char tmp[10];
     int num;
    
     if(dlg.DoModal() == IDOK)
     {
       dlg.c_box.GetLBText(dlg.c_box.GetCurSel(), tmp);
       num = atoi(tmp);
     }
    }
    But this crashes at the call to GetLBText(); I get a debug assetion failed error. Why is this happening?

    Thanks.

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    It may help to post some more code, maybe the GetLBText and related code.
    silk.odyssey

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    GetLBText is a member function of CComboBox; that's not my code. Here's my initdialog function for MyDialog:
    Code:
    BOOL MyDialog::OnInitDialog()
    {
     CDialog::OnInitDialog();
     int i;
     char tmp[10];
    
     for(i = 1; i <= 10; i++)
     {
      sprintf(tmp, "%i", i);
      c_box.InsertString(-1, tmp);
     }
    
     c_box.SetCurSel(0);
    
     return TRUE;
    }

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    mfc objects destroyed after domodal destroywindow result in postncdestroy in objects

    Kuphryn

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    How do I get around that?

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I added an OnOk() button handler. Is that the best way to go about it? So the view class function becomes:
    Code:
    void MyView::OnItemClick()
    {
     MyDialog dlg(this);
    
     dlg.DoModal();
    }
    and my OnOk handler is:
    Code:
    void MyDialog::OnOK() 
    {
     // TODO: Add extra validation here
    	
     CDialog::OnOK();
     CONT_SIMDoc* pDoc = (CONT_SIMDoc*) parent->GetDocument();
     char tmp[10];
    
     c_box.GetLBText(c_box.GetCurSel(), tmp);		
     parent->num = atoi(tmp);
    }
    Last edited by Yasir_Malik; 05-16-2006 at 12:31 PM. Reason: Forgot DoModal().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 01:02 PM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  3. Dialog box
    By DeanaM in forum Windows Programming
    Replies: 3
    Last Post: 10-16-2002, 12:04 PM
  4. Context Menu & Dialog Box :: MFC
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 08-11-2002, 10:01 AM
  5. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM