我有一个对话框,其中包括3个EditControl框和2个用于验证输入数据的对话框。当Editcontrol失去焦点时,我们将使用OnKillFocus方法验证输入的数据,并由于多次调用OnKIllFocus而面临挂起问题,此后,我们为每个Editcontrol分离了每个KillFocus,仍然面临着多次调用KillFocus的相同问题>
`BEGIN_MESSAGE_MAP(CWHPwdDlg, CDialog)
ON_BN_CLICKED(IDOK, OnOK)
ON_BN_CLICKED(IDCANCEL, OnCancel)
ON_WM_CTLCOLOR()
ON_EN_KILLFOCUS(IDC_HMI_SERVERNAME, OnKillFocusServerNameTextBox)
ON_EN_KILLFOCUS(IDC_WH_RT_PORT, OnKillFocusPortTextBox)
ON_EN_KILLFOCUS(IDC_HMI_USERNAME, OnKillFocusUserNameTextBox)
ON_EN_KILLFOCUS(IDC_HMI_PASSWORD, OnKillFocusPwdTextBox)
ON_BN_CLICKED(IDC_WH_RT_TEST_CONNECTION, OnTestConnection)
ON_BN_CLICKED(IDC_WH_RT_VIEW_CERT, OnViewCertificate)
ON_BN_CLICKED(IDC_WH_RT_REQUIRE_TRUST, OnCheckEnableTrust)
END_MESSAGE_MAP()
void CWHPwdDlg::OnKillFocusServerNameTextBox()
{
MessageBoxA(NULL, "Click", "Servername", MB_OK);
if (!UpdateData(TRUE)) {
return;
}
CWnd* pWndOk = GetDlgItem(IDOK);
//if (m_hmiServerName.IsEmpty())
if(m_hmiServerName.GetLength()<=0)
{
m_TestConnection.EnableWindow(FALSE);
SetDlgItemText(IDC_WH_RT_TRUSTED_MSG, _T(""));
CWnd* p_CertificateButton = GetDlgItem(IDC_WH_RT_VIEW_CERT);
if (p_CertificateButton != NULL)
p_CertificateButton->EnableWindow(FALSE);
CWnd* pTrustCheck = GetDlgItem(IDC_WH_RT_REQUIRE_TRUST);
if (pTrustCheck != NULL)
pTrustCheck->EnableWindow(FALSE);
m_whErrorStr.SetWindowText(m_strServerNameError);
m_whErrorStr.ShowWindow(SW_SHOW);
m_whErrorIcon.ShowWindow(SW_SHOW);
pWndOk->EnableWindow(FALSE);
return;
}
else
{
SetCertificateAndEnableViewer();
}
}
void CWHPwdDlg::OnKillFocusPortTextBox()
{
MessageBoxA(NULL, "Click", "KillPort", MB_OK);
if (!UpdateData(TRUE)) {
return;
}
CWnd* pWndOk = GetDlgItem(IDOK);
if (m_hmiPortNum.IsEmpty() || m_hmiPortNum == _T("0"))
{
m_whErrorStr.SetWindowText(m_strPortError);
m_whErrorStr.ShowWindow(SW_SHOW);
m_whErrorIcon.ShowWindow(SW_SHOW);
pWndOk->EnableWindow(FALSE);
//return FALSE;
}
}
void CWHPwdDlg::OnKillFocusUserNameTextBox()
{
MessageBoxA(NULL, "Click", "KillUserName", MB_OK);
if (!UpdateData(TRUE)) {
return;
}
CWnd* pWndOk = GetDlgItem(IDOK);
if (m_hmiUserName.IsEmpty())
{
m_whErrorStr.SetWindowText(m_strUserNameError);
m_whErrorStr.ShowWindow(SW_SHOW);
m_whErrorIcon.ShowWindow(SW_SHOW);
pWndOk->EnableWindow(FALSE);
// return FALSE;
}
}
`