Edit问题
win api下 我想在一个对话框的edit里填好文字 按回车把文字发送出去,该如何得到回车这个消息从而发出文字啊
[解决办法]
BOOL CXXXX::PreTranslateMessage(MSG* pMsg)
{
if (pMsg-> hWnd == m_edit.GetSafeHwnd() &&
pMsg-> message == WM_KEYDOWN &&
pMsg-> wParam == VK_RETURN)
{
//....
}
return ....;
}
你也可以自己做一个CEditbox类,重载OnChar()函数,for example,
void CMyEditBox::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar==VK_RETURN)
{
//do something here
}
CEditBox::OnChar(nChar, nRepCnt, nFlags);
}
[解决办法]
virtual void WndProc (Message* m)
{
int WM_CHAR = 0x0102;
if (m-> hWnd == GetSafeHwnd() &&
m-> message == WM_KEYDOWN &&
m-> wParam == VK_RETURN) //这里接受回车消息
{
//....
}
if (m.Msg == WM_CHAR) //这里是只能输入数字
{
if (((char)m.WParam > = '0 ') && ((char)m.WParam <= '9 ') ||
(int)m.WParam == (int)Keys.Back || (int)m.WParam == (int)Keys.Delete)
{
base.WndProc(ref m);
}
}
else
{
base.WndProc(ref m);
}
}