Dave's Brain

Browse - Programming Tips - How respond to a user's click on a disabled control?

Date: 2010feb24
Platform: Windows
Language: C/C++

Q.  How respond to a user's click on a disabled control?
After I have done m_MyControl.EnableWindow(FALSE) it does nothing.
(I want a user click to "wake it up").

A.  You need to receive the click in the containing dialog.
With MFC:

BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() // Helper function void GetNormalRect(const CWnd &wnd, CRect &rect) { WINDOWPLACEMENT wp; wnd.GetWindowPlacement(&wp); rect = wp.rcNormalPosition; } void CMyDialog::OnLButtonDown(UINT nFlags, CPoint point) { CRect rect; GetNormalRect(m_MyControl, rect); if (rect.PtInRect(point)) { // The user clicked on my disabled control. // Do whatever I want - eg enable the control: m_MyControl.EnableWindow(TRUE); } }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.