CWnd::EnableWindow
Enables or disables mouse and keyboard input.
BOOL EnableWindow( BOOL bEnable = TRUE );
When input is disabled, input such as mouse clicks and keystrokes is ignored. When input is enabled, the window processes all input.
If the enabled state is changing, the WM_ENABLE message is sent before this function returns.
If disabled, all child windows are implicitly disabled, although they are not sent WM_ENABLE messages.
A window must be enabled before it can be activated. For example, if an application is displaying a modeless dialog box and has disabled its main window, the main window must be enabled before the dialog box is destroyed. Otherwise, another window will get the input focus and be activated. If a child window is disabled, it is ignored when Windows tries to determine which window should get mouse messages.
By default, a window is enabled when it is created. An application can specify the WS_DISABLED style in the Create or CreateEx member function to create a window that is initially disabled. After a window has been created, an application can also use the EnableWindow member function to enable or disable the window.
An application can use this function to enable or disable a control in a dialog box. A disabled control cannot receive the input focus, nor can a user access it.
//CMyFileDialog is a CFileDialog-derived class //OnInitDialog is the handler for WM_INITDIALOG BOOL CMyFileDialog::OnInitDialog() { CFileDialog::OnInitDialog(); CWnd* pWndParent = GetParent(); //make sure you add #include <dlgs.h> for IDs 'edt1' & 'stc3' //disables the 'file name' edit and static control //of the standard file open dialog //get handle of 'file name' combobox control & disable it CWnd* pWnd = pWndParent->GetDlgItem(cmb13); pWnd->EnableWindow(FALSE); //get handle of 'file name' static control & disable it pWnd = pWndParent->GetDlgItem(stc3); pWnd->EnableWindow(FALSE); return TRUE; }