⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yhlistctrl.cpp

📁 一个实用的GIS系统的系统维护模块
💻 CPP
字号:
// YHListCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "yhgl.h"
#include "YHListCtrl.h"
#include "YHEditCell.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEMDListCtrl

CYHListCtrl::CYHListCtrl()
{
}

CYHListCtrl::~CYHListCtrl()
{
}

BEGIN_MESSAGE_MAP(CYHListCtrl, CListCtrl)
	//{{AFX_MSG_MAP(CYHListCtrl)
    ON_WM_LBUTTONDOWN()
	ON_WM_VSCROLL()
	ON_WM_HSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CYHListCtrl message handlers

// Edit sub item
CEdit* CYHListCtrl::EditSubItem( int nItem, int nSubItem )
{
    if ( nItem < 0 || nSubItem < 0 )
        return NULL;

    
     int nItems = GetItemCount();
     if ( nItem >= nItems )
        InsertItemEx( nItem );

    if ( !EnsureVisible( nItem, TRUE ) )
    {
		InsertItemEx( nItem );
		if ( !EnsureVisible( nItem, TRUE ) )
			return NULL;
    }

    // Make sure that nSubItem is valid
    CHeaderCtrl* pHeader = GetHeaderCtrl();
    int nColumns = pHeader->GetItemCount();
    if ( nSubItem >= nColumns )//|| GetColumnWidth(nSubItem) < 10 )
		return NULL;   // If column width less than 10 then it didn't be edited

    CString csText;    // Retrieve the text of the selected subItem from the list
    CRect rectEdit;    // Get sub item rectangle that was clicked
    CRect rectClient;  // Get client rectangle of list control
    csText = GetItemText( nItem, nSubItem );
    GetSubItemRect( nItem, nSubItem, LVIR_BOUNDS, rectEdit );
    GetClientRect( &rectClient );

    if ( nSubItem == 0 && nColumns > 1)  // The width is full item width
    { 
        CRect rectSub1;
        GetSubItemRect( nItem, 1, LVIR_BOUNDS, rectSub1 );
        rectEdit.right = rectSub1.left;
    }

    if ( rectEdit.right > rectClient.right )  // Out of client
        rectEdit.right = rectClient.right;

    // Create edit cell
    DWORD dwStyle;
    dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
	
  	bool doubleLimited = false;
	if (nSubItem == 4 ) doubleLimited = true;///可以控制输入值的类型
    
	CEdit* pEdit = new CYHEditCell( this, nItem, nSubItem, csText,doubleLimited);

    if ( pEdit->Create( dwStyle, rectEdit, this, IDC_EDIT_CELL ) == 0 )
        return NULL;  // Crate edit control failed !
    return pEdit;
}

// Extended function of insert item
int CYHListCtrl::InsertItemEx( int nItem )
{
	int cntItem = 0;
    int nResult = -1;
    CString csNO;

	csNO.Format( "%d", maxid+1);
    nResult = InsertItem( nItem, csNO );
	maxid++;
    return nResult;
}

void CYHListCtrl::OnLButtonDown( UINT nFlags, CPoint point )
{
    CListCtrl::OnLButtonDown (nFlags, point);
    LVHITTESTINFO info;
    info.pt = point;
    SubItemHitTest( &info );
    if ( info.flags & LVHT_ONITEMLABEL )
    {
		int it = info.iSubItem;
		if (it == 1 || it == 2||it==3||it==4||it==5)
		   EditSubItem( info.iItem, info.iSubItem );
    }
}

void CYHListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	if ( GetFocus() != this )
        SetFocus();
	
	CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CYHListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	if ( GetFocus() != this )
        SetFocus();
	
	CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -