CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Oct 2012
    Posts
    15

    Re: How To Handle An Open Document

    Hi Guys,

    I am just in a dazed state and can't seem to even figure this out. If possible, could you please just build a simple project from the class wizard, add the GetWindowText() and SetWindowText() code to get the text into a control, send the text back to the screen, and where to put the UpdateAllViews() at? I know you can do it in about 5 mins as you are clearly skilled.

    This is really lame on my part but I am at a point of a mental block and am frustrated big time.

    As we used to say as kids... Pretty Please?

    You could either post it here or send it to my Google email account using my screen name.

    For what it is worth, I am 60 years of age and not a student trying to get help on a school project (wish I was that young again). I can send you other files that I have worked on, just not this type

    Thanks.

    John

  2. #17
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How To Handle An Open Document

    Quote Originally Posted by JohnWHagen View Post
    Hi Guys,

    I am just in a dazed state and can't seem to even figure this out. If possible, could you please just build a simple project from the class wizard, add the GetWindowText() and SetWindowText() code to get the text into a control, send the text back to the screen, and where to put the UpdateAllViews() at? I know you can do it in about 5 mins as you are clearly skilled.

    This is really lame on my part but I am at a point of a mental block and am frustrated big time.

    As we used to say as kids... Pretty Please?

    You could either post it here or send it to my Google email account using my screen name.

    For what it is worth, I am 60 years of age and not a student trying to get help on a school project (wish I was that young again). I can send you other files that I have worked on, just not this type

    Thanks.

    John
    I don't believe you need UpdateAllViews in this case. Again, that's used by the document to let the views know that something has changed. Since your document isn't maintaining the data, it isn't appropriate here.

    As to where to put the code, that really depends on when you need it.

    The basic code will be in your view class and look something like this.
    Code:
    CString strText;
    GetEditCtrl()->GetWindowText(strText);
    //manipulate your data here
    GetEditCtrl()->SetWindowText(strtext);
    The first place you could get at it would be in your view's OnInitialUpdate function, after the call to the base class. It should work anywhere after that.

  3. #18
    Join Date
    Oct 2012
    Posts
    15

    Re: How To Handle An Open Document

    I added the OnInitialUpdate function to my main view class. It is being called as the program starts up, but not after I load the file.

    That tells me I need to make another call to the OnInitialUpdate() function. I assume this would be called from the Doc class. I tried that but get an error saying the CView class is protected.

    How do I make the next call from my Doc class so I can manipulate the data?

    Again, thanks!
    John

  4. #19
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How To Handle An Open Document

    Quote Originally Posted by JohnWHagen View Post
    I added the OnInitialUpdate function to my main view class. It is being called as the program starts up, but not after I load the file.

    That tells me I need to make another call to the OnInitialUpdate() function. I assume this would be called from the Doc class. I tried that but get an error saying the CView class is protected.

    How do I make the next call from my Doc class so I can manipulate the data?

    Again, thanks!
    John
    Try handling OnUpdate in the view class.

  5. #20
    Join Date
    Oct 2012
    Posts
    15

    Re: How To Handle An Open Document

    Woo Hoo, progress!

    I added the OnUpdate() to the View class and now it executes. As the program starts it passes through the OnUpdate() function twice. Then when I load the file and use GetWindowText() I can see the file data. Major progress, although it may seem trivial to others.

    I added a Doc object and did a SetDocumentText(<string data>) and it is now resident in my Doc class. From there I should be able to do the manipulation I want. Now, to get the Doc class to send it back to the View I will need to make a call from the View to Doc.GetDocumentText() and the have the view SetWindowText(<my new data>). Is this correct?

    The only thing I am not sure of is how to force the View class to call the Doc class to get the updated document data. Guess I could set up a Message, send it and have the View class respond to the message.

    Does this sound like a reasonable plan? I know how to send/receive AFX_Msgs. Or, is there a better way?

    Thanks again!

    John

  6. #21
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How To Handle An Open Document

    I think you're overly complicating it. In your case, I'd ignore the document completely. The Edit Control seems to be what stores the text and the doc is set up to Serialize in and out of there. As I said, I'd just use Get and Set WindowText in the view class and just use the default doc stuff to handle the file I/I for you.

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