WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
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:
- 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).
- 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)
- 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.
- 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.