MFC CEdit失去焦点处理程序 [英] MFC CEdit lose focus handler
问题描述
我正在使用文档/视图架构创建MFC程序.在视图中,我调用扩展CEdit的单元格类以绘制文本框.效果很好,但是,当我尝试捕获该文本框的焦点丢失消息时,什么也没发生.我试图覆盖PreTranslateMessage,但是没有用.
I am creating a MFC program using the document/view architecture. In the view I call on a cell class that extends CEdit to draw a text box. That works fine, however, when I try to catch a lose focus message for that text box nothing happens. I tried to overwrite PreTranslateMessage but that didn't work.
这是CGridView.cpp类中的代码:
Here's the code in the CGridView.cpp class:
void CGridView::OnInsertText()
{
CWnd* pParentWnd = this;
CellText* pEdit = new CellText(&grid, pParentWnd);
Invalidate();
UpdateWindow();
}
CellText.cpp:
the CellText.cpp:
CellText::CellText(Grid *pgrid, CWnd* pParentWnd)
{
int *pcoordinates = pgrid->GetSelectedCellCoodrinates();
cedit.Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, CRect(*pcoordinates+10, *(pcoordinates+1)+10, *(pcoordinates+2)-10, *(pcoordinates+3)-10), pParentWnd, 1);
cell = pgrid->GetSelectedCell();
pgrid->SetCellType(cell, "text");
grid = pgrid;
}
BEGIN_MESSAGE_MAP(CellText, CEdit)
ON_WM_KILLFOCUS()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
// CellText message handlers
void CellText::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
CString str;
GetWindowTextW(str);
grid->SetCellText(cell, str);
cedit.DestroyWindow();
}
BOOL CellText::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_UP)
{
}
}
return CWnd::PreTranslateMessage(pMsg);
}
当我调试时,根本没有调用onkillfocus和pretranslatemessage.
When I debug, the onkillfocus and pretranslatemessage aren't called at all.
谢谢
推荐答案
您必须在父窗口中处理EN_KILLFOCUS
通知代码.您不必从CEdit派生出来.
You have to handle the EN_KILLFOCUS
notification code in the parent window. You shouldn't have to derive from CEdit to do that.
更新:
编辑控件的父窗口接收此通知代码 通过WM_COMMAND消息.
The parent window of the edit control receives this notification code through a WM_COMMAND message.
wParam::LOWORD包含编辑控件的标识符.这 HIWORD指定通知代码.
wParam: The LOWORD contains the identifier of the edit control. The HIWORD specifies the notification code.
lParam:-处理编辑控件.
这篇关于MFC CEdit失去焦点处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!