Page 57 - DCAP408_WEB_PROGRAMMING
P. 57
Unit 4: Windows Controls
If you are required to programmatically access the properties of a control without using a Notes
connected variable, you may have to call the CWnd::GetDlgItem() member function. It occurs
in two versions as follows:
CWnd* GetDlgItem(int nID) const;
void CWnd::GetDlgItem(int nID, HWND* phWnd) const;
When calling this member function, the first version permits you to allocate a CWnd (or derived
class) to it. The second version returns a handle to the window passed as pointer.
!
Caution In both cases, you must pass the identifier of the control that you would like to
access.
When using the first version, if the control is not a CWnd object, you must cast it to its local class.
Then you can influence the property (or properties) of your option.
Example: Here is an example that accesses a button and modifies its caption:
BOOL CDialog5Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CButton *btnWhatElse = reinterpret_cast<CButton
*>(GetDlgItem(IDC_BUTTON3));
return TRUE; // return TRUE unless you set the focus to a control
}
The second version needs a pointer to a child window that you would like to access.
4.5.3 Enabling or Disabling a Button
For the user to be capable to utilize a control like clicking a button, the control must permit it.
This trait of Windows objects is handled by the CWnd::EnableWindow() member function. Its
syntax is:
BOOL EnableWindow(BOOL bEnable = TRUE);
This member function is utilized to enable or disable a control.
Did u know? The default value of the argument bEnable is set to TRUE, which would exhibit
a control.
To disable a control, set the argument to FALSE.
LOVELY PROFESSIONAL UNIVERSITY 51