Article ID: 136302
Article Last Modified on 12/1/2003
class CMySheet : public CWnd
To this:
class CMySheet : public CPropertySheet
DECLARE_DYNAMIC(CMySheet)
CMySheet(UINT nIDCaption, CWnd *pParentWnd = NULL,
UINT iSelectPage = 0 ) : CPropertySheet(nIDCaption,
pParentWnd, iSelectPage) { }
CMySheet(LPCTSTR pszCaption, CWnd *pParentWnd = NULL,
UINT iSelectPage = 0 ) : CPropertySheet(pszCaption,
pParentWnd, iSelectPage) { }
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
BOOL CMySheet::PreTranslateMessage(MSG* pMsg)
{
// check for special cancel modes for ComboBoxes
if (pMsg->message == WM_LBUTTONDOWN ||
pMsg->message == WM_NCLBUTTONDOWN)
_AfxCancelModes(pMsg->hwnd); // filter clicks
return CPropertySheet::PreTranslateMessage(pMsg);
}
/* Compile options needed: Default AppWizard options
*/
#ifdef _AFXDLL // define the functions
BOOL PASCAL _AfxIsComboBoxControl(HWND hWnd, UINT nStyle)
{
if (hWnd == NULL)
return FALSE;
// do cheap style compare first
if ((UINT)(::GetWindowLong(hWnd, GWL_STYLE) & 0x0F) != nStyle)
return FALSE;
// do expensive classname compare next
// If using 16-bit Visual C++, use the following code
static char BASED_CODE szComboBox[] = "combobox";
char szCompare[sizeof(szComboBox) + 1];
::GetClassName(hWnd, szCompare, sizeof(szCompare));
// else if using 32-bit Visual C++, use the following code
// and comment out the code above.
//
// static const TCHAR szComboBox[] = _T("combobox");
// TCHAR szCompare[sizeof(szComboBox)/sizeof(szCompare[0])+1];
// ::GetClassName(hWnd, szCompare,
// sizeof(szCompare)/sizeof(szCompare[0]) );
return (lstrcmpi(szCompare, szComboBox) == 0);
}
void PASCAL _AfxCancelModes(HWND hWndRcvr)
{
// if we receive a message destined for a window, cancel any
// combobox popups that could be in toolbars or dialog bars
HWND hWndCancel = ::GetFocus();
if (hWndCancel == NULL)
return; // nothing to cancel
if (hWndCancel == hWndRcvr)
return; // let input go to window with focus
// focus is in part of a combo-box
if (!_AfxIsComboBoxControl(hWndCancel, (UINT)CBS_DROPDOWNLIST))
{
// try as a dropdown
hWndCancel = ::GetParent(hWndCancel);// parent of edit is combo
if (hWndCancel == hWndRcvr)
return; // let input go to part of combo
if (!_AfxIsComboBoxControl(hWndCancel, (UINT)CBS_DROPDOWN))
return; // not a combo-box that is active
}
// combo-box is active, but if receiver is a popup, do nothing
if (hWndRcvr != NULL &&
(::GetWindowLong(hWndRcvr, GWL_STYLE) & WS_CHILD) != 0 &&
::GetParent(hWndRcvr) == ::GetDesktopWindow())
return;
// finally, you should cancel the mode !
::SendMessage(hWndCancel, CB_SHOWDROPDOWN, FALSE, 0L);
}
#else // just prototype it
void PASCAL _AfxCancelModes(HWND hWndRcvr);
#endifAdditional query words: 2.00 2.51 2.52 3.00 3.10 3.20
Keywords: kbbug kbfix kbpropsheet kbuidesign kbvc210fix kbvc152fix kbvc220fix kbvc200fix kbcombobox kbcode KB136302