问题
You must actually be editing a tuple to get the dot to behave as desired. So if I want to change 10.0.1.10 to 10.0.1.11, I must type "10.0.1.11" because the dot does NOT behave like a TAB. I would like to type just "...11", but the dots are ignored until you are editing a tuple. Doh!
Any ideas on how to make this work?
回答1:
By default IP address control does not respond to '.' unless the cursor is at the end of the sub field edit control, only then, it will move to the next field.
Override PreTranslateMessage in parent window/dialog to change the default behavior. The code below adds optional support for tab as well.
BOOL CMyDialog::PreTranslateMessage(MSG *msg)
{
if(msg->message == WM_KEYDOWN)
{
CWnd *focus = GetFocus();
if(ip_address.IsChild(focus))
{
//don't proceed unless the field is set
if(focus->GetWindowTextLength() && (
msg->wParam == VK_DECIMAL ||
msg->wParam == VK_OEM_PERIOD ||
msg->wParam == VK_TAB))
{
//undocumented method to find the current field:
int field = GetWindowLongPtr(focus->m_hWnd, GWL_USERDATA);
//set focus to next field:
if(field >= 0 && field < 3)
{
ip_address.SetFieldFocus(field + 1);
return TRUE;
}
}
}
}
return CDialog::PreTranslateMessage(msg);
}
来源:https://stackoverflow.com/questions/53011876/how-do-i-get-cipaddressctrl-to-support-tabbing-between-tuple-fields-using-period