Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


value lets the pWndInsertAfter be performed but the
window will not be activated
SWP_NOCOPYBITS Normally, after a window has been repositioned, its
controls are restored to their corresponding relative
locations and dimensions. It you want this validation to
be ignored, pass this value
SWP_NOOWNERZORDER
SWP_NOREPOSITION

If this value is passed, this method will not reposition
the windows in the z coordinate
SWP_NOREDRAW When this value is set, the client area of the window
will not be redrawn
SWP_NOSENDCHANGING When this value is set, the window cannot receive a
WM_WINDOWPOSCHANGING message
SWP_SHOWWINDOW Displays the window

In the following example, a window named m_Panel is repositioned and resized:

void CTestDialog::OnBtnMovePanel()
{
// TODO: Add your control notification handler code here
m_Panel.SetWindowPos(NULL, 40, 72, 100, 86, SWP_NOZORDER);
}

14.2.5..The Handle or Pointer to a Window.................................................


Once a control has been created, its identifier set, its location and its dimensions
specified, you and your users can exploit it. On one hand, the user can type a value, select
text, scroll or control or click something. One of your jobs as a programmer is to predict
as many actions as the user may want to perform on your control(s) and take appropriate
actions. We have learned that one good way you can refer to a control in your code
consists of first providing it with an identifier. Another prerequisite you can take is to
declare and associate a control and/or a value variable for your control. Sometimes you
will not have declared a control variable for a control but at one time you need to refer to
it. One way you can do this is to use the control’s identifier and cast it to its
corresponding class. This can be taken care of by calling the CWnd::GetDlgItem()
method. It comes in two versions as follows:

CWnd* GetDlgItem(int nID) const;
void CWnd::GetDlgItem(int nID, HWND* phWnd) const;

By providing the nID argument as the identifier of the control to this method, you can
get a pointer to its class. To do this, you can declare a pointer to the class of the control,
then call the GetDlgItem() method. Because GetDlgItem() returns a CWnd pointer, using
the features of inheritance, cast this return value to the class of the control.

Practical Learning: Accessing a Window’s Handle



  1. The Geometry application should still be opened.
    Open the OnClickedBnUcalc() event of the CGeom3D class

  2. To get handles to the edit boxes on the dialog, implement the event as follows:


void CGeome3D::OnBnClickedBtnUcalc()
{
// TODO: Add your control notification handler code here
// Related Calculations of the cube
Free download pdf