Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


{
// TODO: Add your command handler code here

char NewTitle[] = "Introduction to Windows Programming";

SendMessage(WM_SETTEXT, NULL, reinterpret_cast<LPARAM>(NewTitle));
}

To retrieve the name of a window (always remember that the name of a window is not
the name of a class) or the text stored in a control, you can call the
CWnd::GetWindowText() function. Its syntax is:

int GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) const;

The lpszStringBuf is the null-terminated string that will store the window name. The
nMaxCount is the minimum number of characters of the lpszStringBuf. If you specify
more characters than the name is made of, the compiler would reduce this number to the
actual length of the string. Therefore, it is safe to provide a high number.

Practical Learning: Changing a Control’s Text



  1. The Geometry application should still be opened.
    To perform window text operations, change the Quadrilateral.cpp source file as
    follows:


// Quadrilateral.cpp : implementation file
//

...


// CQuadrilateral message handlers

BOOL CQuadrilateral::OnInitDialog()
{
CPropertyPage::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_SquareSide.SetWindowText("0.00");
m_SquarePerimeter.SetWindowText("0.00");
m_SquareArea.SetWindowText("0.00");
m_RectLength.SetWindowText("0.00");
m_RectHeight.SetWindowText("0.00");
m_RectPerimeter.SetWindowText("0.00");
m_RectArea.SetWindowText("0.00");

return TRUE; // return TRUE unless you set the focus to a control
}

...


void CQuadrilateral::OnBnClickedBtnScalc()
{
Free download pdf