CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: UpdateData ???

  1. #1
    Join Date
    Oct 2011
    Posts
    14

    UpdateData ???

    I have a timer that updated read angles from a turn table. It does update each 200ms using UpdataData(FALSE)

    Now I also have an EditBox where I enter some commands. But the timer overrun the commands I have entered before I have time to run UpdateData(TRUE).

    Is there no way to update each EditBox by itself or any other way to avoid the problem?

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: UpdateData ???

    ...or any other way to avoid the problem?
    Stop using updatedata and assign a member variable so you can do the read/write actions yourself.

  3. #3
    Join Date
    Oct 2011
    Posts
    14

    Re: UpdateData ???

    By member variable I suppose you talk about a variable that is not connected in any way to the control. I did use the Control variable of category Value. Suppose that was wrong.
    I will try what you suggest.

    But....
    What about GetDlgItem(IDC_EDIT1)->SetWindowTextW(CString) ?
    Is that recommended or not?

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: UpdateData ???

    Is that recommended or not?
    Good question. I think it's what you prefer. I never use it, but I see a lot of posts using it. I prefer to assing a member variable. The only thing I know is that the UpdateData construction isn't one of MS best inventions

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: UpdateData ???

    Quote Originally Posted by jangus View Post
    By member variable I suppose you talk about a variable that is not connected in any way to the control. I did use the Control variable of category Value. Suppose that was wrong.
    I will try what you suggest.

    But....
    What about GetDlgItem(IDC_EDIT1)->SetWindowTextW(CString) ?
    Is that recommended or not?
    If you have a member variable of “control” type, like CEdit for edit box, you can simply call its member function SetWindowText() directly.
    Alternatively, you could call SetDlgItemText (), which is pretty much the same ad your GetDlgItem(IDC_EDIT1)->SetWindowTextW(CString).
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: UpdateData ???

    Quote Originally Posted by Skizmo View Post
    ... The only thing I know is that the UpdateData construction isn't one of MS best inventions
    I agree. It can makes sense only once in OnInitDialog and then in OnOK.

    Avoiding UpdateData
    Victor Nijegorodov

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

    Re: UpdateData ???

    Quote Originally Posted by VictorN View Post
    I agree. It can makes sense only once in OnInitDialog and then in OnOK.

    Avoiding UpdateData
    It makes sense whenever you need to get data to or from all the controls at once. For just populating a single control, SetWindowText is more efficient.

    The article you quoted is written by somebody who doesn't understand how it's supposed to work. I've pointed out the many flaws in his thinking before. He's even addressed some of them himself in reply to comments. I'll do it again, if you're interested, but for not I'll just say it's a load of nonsense.
    Last edited by GCDEF; October 3rd, 2011 at 09:34 AM.

  8. #8
    Join Date
    Oct 2011
    Posts
    14

    Smile Re: UpdateData ???

    Thanks everyone for all the help. I think I understand now

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

    Re: UpdateData ???

    Quote Originally Posted by jangus View Post
    What about GetDlgItem(IDC_EDIT1)->SetWindowTextW(CString) ?
    A lot of old timers like to program that way. For the folks that have discovered C++ and understand MFC, they prefer to create a control variable once during the life of the dialog and prefer to reuse it.

    Btw, what you definitely shouldn't do is call the 'W' version of an api and pass it a CString variable. Just leave off the 'A' or 'W' and let the pre-processor use the build settings to figure out the correct api to use.

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