?? yheditcell.cpp
字號(hào):
// YHEditCell.cpp : implementation file
//
#include "stdafx.h"
#include "yhgl.h"
#include "YHEditCell.h"
#include "XListCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CYHEditCell::CYHEditCell( CXListCtrl* userlist,
int nItem, int nSubItem, CString csInitText,bool editDoubleLimitged)
{
m_userlist = userlist;
m_nItem = nItem;
m_nSubItem = nSubItem;
m_csInitText = csInitText;
m_bUndo = false;
bLimitedToDouble = editDoubleLimitged;
}
CYHEditCell::~CYHEditCell()
{
}
BEGIN_MESSAGE_MAP(CYHEditCell, CEdit)
//{{AFX_MSG_MAP(CYHEditCell)
ON_WM_KILLFOCUS()
ON_WM_NCDESTROY()
ON_WM_CHAR()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYHEditCell message handlers
// Set list item text
void CYHEditCell::SetListItemText()
{
CString csText;
GetWindowText( csText );
m_userlist->SetItemText( m_nItem, m_nSubItem, csText,RGB(255,255,255),RGB(0,0,255));
if (!bLimitedToDouble)
m_userlist->updateStringItem( m_nItem, m_nSubItem, csText );
UpdateWindow();
}
BOOL CYHEditCell::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN )
{
if ( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_DELETE
|| pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_TAB
|| pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN
|| GetKeyState(VK_CONTROL) )
{
::TranslateMessage( pMsg );
::DispatchMessage ( pMsg );
return TRUE; // DO NOT process further
}
}
return CEdit::PreTranslateMessage( pMsg );
}
int CYHEditCell::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
// --- Set the proper font ---
CFont* pFont = m_userlist->GetFont();
SetFont( pFont );
SetWindowText( m_csInitText );
SetFocus();
return 0;
}
void CYHEditCell::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
if ( m_bUndo == true ) // User press 'ESC' button
{
}
else
SetListItemText();
DestroyWindow();
}
void CYHEditCell::OnNcDestroy()
{
CEdit::OnNcDestroy();
delete this;
}
void CYHEditCell::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
bool bShift = ( GetKeyState(VK_SHIFT) ) < 0;
switch ( nChar )
{
case VK_ESCAPE :
{
if ( nChar == VK_ESCAPE )
m_bUndo = true;
GetParent()->SetFocus();
return;
}
case VK_RETURN :
{
SetListItemText();
return;
}
default:
if (bLimitedToDouble)
{
if (nChar == 8)
CEdit::OnChar(nChar, nRepCnt, nFlags);
POINT caret;
::GetCaretPos (&caret);
caret.x = LOWORD (CharFromPos (caret));
CString text;
GetWindowText (text);
if (isdigit(nChar))
CEdit::OnChar(nChar, nRepCnt, nFlags);
else if (nChar == '-')
{
if (!caret.x)
{
if (((text.GetLength() > 0) && (text[0]!='-')) || (text.GetLength()==0))
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
else
{
if ((text [caret.x-1] == 'e') || (text [caret.x-1] == 'E'))
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
else if ((nChar == 'e') || (nChar == 'E'))
{
if ((caret.x == 1) && (text[0] == '-'))
return ;
if (caret.x)
{
for (int i=0; i<text.GetLength(); i++)
{
if ((text[i] == 'e') ||(text[i] == 'E'))
return ;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
else if (nChar == '.')
{
for (int i=0; i<text.GetLength(); i++)
{
if (text[i] == '.')
return ;
}
for (i=0; i<text.GetLength(); i++)
{
if (((text[i] == 'e') ||(text[i]=='E')) && (caret.x > i))
return ;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
else
CEdit::OnChar(nChar, nRepCnt, nFlags);
return;
}
}
void CYHEditCell::SetDoubleValue(double val)
{
if (bLimitedToDouble)
{
CString tmp;
tmp.Format ("%G",val);
SetWindowText (tmp);
}
}
double CYHEditCell::GetDoubleValue()
{
if (bLimitedToDouble)
{
CString tmp;
GetWindowText (tmp);
return strtod (tmp,NULL);
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -