Alternative Mechanism for Acessing Simple Dialog Items

I never liked using standard MSVC features for manipulating simple text controls such as edit or static controls, like using Class Wizard variables and the UpdateData function. So, I developed support for "UI variables." It allows you to:

  1. Add a text "variable" to the class by just one line added to the Windows class definition (that is derived from MFC Cdialog or the CformView class).
  2. Manipulate with this variable by simply accessing it like a regular string (or integer). Every time you assign a value to it, the new value will be displayed. When you read it, the current value will be obtained from the control and returned as the "variable" value (for string UI variables only).

UI variables are implemented by C++ macros:

  • WUI_VAR(name, item, parent_type)
  • WUI_VARI(name, item, fmt_, parent_type)

Where:

  • name: Variable name
  • item: ID of the control
  • fmt_: Output format string for a single integer value
  • parent_type: Class name of the parent class.

Notes:

  • The parent class must be derived from CWndB (typically from either Cdialog or CformView).
  • The UI variables mechanism does not provide any checking of read values. That is why WUI_VARI allows only output of integer values.
  • The "parent_type" argument seems to be redundant for users. It is the only way I have found (using C++) to have a definition of the UI variable exactly in one place and allow access to the parent object. And, even this way is not perfect because it uses a non-standard C++ feature: using "offsetof" with a non-POD class. It works with simple regular MFC classes (what is actually needed), but I am not sure it would work correctly in case of using multiple/virtual inheritance.
  • All this was developed and tested using MSVC 6.0 and Windows XP.


Downloads

Comments

  • tee shirt gay tee shirt anti transpirant

    Posted by jcydldak on 03/16/2013 05:34am

    ÿþ

    Reply
  • Could not compile under VS 2005

    Posted by tnarol on 06/30/2006 09:32am

    It seems the macro definition doesn't work with VS 2005. It says "error C4430 : missing type specifier - int assumed." when using WUI_VARI or WUI_VAR.

    • Problem with VS 2005 fixed (but not published)

      Posted by MichaelFurman on 07/12/2006 04:11pm

      Though I have submitted changes, they have not gotten to the CodeGuru site for unknown reason - sorry. I just submitted the update one more time (only two "zip" files are changed).

      Reply
    • Problem with VS 2005 fixed

      Posted by MichaelFurman on 06/30/2006 01:26pm

      Thanks, tnarol, for pointing me on the error that was not detected by VS 6 (I do not have VS2005). Actually, I was was informed of this error even earlier by the Codeguru reviewer. Now I have fixed it.

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date