MFC Dialog: How to set/get the values of various controls?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

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

Hybrid View

  1. #1
    Join Date
    Sep 2000
    Location
    Indianapolis
    Posts
    6,425

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center