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

📄 emdlistctrl.cpp

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

#include "stdafx.h"
#include "yhgl.h"
#include "EMDListCtrl.h"
#include "EMDEditCell.h"


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

CString csText;
/////////////////////////////////////////////////////////////////////////////
// CEMDListCtrl

CEMDListCtrl::CEMDListCtrl()
{
}

CEMDListCtrl::~CEMDListCtrl()
{
}

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

/////////////////////////////////////////////////////////////////////////////
// CEMDListCtrl message handlers

// Edit sub item
CEdit* CEMDListCtrl::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

        // 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;
	if(nSubItem==2)
    dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL|ES_PASSWORD;
	else
    dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
	
	bool doubleLimited = false;
    //if (nSubItem == 4 || nSubItem == 5) doubleLimited = true;可以控制输入值的类型
    
	CEdit* pEdit = new CEMDEditCell( 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 CEMDListCtrl::InsertItemEx( int nItem )
{
	int cntItem = 0;
    int nResult = -1;
    CString csNO;

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

void CEMDListCtrl::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)
		{
            EditSubItem( info.iItem, info.iSubItem );
		}
    }
}

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

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



void CEMDListCtrl::updateStringItem(int nItem, int nSubItem, LPCTSTR dval)
{
	if (nSubItem ==0 ) return;
	if(strcmp(csText,dval)==0) return;
	else
	{
      switch (nSubItem)
	  {
	  case 1:
		  {
			  Info[nItem].flag1=1;
			  Info[nItem].qname = dval;
              Info[nItem].qname = Info[nItem].qname.Left(30);
		       break;
		  }
		
	  case 2:
		  { 
			  Info[nItem].flag2=1;
			  Info[nItem].qcode = dval;
			  Info[nItem].qcode = Info[nItem].qcode.Left(8);
		      break;
		  }
	  case 3:
		  {
              Info[nItem].flag3=1;
			  Info[nItem].qdes = dval;
			  Info[nItem].qdes =Info[nItem].qdes.Left(40);
		      break;
		  }
	  default:
		      break;
	  }
	}
}

⌨️ 快捷键说明

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