📄 celledit.cpp
字号:
// CellEdit.cpp : implementation file
//
#include "stdafx.h"
#include "CellEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCellEdit
CCellEdit::CCellEdit(CWnd* pParent, CRect& rect, UINT nID, int nRow, int nColumn, CString strText, bool bEditable)
{
m_strText = strText;
m_nRow = nRow;
m_nColumn = nColumn;
m_bEditable = bEditable;
DWORD dwEditStyle = WS_BORDER|WS_CHILD|WS_VISIBLE| ES_AUTOHSCROLL
| ES_LEFT;
if (!Create(dwEditStyle, rect, pParent, nID))
return;
SetFont(pParent->GetFont());
SetWindowText(strText);
SetFocus();
}
CCellEdit::~CCellEdit()
{
}
BEGIN_MESSAGE_MAP(CCellEdit, CEdit)
//{{AFX_MSG_MAP(CCellEdit)
ON_WM_KILLFOCUS()
ON_WM_CHAR()
ON_WM_GETDLGCODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCellEdit message handlers
void CCellEdit::CloseEdit()
{
CString str;
GetWindowText(str);
NMHDR32 hdr32;
hdr32.hwndFrom = GetSafeHwnd();
hdr32.idFrom = GetDlgCtrlID();
hdr32.code = GVN_ENDLABELEDIT;
hdr32.nRow = m_nRow;
hdr32.nCol = m_nColumn;
hdr32.strText = str;
CWnd* pOwner = GetOwner();
if (pOwner && m_bEditable)
pOwner->SendMessage(WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&hdr32);
// Close this window (PostNcDestroy will delete this)
PostMessage(WM_CLOSE, 0, 0);
}
void CCellEdit::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
CloseEdit();
}
void CCellEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if (nChar == VK_TAB || nChar == VK_RETURN)
{
GetParent()->SetFocus(); // This will destroy this window
return;
}
if (nChar == VK_ESCAPE)
{
m_bEditable = false;
GetParent()->SetFocus();
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
void CCellEdit::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CEdit::PostNcDestroy();
delete this;
}
BOOL CCellEdit::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_SYSCHAR)
return TRUE;
return CEdit::PreTranslateMessage(pMsg);
}
UINT CCellEdit::OnGetDlgCode()
{//重载该函数可强制窗口(CWin)接收所有键盘信息
return DLGC_WANTALLKEYS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -