Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals


CEdit *edtCubeSide, *edtCubeArea, *edtCubeVolume;

edtCubeSide = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_USIDE));
edtCubeArea = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_UAREA));
edtCubeVolume = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_UVOL));
}


  1. Change the content of theOnBnClickedBcalc event as follows:


void CGeome3D::OnBnClickedBtnBcalc()
{
// TODO: Add your control notification handler code here

// Related Calculations of the box
CEdit *edtBoxLength, *edtBoxWidth, *edtBoxHeight,
*edtBoxArea, *edtBoxVolume;

edtBoxLength = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BLENGTH));
edtBoxWidth = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BHEIGHT));
edtBoxHeight = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BWIDTH));
edtBoxArea = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BAREA));
edtBoxVolume = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BVOL));
}


  1. Save All


14.2.6..The Text of a Control..........................................................................


For you the programmer, the control identifier may be one of the most important
properties of a window. For the user, this is not the case. For a text-based control, the
most important part, as far as the user is concerned, may be its text. For example, if the
user is filling an employment application, the text entered on the fields is what would
make the difference. Many controls use text. In fact, one of the most obvious items on
most windows such as frames or dialog-based objects is the text they display. This text
allows the user to identify a window or an object on the screen.

Some controls only display text that the user can/must read in order to use an application.
Some other controls allow the user to change their text. Regardless of what such text is
used for, you should exercise a good deal of control on the text that a control would
display or receive.

When we started reviewing controls, we saw that some of the controls that use text would
allow you to change the Caption property at design time. On the other hand, while a using
is interacting with your application, depending on various circumstances, at a certain time
you may want to change the text that a window or control is displaying or holding; that is,
if the control is meant to display text. Changing the text of a window or a control can be
taken care of by calling the CWnd::SetWindowText() method. Its syntax is:

void SetWindowText(LPCTSTR lpszString);

The lpszString argument is a null-terminated string that holds the value you want to
display. It can be configured using any of the valid null-terminated string operations
available. Here is an example that changes the title of a dialog box when the window
displays. The text is provided as a null-terminated string passed to the method:

BOOL CDismissDlg::OnInitDialog()
{
Free download pdf