Using MFC in C++ Part 4: Controls, DDX and DDV - Controls explained
(Page 2 of 9 )
Controls are the building blocks of an application hierarchy, and are used to provide users with a way to easily enter input. Some controls are bi-directional (accept input, and display out), while others are uni-directional (only accept input or only display output). Controls are created as part of a dialog box in a resource file.
The EDITTEXT controlOne of the most popular controls in C++ is the edit box. The edit box is represented in C++ through MFC as the EDITTEXT control. The syntax of the EDITTEXT resource looks like this:
EDITTEXT
[Control Id], [X Pos], [Y Pos], [Width], [Height], [Style Options]The Control Id is a user #defined numerical value, which is usually stored in a separate file. Because we are creating an edit box, the ID should be prefixed with “IDE_”, such as “IDE_NAME”. The x pos, y pos, width and height are self-explanatory. The style options define how the edit box will be displayed. Some default styles, such as WS_VISIBLE, WS_BORDER, WS_CHILD and WS_TABSTOP should be used. Also, to allow a user to scroll the edit box, the ES_AUTOHSCROLL style macro should be used. Style macros can be Ored together. A sample EDITTEXT control would be declared like this:
EDITTEXT IDE_NAME, 20, 20, 50, 12, WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLLThe EDITTEXT control has a number of functions, which can be used to manipulate its contents, check for valid values, etc. But before I describe them, let’s talk about buttons.
Next: The push button control >>
More C++ Articles
More By Mitchell Harper