[英]MFC CEdit lose focus handler
我正在使用文檔/視圖架構創建MFC程序。 在視圖中,我調用一個擴展CEdit的單元類來繪制文本框。 但是,當我嘗試捕獲該文本框的丟失焦點消息時,沒有任何反應。 我試圖覆蓋PreTranslateMessage,但這不起作用。
這是CGridView.cpp類中的代碼:
void CGridView::OnInsertText()
{
CWnd* pParentWnd = this;
CellText* pEdit = new CellText(&grid, pParentWnd);
Invalidate();
UpdateWindow();
}
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。
謝謝,
您必須在父窗口中處理EN_KILLFOCUS
通知代碼。 你不應該從CEdit派生來做到這一點。
更新:
編輯控件的父窗口通過WM_COMMAND消息接收此通知代碼。
wParam: LOWORD包含編輯控件的標識符。 HIWORD指定通知代碼。
lParam: - 處理編輯控件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.