Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


// 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
HINSTANCE Instance1 = AfxGetInstanceHandle();
LONG Instance2 = GetWindowLong(m_hWnd, GWL_HINSTANCE);

m_Instance1.Format("%ld", Instance1);
m_Instance2.Format("%ld", Instance2);
UpdateData(FALSE);

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

14.4.2..Changing Control Information..........................................................


We have seen how easy it can be to define the properties, styles, and other characteristics
when creating a control. While the user is interacting with the computer using your
application, you may need to change some of these attributes of a window. To change the
value of an aspect of the window, you can call the SetWindowLong() function. Its
syntax is:

LONG SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong);

If you want to work with a pointer instead of a value, you can use the
SetWindowLongPtr() function. Its syntax is:

LONG_PTR SetWindowLongPtr(HWND hWnd, int nIndex, LONG_PTR dwNewLong);

The hWnd argument is a handle to the window whose informtation you want to change.
The value of nIndex species the type of information you want to change. It can have the
following values:

nIndex Value
GetWindowLong GetWindowLongPtr

Description

GWL_EXSTYLE Allows changing the extended style(s) of the
window or control

GWL_STYLE Allows changing the style(s) of the window or
control
GWL_WNDPROC GWLP_WNDPROC Allows changing the procedure of the control
GWL_HINSTANCE GWLP_HINSTANCE Changes the application instance of the control
GWL_ID GWLP_ID Allows changing the ID value of the control
GWL_USERDATA GWLP_USERDATA Gives access to a 32-bit value associated with the
window, allowing it to be changed

If the hWnd argument represents a dialog box, the nIndex argument can also have the
following values:

nIndex Value
GetWindowLong GetWindowLongPtr

Description

DWL_DLGPROC DWLP_DLGPROC Allows changing the procedure of the dialog box
DWL_MSGRESULT DWLP_MSGRESULT Allows changing the return value of the procedure
Free download pdf