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

    MFC Dialog: How to set/get the values of various controls?

    Q: How to set/get the values of various controls?

    A: Use the class wizard (CTRL+W) to create member variables for your controls. For each control you can create two variables: one of the type "Value" and one of the type "Control". Use the "Value" type variable to set or get the value of the control. Use the "Control" type variable to access the control.

    Avoid using 'GetDlgItem()' for several reasons. 'GetDlgItem()' returns a 'CWnd*' that need to be casted to the correct class. Subtle bugs can arise from wrong casting (e.g. if a 'CListCtrl' is casted to a 'CListBox' by mistake). These bugs are very hard to find, because they do not trigger a runtime error in the most cases - the control simply "refuses" to do what it is told to.

    Besides of that, repeatedly calling 'GetDlgItem()' is slower than having your controls member variables of their container.

    For further information take a look at this article...

    Last edited by Andreas Masur; July 24th, 2005 at 04:20 PM.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)