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. Adding items to a list box in a dialog. [modified]

Adding items to a list box in a dialog. [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiodebugging
6 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    Ben Aldhouse
    wrote on last edited by
    #1

    The following refers to an application I am writing in VC++ 6. I want to add some items to a list box in a dialog. I understand that this involves something called DDX, which, as far as I am aware is something that the IDE sorts out for me. I have added a public variable to the dialog class via the Class Wizard to be associated with the List box - m_listGTTimeUnits. Now, the application is a Windows Explorer style application and the dialog appears when I right-click over the right hand pane. I have tried a couple of ways to add values to the list box, both of which allow the code to compile but cause the program to crash with the message "Debug assertion failed" when the dialog is called... Firstly... void CRightView::OnRightmenuEditnode() { ... CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days"); ... and secondly void CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ... If anyone has any idea of what it is that I am doing wrong, I would be very glad to hear! Thanks, Ben.

    modified on Saturday, January 26, 2008 10:47:25 AM

    CPalliniC 1 Reply Last reply
    0
    • B Ben Aldhouse

      The following refers to an application I am writing in VC++ 6. I want to add some items to a list box in a dialog. I understand that this involves something called DDX, which, as far as I am aware is something that the IDE sorts out for me. I have added a public variable to the dialog class via the Class Wizard to be associated with the List box - m_listGTTimeUnits. Now, the application is a Windows Explorer style application and the dialog appears when I right-click over the right hand pane. I have tried a couple of ways to add values to the list box, both of which allow the code to compile but cause the program to crash with the message "Debug assertion failed" when the dialog is called... Firstly... void CRightView::OnRightmenuEditnode() { ... CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days"); ... and secondly void CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ... If anyone has any idea of what it is that I am doing wrong, I would be very glad to hear! Thanks, Ben.

      modified on Saturday, January 26, 2008 10:47:25 AM

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Ben Aldhouse wrote:

      CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days");

      Ben Aldhouse wrote:

      void CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ...

      In the above handlers, you created an instance of your dialog but you never created the dialog window. Why do you need to update the list box from the view? Cannot you update it from the dialog itself?

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      [my articles]

      In testa che avete, signor di Ceprano?

      B 1 Reply Last reply
      0
      • CPalliniC CPallini

        Ben Aldhouse wrote:

        CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days");

        Ben Aldhouse wrote:

        void CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ...

        In the above handlers, you created an instance of your dialog but you never created the dialog window. Why do you need to update the list box from the view? Cannot you update it from the dialog itself?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        [my articles]

        B Offline
        B Offline
        Ben Aldhouse
        wrote on last edited by
        #3

        These are just snippets, I have the following lines later on if (dlg.DoModal () == IDOK) { myPNode->SetNodeDescr(dlg.m_strNodeDesc); if (dlg.m_strNodeDesc != oldDesc) pDoc->SetModifiedFlag(); } I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog... bool CEditNodeDlg::OnInitDialog() { m_listGTTimeUnits.AddString("days"); } but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.

        B CPalliniC 2 Replies Last reply
        0
        • B Ben Aldhouse

          These are just snippets, I have the following lines later on if (dlg.DoModal () == IDOK) { myPNode->SetNodeDescr(dlg.m_strNodeDesc); if (dlg.m_strNodeDesc != oldDesc) pDoc->SetModifiedFlag(); } I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog... bool CEditNodeDlg::OnInitDialog() { m_listGTTimeUnits.AddString("days"); } but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.

          B Offline
          B Offline
          Ben Aldhouse
          wrote on last edited by
          #4

          I've got it! Thanks for your help! Basically I needed to change 'bool' to 'BOOL'. BOOL CEditNodeDlg::OnInitDialog() { CDialog::OnInitDialog(); m_listGTTimeUnits.AddString("days"); return TRUE; }

          1 Reply Last reply
          0
          • B Ben Aldhouse

            These are just snippets, I have the following lines later on if (dlg.DoModal () == IDOK) { myPNode->SetNodeDescr(dlg.m_strNodeDesc); if (dlg.m_strNodeDesc != oldDesc) pDoc->SetModifiedFlag(); } I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog... bool CEditNodeDlg::OnInitDialog() { m_listGTTimeUnits.AddString("days"); } but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            Ben Aldhouse wrote:

            I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...

            This is the way to go.

            Ben Aldhouse wrote:

            bool CEditNodeDlg::OnInitDialog()

            Replace bool with BOOL. BTW Why don't you make the Visual Studio make the work for you (select your dialog on class explorer, right click and choose Add Windows Message Handler item)?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            [my articles]

            In testa che avete, signor di Ceprano?

            B 1 Reply Last reply
            0
            • CPalliniC CPallini

              Ben Aldhouse wrote:

              I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...

              This is the way to go.

              Ben Aldhouse wrote:

              bool CEditNodeDlg::OnInitDialog()

              Replace bool with BOOL. BTW Why don't you make the Visual Studio make the work for you (select your dialog on class explorer, right click and choose Add Windows Message Handler item)?

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              [my articles]

              B Offline
              B Offline
              Ben Aldhouse
              wrote on last edited by
              #6

              Thanks!

              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