How do I get CIPAddressCtrl to support tabbing between tuple fields using period

本小妞迷上赌 提交于 2020-01-15 10:15:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!