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

📄 listctrlex.cpp

📁 AD 数据采集卡基本的采集界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:

void CListCtrlEx::OnPaint() 
{
	// in full row select mode, we need to extend the clipping region
	// so we can paint a selection all the way to the right
	if(m_bClientWidthSel && (GetStyle() & LVS_TYPEMASK)==LVS_REPORT && GetFullRowSel())
	{
		CRect rcAllLabels;
		GetItemRect(0,rcAllLabels,LVIR_BOUNDS);

		if(rcAllLabels.right<m_cxClient)
		{
			// need to call BeginPaint (in CPaintDC c-tor)
			// to get correct clipping rect
			CPaintDC dc(this);

			CRect rcClip;
			dc.GetClipBox(rcClip);

			rcClip.left=min(rcAllLabels.right-1,rcClip.left);
			rcClip.right=m_cxClient;

			InvalidateRect(rcClip,FALSE);
			// EndPaint will be called in CPaintDC d-tor
		}
	}

	CListCtrl::OnPaint();
}
*/
void CListCtrlEx::OnSetFocus(CWnd* pOldWnd) 
{
	CListCtrl::OnSetFocus(pOldWnd);

	// check if we are getting focus from label edit box
	if(pOldWnd!=NULL && pOldWnd->GetParent()==this)
		return;

	// repaint items that should change appearance
	if(m_bFullRowSel && (GetStyle() & LVS_TYPEMASK)==LVS_REPORT)
		RepaintSelectedItems();
}

void CListCtrlEx::OnKillFocus(CWnd* pNewWnd) 
{
	CListCtrl::OnKillFocus(pNewWnd);

	// check if we are losing focus to label edit box
	if(pNewWnd!=NULL && pNewWnd->GetParent()==this)
		return;

	// repaint items that should change appearance
	if(m_bFullRowSel && (GetStyle() & LVS_TYPEMASK)==LVS_REPORT)
		RepaintSelectedItems();
}

void CListCtrlEx::PreSubclassWindow() 
{
	CListCtrl::PreSubclassWindow();
	EnableToolTips(TRUE);
}

int CListCtrlEx::CellRectFromPoint(CPoint& point, CRect* pRectCell, int* pCol) const
{
    if((::GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
	   return -1;

    int nRow = GetTopIndex();
    int nBottom = nRow + GetCountPerPage();
    if(nBottom > GetItemCount())
		nBottom = GetItemCount();
        
    CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
    int nColumnCount = pHeader->GetItemCount();

    for(; nRow <= nBottom; nRow++)
    {
        CRect rect;
        GetItemRect(nRow, &rect, LVIR_BOUNDS);
        if(rect.PtInRect(point))
        {
			for(int nColumn = 0; nColumn < nColumnCount; nColumn++)
			{
				int nColWidth = GetColumnWidth(nColumn);
				if(point.x >= rect.left && point.x <= (rect.left + nColWidth))
				{
					CRect rectClient;
					GetClientRect(&rectClient);
					if(pCol)
						*pCol = nColumn;
					
					rect.right = rect.left + nColWidth;

					if(rect.right > rectClient.right) 
						rect.right = rectClient.right;
					
					*pRectCell = rect;
					
					return nRow;
				}

				rect.left += nColWidth;
			}
		}
	}

	return -1;
}

BOOL CListCtrlEx::OnToolTipText(UINT /*uID*/, NMHDR* pNMHDR, LRESULT* pResult)
{
    BOOL bRet = TRUE;
#ifdef _TOOL_TIP_ENABLE
	TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
    TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
    UINT nID = pNMHDR->idFrom;
    if(!nID)
    	bRet = FALSE;

	if(bRet)
	{
		int nRow = ((nID-1) >> 10) & 0x3fffff ;
		int nCol = (nID-1) & 0x3ff;
		CString strTipText = GetItemText(nRow, nCol);
		strTipText.TrimRight();
		strTipText.TrimLeft();
#ifndef _UNICODE
		if (pNMHDR->code == TTN_NEEDTEXTA)
			lstrcpyn(pTTTA->szText, strTipText, 80);
		else
			_mbstowcsz(pTTTW->szText, strTipText, 80);
#else
		if(pNMHDR->code == TTN_NEEDTEXTA)
			_wcstombsz(pTTTA->szText, strTipText, 80);
		else
			lstrcpyn(pTTTW->szText, strTipText, 80);
#endif
	}
    
	*pResult = 0;
#endif

    return bRet;
}

int CListCtrlEx::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
	int nID = -1;
#ifdef _TOOL_TIP_ENABLE
	int nCol;
	CRect rect;
	int nRow = CellRectFromPoint(point, &rect, &nCol);
	if(nRow == -1 ) 
		return -1;
	
	pTI->hwnd = m_hWnd;
	pTI->uId = (UINT)((nRow << 10) + (nCol & 0x3ff) + 1);
	nID = pTI->uId
	pTI->lpszText = LPSTR_TEXTCALLBACK;
	
	pTI->rect = rect;
#endif
	
	return nID;
}
int CListCtrlEx::HitTestEx(CPoint &point, int *col)
{
	int column = 0;
	int row = HitTest( point,NULL );
	if( col ) *col = 0;
	
	// Make sure that the ListView is in LVS_REPORT
	if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
		return row;

	// Get the top and bottom row visible
	row = GetTopIndex();
	int bottom = row + GetCountPerPage();
	if( bottom > GetItemCount() )
		bottom = GetItemCount();
	
	// Get the number of columns
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();

	// Loop through the visible rows
	for( ;row <=bottom;row++)
	{
		// Get bounding rect of item and check whether point falls in it.
		CRect rect;
		GetItemRect( row, &rect, LVIR_BOUNDS );
		if( rect.PtInRect(point) )
		{
			// Now find the column
			for( column = 0; column < nColumnCount; column++ )
			{
				int colwidth = GetColumnWidth(column);
				if( point.x >= rect.left 
					&& point.x <= (rect.left + colwidth ) )
				{
					if( col ) *col = column;
					CString tp;
					return row;
				}
				rect.left += colwidth;
			}
		}
	}
	if( col ) *col = -1;
	return -1;
}

void CListCtrlEx::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	// TODO: Add your control notification handler code here
	LV_ITEM	*plvItem = &pDispInfo->item;
	CString str;int num,count=0,tmpNum;
	if (plvItem->pszText != NULL)
	{
		SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText);
		for(int i=0;i<GetItemCount();i++)
		{
			str=GetItemText(i,1);
			num=(int)strtol(str,NULL,10);
			ADPara.ChannelArray[i].ADChannel =num;
			str=GetItemText(i,2);
			num=(int)strtol(str,NULL,10);
		
			tmpNum=strtol(str,NULL,10);
			
			switch(tmpNum)
			{
			case 1:
				//str.Format("%d",ADPara.Gains[ChannelArray.ChannelArray [i].ADChannel[j]]);
				num=PCI2006_1MULT_GAINS;
				break;
			case 10:
				num=PCI2006_10MULT_GAINS;
				break;
			case 100:
				num=PCI2006_100MULT_GAINS;
				break;			
			case 1000:
				num=PCI2006_1000MULT_GAINS;
				break;			
			}
			//ADPara.ChannelArray[i].ADGains =num;//设定增益
			ADPara.ChannelArray [i].ADGains =num;
		}
		ADPara.ChannelCount =GetItemCount();
	}
	*pResult = 0;
}

void CListCtrlEx::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	int index;
	int column;
	if( ( index = HitTestEx( point, &column )) != -1 )
	{
		index =HitTestEx( point, &column );
		{
			{
				if(EnsureVisible (index,TRUE)==FALSE) return;

				CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
				int nColumnCount = pHeader->GetItemCount();
				if( column >= nColumnCount ||GetColumnWidth(column) < 5 )
					return ;

				// Get the column offset
				int offset = 0;
				for( int i = 0; i < column; i++ )
					offset += GetColumnWidth( i );

				CRect rect;
				GetItemRect(index,&rect,LVIR_BOUNDS);
				// Now scroll if we need to expose the column
				CRect rcClient;
				GetClientRect( &rcClient );
				if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
				{
					CSize size;
					size.cx = offset + rect.left;
					size.cy = 0;
					Scroll( size );
					rect.left -= size.cx;
				}

	// Get Column alignment
				LV_COLUMN lvcol;
				lvcol.mask = LVCF_FMT;
				GetColumn( column, &lvcol );
				DWORD dwStyle ;
				if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
					dwStyle = ES_LEFT;
				else if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
					dwStyle = ES_RIGHT;
				else dwStyle = ES_CENTER;
				rect.top-=2;
				rect.left += offset-1;
				rect.right = rect.left + GetColumnWidth( column ) +2 ;
				if( rect.right > rcClient.right) rect.right = rcClient.right;
				rect.bottom =rect.top+150;
				if(column==2)
				{
					dwStyle |= CBS_DROPDOWN|WS_VISIBLE|CBS_SIMPLE;
					pEdit = new CMyComboBox(index, column,GetItemText( index, column ));
					pEdit->Create(dwStyle,rect,this,IDC_LISTEDIT );
					pEdit->AddString("1倍");
					pEdit->AddString("10/2倍");
					pEdit->AddString("100/4倍");
					pEdit->AddString("1000/8倍");
					CString str=GetItemText(index,column);					
					int i;
					if(str=="1倍")
						i=0;
					if(str=="10/2倍")
						i=1;
					if(str=="100/4倍")
						i=2;
					if(str=="1000/8倍")
						i=3;

					pEdit->SetCurSel(i);
				}	
				if(column==1)
				{
					dwStyle |= CBS_DROPDOWNLIST|WS_VISIBLE|WS_VSCROLL   |CBS_SIMPLE;
					pEdit = new CMyComboBox(index, column,GetItemText( index, column ));
					pEdit->Create(dwStyle,rect,this,IDC_LISTEDIT );
					CString str;
					for(int ComBoCount=0;ComBoCount<MAX_CHANNELCOUNT;ComBoCount++)
					{//加入通道号
						str.Format("%d",ComBoCount);
						pEdit->AddString(str);
					}
					ComBoCount=HitTest (point,NULL);//取得list中列号						
					str=GetItemText(ComBoCount,column);
					i=strtol(str,NULL,10);						
					pEdit->SetCurSel(i);
					
				}
			}
		}
	}

	CListCtrl::OnLButtonDblClk(nFlags, point);
}


void CListCtrlEx::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	pParaCfgView->ReadPara();	
	CListCtrl::OnLButtonUp(nFlags, point);
}

int CListCtrlEx::GetCheckCount()
{
	LONG Count=0;
	int i=GetItemCount();
	for(int x=0;x<i;x++)
	{
		if(GetCheck(x))
			Count++;
	}
	return Count;
}

⌨️ 快捷键说明

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