Filter the EN_KILLFOCUS message from CIPAddressCtrl
-
You will get a EN_KILLFOCUS message,when the focus switch from CIPAddressCtrl to another control, and this is normal case. But when you click at the dots among four ip fields, you will get the EN_KILLFOCUS message too(with SPY++), which is not what I want, because I just want to do data validation when the CIPAddressCtrl lost focus. How can I filer the EN_KILLFOCUS message when I click the dots??? :doh:
-
You will get a EN_KILLFOCUS message,when the focus switch from CIPAddressCtrl to another control, and this is normal case. But when you click at the dots among four ip fields, you will get the EN_KILLFOCUS message too(with SPY++), which is not what I want, because I just want to do data validation when the CIPAddressCtrl lost focus. How can I filer the EN_KILLFOCUS message when I click the dots??? :doh:
Not sure if this will work or not, but in the message handler for EN_KILLFOCUS, check where the focus "went" with GetFocus[^] or CWnd::GetFocus[^] (whichever suits you best) and determine if the newly focused control is still "inside" the IP address control. I suspect it has four separate edit fields for each segment and all four have the IP address control thing set as its parent, so i supose a GetParent[^] or CWnd::GetParent[^] call can tell you if the user is still editing the IP address or is trying to leave the control altogether. If you try this, do share with us if it worked or not, thanks in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<
-
Not sure if this will work or not, but in the message handler for EN_KILLFOCUS, check where the focus "went" with GetFocus[^] or CWnd::GetFocus[^] (whichever suits you best) and determine if the newly focused control is still "inside" the IP address control. I suspect it has four separate edit fields for each segment and all four have the IP address control thing set as its parent, so i supose a GetParent[^] or CWnd::GetParent[^] call can tell you if the user is still editing the IP address or is trying to leave the control altogether. If you try this, do share with us if it worked or not, thanks in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<
Thank you mat. You are right.I just call GetFocus and determine weather the EN_KILLFOCUS comes from the focused control.
BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
UINT notificationCode = (UINT)HIWORD(wParam);
if (notificationCode == EN_KILLFOCUS || notificationCode == CBN_KILLFOCUS)
{
HWND hwnd = (HWND)lParam;
if (hwnd == NULL)
{
return false;
}
CWnd* pWnd = CWnd::FromHandle(hwnd);
int nID = pWnd->GetDlgCtrlID();
if (GetFocus() != NULL && GetFocus()->m_hWnd == pWnd->m_hWnd) // Add this
{
return false;
}
GetParent()->PostMessage(UM_KILLFOCUS, nID, 0);
}
return CDialog::OnCommand(wParam, lParam);
} -
Thank you mat. You are right.I just call GetFocus and determine weather the EN_KILLFOCUS comes from the focused control.
BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
UINT notificationCode = (UINT)HIWORD(wParam);
if (notificationCode == EN_KILLFOCUS || notificationCode == CBN_KILLFOCUS)
{
HWND hwnd = (HWND)lParam;
if (hwnd == NULL)
{
return false;
}
CWnd* pWnd = CWnd::FromHandle(hwnd);
int nID = pWnd->GetDlgCtrlID();
if (GetFocus() != NULL && GetFocus()->m_hWnd == pWnd->m_hWnd) // Add this
{
return false;
}
GetParent()->PostMessage(UM_KILLFOCUS, nID, 0);
}
return CDialog::OnCommand(wParam, lParam);
}A bit less "specific" than the approach i might have chosen, but if it works for you, then great! :thumbsup:
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<