📄 yxlistctrl.cpp
字号:
// YxListCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "YxListCtrl.h"
#include "Xt9702Slave.h"
#include "Xt9702SlaveDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//extern CMycomDlg* CMycomdlg;
/////////////////////////////////////////////////////////////////////////////
// CYxListCtrl
CYxListCtrl::CYxListCtrl()
{
m_pEdit = NULL;
}
CYxListCtrl::~CYxListCtrl()
{
delete m_pEdit;
}
BEGIN_MESSAGE_MAP(CYxListCtrl, CListCtrl)
//{{AFX_MSG_MAP(CYxListCtrl)
ON_WM_LBUTTONDBLCLK()
ON_EN_KILLFOCUS(IDC_EDIT_CTRL, OnEnKillFocus)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYxListCtrl message handlers
void CYxListCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CListCtrl::OnLButtonDblClk(nFlags, point);
CXt9702SlaveDlg* pFrame = ( CXt9702SlaveDlg* )GetParent();
SYSTEMTIME systime;
LVHITTESTINFO hti = {0};
CString str = _T( "" );
hti.pt = point;
if( SubItemHitTest( &hti ) == -1 ) return;
int iItem = hti.iItem;
int iSubItem = hti.iSubItem;
if( iItem == -1 || iSubItem == -1 ) return;
CRect rect;
GetSubItemRect( iItem, iSubItem, LVIR_LABEL, rect );
ClientToScreen( rect );
CPoint pt( rect.right, rect.bottom );
CRect rc;
GetWindowRect( rc );
if( !rc.PtInRect( pt ) ) SendMessage( WM_VSCROLL, SB_LINEDOWN, 0 );
pt.x = rect.left;
pt.y = rect.top;
if( !rc.PtInRect( pt ) ) SendMessage( WM_VSCROLL, SB_LINEUP, 0 );
m_iRow = iItem;
m_iCol = iSubItem;
switch( m_iCol ) {
case 1:
str = GetItemText( m_iRow, m_iCol );
if( str == _T( " ■" ) ) {
SetItemText( m_iRow, m_iCol, _T( " □" ) );
pFrame->SetCOS( m_iRow, FALSE );
GetLocalTime( &systime );
pFrame->SetSOE( m_iRow, FALSE, systime );
}
else if( str == _T( " □" ) ) {
SetItemText( m_iRow, m_iCol, _T( " ■" ) );
pFrame->SetCOS( m_iRow, TRUE );
GetLocalTime( &systime );
pFrame->SetSOE( m_iRow, TRUE, systime );
}
else {
SetItemText( m_iRow, m_iCol, _T( " □" ) );
pFrame->SetCOS( m_iRow, FALSE );
GetLocalTime( &systime );
pFrame->SetSOE( m_iRow, FALSE, systime );
}
break;
case 2:
break;
case 3: OnShowEditCtrl(); break;
default: break;
}
}
void CYxListCtrl::OnShowEditCtrl( void )
{
if( m_iRow >= GetItemCount() ) return;
if( GetItemData( m_iRow ) & 1 ) {
if( m_pEdit ) m_pEdit->ShowWindow( SW_HIDE );
return;
}
CRect rect;
GetSubItemRect( m_iRow, m_iCol, LVIR_LABEL, rect );
rect.top;
if( m_pEdit == NULL ) {
m_pEdit = new CEdit;
m_pEdit->Create( WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_TABSTOP | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL,
rect, this, IDC_EDIT_CTRL );
m_pEdit->SetFont( GetFont() );
m_pEdit->ShowWindow( SW_SHOW );
}
else {
m_pEdit->SetWindowPos( NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW );
}
TCHAR szItem[256] = {0};
LVITEM item;
item.mask = LVIF_TEXT;
item.iItem = m_iRow;
item.iSubItem = m_iCol;
item.cchTextMax = ARRSIZE( szItem );
item.pszText = szItem;
GetItem( &item );
m_pEdit->SetWindowText( szItem );
m_pEdit->SetSel( 0, -1 );
m_pEdit->SetFocus();
m_pEdit->BringWindowToTop();
}
void CYxListCtrl::OnEnKillFocus()
{
if( m_iRow != -1 && m_iCol != -1 ) {
if( m_pEdit && m_pEdit->IsWindowVisible() ) {
CString strItem;
m_pEdit->GetWindowText( strItem );
strItem.TrimLeft();
strItem.TrimRight();
SetItemText( m_iRow, m_iCol, strItem );
}
}
if( m_pEdit ) m_pEdit->ShowWindow( SW_HIDE );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -