Dialog Issues in VC++

This is a discussion on Dialog Issues in VC++ within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to populate a list box on the main dialog box with data selected from a different dialog box ...

  1. #1
    Frustrated
    Guest

    Unhappy Dialog Issues in VC++

    I'm trying to populate a list box on the main dialog box with data selected from a different dialog box which contains radio buttons. My code compiles, but the program bombs when I run it. What am I doing wrong?

    CProject1Dlg is the main dialog box.


    void CProject1Dlg::OnButtonDrink()
    {
    DRINK dlg_Drink(this);

    // Initialize dialog data
    int nRetCode = dlg_Drink.DoModal();

    if(nRetCode = IDOK)
    {
    CString strMessage, strDType, strDSize;

    UpdateData();

    // Determine which button is selected and confirm addition.
    GetDlgItem(IDC_RADIO_LG + dlg_Drink.m_DSize) -> GetWindowText(strDSize);
    GetDlgItem(IDC_RADIO_D_POP + dlg_Drink.m_DType) -> GetWindowText(strDType);

    strMessage = strDSize +" "+ strDType + " is selected";

    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    Code:
    // Determine which button is selected and confirm addition. 
    GetDlgItem(IDC_RADIO_LG + dlg_Drink.m_DSize) -> GetWindowText(strDSize); 
    GetDlgItem(IDC_RADIO_D_POP + dlg_Drink.m_DType) -> GetWindowText(strDType);
    The above code is very suspect. The api is as follows:

    CWnd* GetDlgItem( int nID ) const;

    void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;

    Return Value

    A pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL.

    You're adding some value to the nID... Is there a reason for that?

    My guess is ther is not. But since you don't check the return but rather assume you've got a valid pointer in temporary storage and attempt to dereference it with GetWindowText... bad ju-ju

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 03:18 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 03:42 PM
  4. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 03:59 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

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