Page 202 - DCAP408_WEB_PROGRAMMING
P. 202
Windows Programming
Notes // Reset our boolean.
m_bDemoDlgActive = FALSE;
}
If you successfully compiled this and ran the resulting program, you could bring up the
demonstration dialog box, modify the edit control, check the check box, and press “OK”. What
you would see would be the text you entered and the status of the check box displayed on the
status bar (at the bottom of the window). The MFC DDX mechanism did all of the work for you!
To you, working with your dialog box was as easy as working with another C++ class’ member
variables. Class Wizard is really something!
Task Illustrate the use of DDX_OCFloat.
Self Assessment
Fill in the blanks:
1. ......................... function is used to manage the transfer of BOOL data between a read-only
property of an OLE control and a BOOL data member.
2. ......................... function is used to manage the transfer of CString data between a read-only
property of an OLE control and a CString data member.
3. ......................... function manages the transfer of short data between a property of an OLE
control and a short data member.
4. One of the parameters passed to DialogBox() is a ......................... to a subroutine we created
to actually bring up the dialog box.
5. If the user modified the text, we’d have to write the new string back to the .........................
variable or find some other viable means of retrieving the string prior to the dismissal of
the dialog box.
12.2 Problems in Global Variables
As with all Heuristic Rules, this is not a rule that applies 100% of the time. Code is generally
clearer and easier to maintain when it does not use globals, but there are exceptions. It is similar
in spirit to GotoConsideredHarmful, although use of global variables is less likely to get you
branded as an inveterate hacker.
12.2.1 Why Global Variables Should be Avoided when Unnecessary?
Non-locality: Source code is easiest to understand when the scope of its individual elements
are limited. Global variables can be read or modified by any part of the program, making
it difficult to remember or reason about every possible use.
No Access Control or Constraint Checking: A global variable can be get or set by any part
of the program, and any rules regarding its use can be easily broken or forgotten. (In other
words, get/set accessors are generally preferable over direct data access, and this is even
more so for global data.) By extension, the lack of access control greatly hinders achieving
security in situations where you may wish to run untrusted code (such as working with
3rd party plugins).
196 LOVELY PROFESSIONAL UNIVERSITY