Thread: Get a string from a modal dialog box

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    Get a string from a modal dialog box

    Hi,
    I have a dialog based application. I want to pop up a little dialog box asking for a serial number before starting the main application. I used the following code in the constructor of the main dialog window:
    Code:
    CDialog serialDlg(IDD_SERIAL);
    
    	// Create and show the dialog box
       INT_PTR nRet = -1;
       nRet = serialDlg.DoModal();
    CString newValue;
    	
    
       // Handle the return value from DoModal
       switch ( nRet )
       {
       case -1: 
          AfxMessageBox("Dialog box could not be created!");
          break;
       case IDABORT:
          // Do something
          break;
       case IDOK:
          m_serial.GetWindowText(newValue);
          break;
       case IDCANCEL:
          // Do something
          break;
       default:
          // Do something
          break;
       };
    
    DDX_Control(pDX, IDC_EDITSERIAL, m_serial);
    m_serial is a CEdit variable in my main dialog class.
    Alas it is giving me an exception error. Anybody would know how to go about doing that. Thanks
    Amish

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Try moving that code from the constructor to the WM_INITDIALOG message handler.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM