WTL 中CEdit如何设置一个tip,当用户没有输入任何东西的时候作为提示
1. 在声明CEdit m_edtPhoneNumber的类里面声明一个变量:
BOOL m_bedtPhoneNumberInitState;
在initDialog之类的函数里面:
m_bedtPhoneNumberInitState=TRUE;
m_edtPhoneNumber.SetWindowText(_T("请输入手机号"));
2. 在.h文件中添加:
COMMAND_ID_HANDLER(IDC_EDIT_PHONE_NUMBER,OnEditCtrlMsg)
LRESULT OnEditCtrlMsg(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
在.cpp文件中实现:
LRESULT CXXX::OnEditCtrlMsg(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { //如果获得焦点的时候,还是init状态,设置为FALSE if (wNotifyCode==EN_SETFOCUS) { CString strEditText; m_edtPhoneNumber.GetWindowText(strEditText); if (m_bedtPhoneNumberInitState) { m_bedtPhoneNumberInitState=FALSE; m_edtPhoneNumber.SetWindowText(_T("")); } } //如果失去焦点的时候,还是空白的,那么设置为Init状态 else if (wNotifyCode==EN_KILLFOCUS) { CString strEditText; m_edtPhoneNumber.GetWindowText(strEditText); if (strEditText.IsEmpty()) { m_bedtPhoneNumberInitState=TRUE; m_edtPhoneNumber.SetWindowText(_T("请输入手机号")); } else { m_bedtPhoneNumberInitState=FALSE; } } return 0; }