Get a string from a modal dialog box

This is a discussion on Get a string from a modal dialog box within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have a dialog based application. I want to pop up a little dialog box asking for a serial ...

  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,265
    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, 05:05 AM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07: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, 04:58 PM

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