Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Passing CDialog results to CFormView ??

Passing CDialog results to CFormView ??

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestion
4 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I need to configure some application variables. I have a CFormView and via menu conmstruct a simple CDialog. However, after DoModal returns TDOK I am unable to retrieve the CComboBox selection - not even the GetCount returns number of items in the CComboBox. I seldom use CDialog but this got me stumped, I am obviously missing an important piece of code. Thanks for reading and your help is as always appreciated. Here is the offending code: void CFD2008View::OnConfigureSetup() {           CString strText;      CComboBox* pCombo10;      int nIndex;      int nCount;      // verify document        if(!m_CFD2008Doc)           m_CFD2008Doc = GetDocument();      VERIFY (m_CFD2008Doc);      CDialog dlg(IDD_DIALOG1);           if (dlg.DoModal()==IDOK){           TRACE("\nvoid CFD2008View::OnConfigureSetup() ");           pCombo10 = (CComboBox *) GetDlgItem(IDC_COMBO10);           VERIFY(pCombo10);           nIndex = pCombo10->GetCurSel(); //always returns 0                                   nCount = pCombo10->GetCount(); // always returns 0      } }

    S K 2 Replies Last reply
    0
    • V Vaclav_

      I need to configure some application variables. I have a CFormView and via menu conmstruct a simple CDialog. However, after DoModal returns TDOK I am unable to retrieve the CComboBox selection - not even the GetCount returns number of items in the CComboBox. I seldom use CDialog but this got me stumped, I am obviously missing an important piece of code. Thanks for reading and your help is as always appreciated. Here is the offending code: void CFD2008View::OnConfigureSetup() {           CString strText;      CComboBox* pCombo10;      int nIndex;      int nCount;      // verify document        if(!m_CFD2008Doc)           m_CFD2008Doc = GetDocument();      VERIFY (m_CFD2008Doc);      CDialog dlg(IDD_DIALOG1);           if (dlg.DoModal()==IDOK){           TRACE("\nvoid CFD2008View::OnConfigureSetup() ");           pCombo10 = (CComboBox *) GetDlgItem(IDC_COMBO10);           VERIFY(pCombo10);           nIndex = pCombo10->GetCurSel(); //always returns 0                                   nCount = pCombo10->GetCount(); // always returns 0      } }

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Try using

            pCombo10 = (CComboBox \*) dlg.GetDlgItem(IDC\_COMBO10);
      

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      1 Reply Last reply
      0
      • V Vaclav_

        I need to configure some application variables. I have a CFormView and via menu conmstruct a simple CDialog. However, after DoModal returns TDOK I am unable to retrieve the CComboBox selection - not even the GetCount returns number of items in the CComboBox. I seldom use CDialog but this got me stumped, I am obviously missing an important piece of code. Thanks for reading and your help is as always appreciated. Here is the offending code: void CFD2008View::OnConfigureSetup() {           CString strText;      CComboBox* pCombo10;      int nIndex;      int nCount;      // verify document        if(!m_CFD2008Doc)           m_CFD2008Doc = GetDocument();      VERIFY (m_CFD2008Doc);      CDialog dlg(IDD_DIALOG1);           if (dlg.DoModal()==IDOK){           TRACE("\nvoid CFD2008View::OnConfigureSetup() ");           pCombo10 = (CComboBox *) GetDlgItem(IDC_COMBO10);           VERIFY(pCombo10);           nIndex = pCombo10->GetCurSel(); //always returns 0                                   nCount = pCombo10->GetCount(); // always returns 0      } }

        K Offline
        K Offline
        krmed
        wrote on last edited by
        #3

        When DoModal returns, the dialog box window (and combo box) have been destroyed, so attempting to access them won't work. Instead, you could pass a pointer to the CFD2008View into the dialog - one way is

        CDialog dlg(IDD_DIALOG1);
        dlg.m_pView = this;
        if (dlg.DoModal()...

        Of course, you need to define a member variable in the dialog to hold this pointer (m_pView). Then in the view class, add member variables for the information you're trying to get. Now in the dialog's OnOK function, set the view class variable so they contain the desired information. Note that getting the count, or a pointer to the combo box will be useless as it's going to be destroyed. If you need to know the value of a selected combo box items, you'll need to find that value in the dialog's OnOK, and set that value into the view class. Hope that helps.

        Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

        V 1 Reply Last reply
        0
        • K krmed

          When DoModal returns, the dialog box window (and combo box) have been destroyed, so attempting to access them won't work. Instead, you could pass a pointer to the CFD2008View into the dialog - one way is

          CDialog dlg(IDD_DIALOG1);
          dlg.m_pView = this;
          if (dlg.DoModal()...

          Of course, you need to define a member variable in the dialog to hold this pointer (m_pView). Then in the view class, add member variables for the information you're trying to get. Now in the dialog's OnOK function, set the view class variable so they contain the desired information. Note that getting the count, or a pointer to the combo box will be useless as it's going to be destroyed. If you need to know the value of a selected combo box items, you'll need to find that value in the dialog's OnOK, and set that value into the view class. Hope that helps.

          Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          Thanks guys. I used both of yours advices and came up with this.      X_ConfigureDialog dlg; // derived from CDialog with IDD_DIALOG1 resource;           if (dlg.DoModal()==IDOK){           // pass dialog data to current view           // or use directly in current view                         m_strBand = dlg.m_ComboBox10;           m_strMode = dlg.m_ComboBox20;      } Conclusion 1. Do not use CDialog "directly" as local variable. 2. Derive view class variable from CDialog - I guess I should have known that. 3. Let DDX/DDV do its stuff - when DoModal completes. It still puzzles me why dlg is valid when used as derived class. I guess MFC / C++ class hierary magic. Thanks Vaclav

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups