CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Mar 2006
    Posts
    63

    Re: CDialog:ListBox in Doc/View

    Thanks Arjay. I appreciate your efforts and time spent. You have created a Doc/View project in Visual Studio 2005, which successfully permits writing of data from Doc/View to a dialog called from a menu item. This is what I have already achieved in VC++6.
    Unfortunately I cannot figure out what I should do either in VC++6 nor in the VS2005 example you sent in order to be able to transfer data to a CListBox. It has to be a listbox, since the entries are generated at runtime from random filesets, and the entry count can be between 1 and 100 or so, and the user must select which ones he wants converted and simultaneously displayed.
    Eugene Kain in his modestly titled book shows how one can communicate between a Dialog and a Doc/View, but cleverly avoids anything other than trivial items. No guesses for what I'd like to do with his fat tome.
    I'm beginning to think that what I'm trying to do is impossible.

  2. #17
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CDialog:ListBox in Doc/View

    It's possible. All you do is create a list of items in the document and expose the list to the dialog.

    You populate the list box in the OnInitDialog by cycling through the list in the document and calling AddString for each item.

    In the OnOk, you add/remove any items in the document's list.

    Essentially, it's the exact same thing as what I've shown with the m_sEdit variable except that instead of exposing a CString variable, you expose a list.

    Btw, instead of using a CListBox, I'd probably use a CListCtrl in report mode - that way you can bind to the document's list directly.

    If I get time, I'll update the sample.

  3. #18
    Join Date
    Mar 2006
    Posts
    63

    Re: CDialog:ListBox in Doc/View

    Thanks again Arjay.
    I made a few small changes to your project, in order to access a CListBox which I added to the dialog. I commented all the changes ( I hope) with //**crasher.
    I get an assertion failure - same as in VC++6 - when trying to AddString.
    The dialog Clistbox apparently doesn't exist at that point (one could ask why not, since the Wizard knows all about it?), although its empty rectangle is merrily displayed on the dialog, even though it doesn't exist.
    I believe that just before one tries to AddString, a (dlg).Create should be executed, but I'm stuck for which handle/pointer to pass to it (tried a few things). That's even assuming that a Create there would be correct.
    In a CListbox in a Dialog App, the CListbox is fully up and running without the programmer having to bend over backwards. Here in a Doc/View it's just left hanging (or totally messed up?).
    I've attached the modified project.
    Thanks again for your time and trouble.
    (Btw, I use VC++6 because 2005 is desperately slow on importing big text/binary files)
    Attached Files Attached Files

  4. #19
    Join Date
    Mar 2008
    Location
    Turin / Italy
    Posts
    178

    Re: CDialog:ListBox in Doc/View

    By moving the
    Code:
    m_list.AddString(m_pDocument->GetEditString());
    after
    Code:
    CDialog::OnInitDialog();
    everything works. Just as GCDEF says. The list control hasn't been initialized(created) that's why you're getting ASSERT on IsWindow.
    Or maybe I haven't understood where the problem stands.
    Last edited by SkyNetTo; August 16th, 2009 at 04:32 PM.

  5. #20
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: CDialog:ListBox in Doc/View

    Quote Originally Posted by crasher View Post
    Thanks again Arjay.
    I made a few small changes to your project, in order to access a CListBox which I added to the dialog. I commented all the changes ( I hope) with //**crasher.
    I get an assertion failure - same as in VC++6 - when trying to AddString.
    The dialog Clistbox apparently doesn't exist at that point (one could ask why not, since the Wizard knows all about it?), although its empty rectangle is merrily displayed on the dialog, even though it doesn't exist.
    I believe that just before one tries to AddString, a (dlg).Create should be executed, but I'm stuck for which handle/pointer to pass to it (tried a few things). That's even assuming that a Create there would be correct.
    In a CListbox in a Dialog App, the CListbox is fully up and running without the programmer having to bend over backwards. Here in a Doc/View it's just left hanging (or totally messed up?).
    I've attached the modified project.
    Thanks again for your time and trouble.
    (Btw, I use VC++6 because 2005 is desperately slow on importing big text/binary files)
    In post number 14 I said "The point is the listbox has to exist when you add strings to it. It exists after the call in OnInitDialog to CDialog::OnInitDialog".

    It's frustrating to give somebody the answer and have them ignore you.

  6. #21
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CDialog:ListBox in Doc/View

    Quote Originally Posted by crasher View Post
    Thanks again Arjay.
    I made a few small changes to your project, in order to access a CListBox which I added to the dialog. I commented all the changes ( I hope) with //**crasher.
    I get an assertion failure - same as in VC++6 - when trying to AddString.
    The dialog Clistbox apparently doesn't exist at that point (one could ask why not, since the Wizard knows all about it?),
    As mentioned several times - a dialog's controls are not available until after the base class call to CDialog::OnInitDialog( );.

    See your code below.
    Code:
    BOOL CTestDlg::OnInitDialog( )
    {
      //
      // Okay to manipulate data variables here
      //
      // Initialize the edit box string variable
      // from the document
     
      // m_sEdit = m_pDocument->GetEditString( ); //**crasher
     
      m_list.AddString(m_pDocument->GetEditString()); //**crasher :   ASSERT failure here
     
      CDialog::OnInitDialog();
     
      // Okay to manipulate control variables here
    
    
     
      return 0;
    }

    Did you not see my comment // Okay to manipulate control variables here ?

    That means to put any control initialization after the base class call.
    Attached Images Attached Images
    Attached Files Attached Files

  7. #22
    Join Date
    Mar 2006
    Posts
    63

    Talking Re: CDialog:ListBox in Doc/View

    Yes, SkynetTo, you're right. Arjay (thanks 2!) had already made that clear earlier, but I 'd already gone into frustration/desperation mode. Thanks for pointing out my stupid mistake.
    You too were indirectly right, GCDEF, but after your "it doesn't work" posts, I didn't look at your subsequent post. Sorry about that.
    Thanks again to all.

  8. #23
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: CDialog:ListBox in Doc/View

    Quote Originally Posted by crasher View Post
    You too were indirectly right, GCDEF, but after your "it doesn't work" posts, I didn't look at your subsequent post. Sorry about that.
    Thanks again to all.
    No, I was exactly right and told you what was wrong from the beginning.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured