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

📄 listctrlex.cpp.svn-base

📁 vc环境下编译的一个对USB设备进行烧录的驱动程序
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
		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 (ColumnNum = 0; ColumnNum < nColumnCount; ColumnNum++)
			{
				int ColWidth = GetColumnWidth (ColumnNum);
				if (Point.x >= Rect.left && Point.x <= (Rect.left + ColWidth))
				{
					nSubItem = ColumnNum;
					return Row;
				}
				Rect.left += ColWidth;
			}
		}
    }
	
    return -1;
}

CEdit* CListCtrlEx::EditSubItem(int nItem, int nSubItem)
{
    // The returned pointer should not be saved
	
    // Make sure that the item is visible
    if (!EnsureVisible (nItem, TRUE)) return NULL;
	
    // Make sure that nCol is valid
    CHeaderCtrl* pHeader = (CHeaderCtrl*) GetDlgItem(0);
    int nColumnCount = pHeader->GetItemCount();
    if (nSubItem >= nColumnCount || GetColumnWidth (nSubItem) < 5)
		return NULL;
	
    // Get the column offset
    int Offset = 0;
    for (int iColumn = 0; iColumn < nSubItem; iColumn++)
		Offset += GetColumnWidth (iColumn);
	
    CRect Rect;
    GetItemRect (nItem, &Rect, LVIR_BOUNDS);
	
    // Now scroll if we need to expose the column
    CRect ClientRect;
    GetClientRect (&ClientRect);
    if (Offset + Rect.left < 0 || Offset + Rect.left > ClientRect.right)
    {
		CSize Size;
		if (Offset + Rect.left > 0)
			Size.cx = -(Offset - Rect.left);
		else
			Size.cx = Offset - Rect.left;
		Size.cy = 0;
		Scroll (Size);
		Rect.left -= Size.cx;
    }
	
    // Get nSubItem alignment
    LV_COLUMN lvCol;
    lvCol.mask = LVCF_FMT;
    GetColumn (nSubItem, &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.left += Offset+4;
    Rect.right = Rect.left + GetColumnWidth (nSubItem) - 3;
    if (Rect.right > ClientRect.right)
		Rect.right = ClientRect.right;
    dwStyle |= WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
    CEdit *pEdit = new CListCellEdit (nItem, nSubItem, GetItemText (nItem, nSubItem));
    pEdit->Create (dwStyle, Rect, this, IDC_EDITCELL);
	//check to see if the length of input messsage is out of restrict
	pEdit->SetLimitText(255);
	/*
	switch (nSubItem)
	{
	case 1:				//phone book user name
		pEdit->SetLimitText(14);
		break;
	case 2:				//work phone
	case 3:				//home phone
	case 4:				//mobile phone
	case 5:				//fax
		pEdit->SetLimitText(20);
		break;
	case 6:				//email
		pEdit->SetLimitText(40);
		break;
	}
	*/
	
	
	m_ItemIndex = nItem;
	m_SubItemIndex = nSubItem;
	
    return pEdit;
}

int CListCtrlEx::GetItemIndex()
{
	return m_ItemIndex;
}

int CListCtrlEx::GetSubItemIndex()
{
	return m_SubItemIndex;
}

void CListCtrlEx::MoveNextItem()
{
    // Get the number of columns
	CString strIndex;
    CHeaderCtrl* pHeader = (CHeaderCtrl*) GetDlgItem(0);
    int nColumnCount = pHeader->GetItemCount();
	
	m_SubItemIndex++;
	if (m_SubItemIndex > nColumnCount-1)
	{
		m_SubItemIndex = 1;
		m_ItemIndex++;
	}

	if (m_ItemIndex >= GetItemCount())
	{
		strIndex.Format("%d", GetItemCount() + 1);
		InsertItem(GetItemCount(), strIndex);
	}

	
	EditSubItem(m_ItemIndex, m_SubItemIndex);
}

void CListCtrlEx::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	int nItem=0, nSubItem=0;
	int rowHeight=0, rowCnt=0;
	CRect rect;
	CConfigDlg *pDlg = (CConfigDlg *)GetParent();
	char text[255];

	LVCOLUMN col;
	
	col.mask = LVCF_TEXT ;
	col.cchTextMax = 255;
	col.pszText = text;
	
	
    if ((nItem = HitTestEx (point, nSubItem)) != -1)
    {
		if (nSubItem != 0)
		{		
			GetColumn(nSubItem, &col);

			if(strcmp(text, "文件在PC路径") == 0)
			{
				if(m_nIndex != nItem)
				{
					m_nIndex = nItem;
					m_nSubItem = nSubItem;
					m_nInterval = GetTickCount();
				}
				else
				{
					if(m_bHit)
					{
						if(GetTickCount() - m_nInterval > GetDoubleClickTime())
						{
							m_nIndex = -1;
							m_nSubItem = -1;
							m_bHit = FALSE;
							EditSubItem(nItem, nSubItem);
							return;
						}

					}
					else
					{
						m_bHit = TRUE;
					}
				}
			}
		}
	}
	
	CListCtrl::OnLButtonDown(nFlags, point);
}

void CListCtrlEx::OnKillfocusCmbBox() 
{
	m_cmbBox.ShowWindow(SW_HIDE);

	Invalidate();
}

void CListCtrlEx::OnSelchangeCmbBox()
{
	CString selStr;
	if (m_cmbBox)
	{
		m_cmbBox.GetLBText(m_cmbBox.GetCurSel(),selStr);
		SetItemText(m_cmbBox_nItem, m_cmbBox_nSubItem, selStr);	
	}
}

void CListCtrlEx::OnMenuSelect(UINT nID)
{
	extern char Current_DirectoryBuffer[MAX_PATH];

	CRect rect;
	
	char text[255];
	
	CString strIndex;

	CConfigDlg *pDlg = (CConfigDlg *)GetParent();

	LVCOLUMN col;
	
	col.mask = LVCF_TEXT ;
	col.cchTextMax = 255;
	col.pszText = text;

	int i=nID-IMENU_ITEM_ID;

	if(i == 0)//file
	{
		extern HINSTANCE _hInstance;
			
		OPENFILENAME ofn;
		TCHAR pstrFileName[260] = {0}, pstrTitleName[260] = {0};
		
		TCHAR szFilter[] =	TEXT ("BIN Files (*.bin;*.nb0)\0*.bin;*.nb0\0")  \
			TEXT ("All Files (*.*)\0*.*\0\0") ;
		
		memset ( &ofn, 0, sizeof ( ofn ) );
		
		ofn.lStructSize       = sizeof (OPENFILENAME) ;
		ofn.hInstance         = _hInstance ;
		ofn.hwndOwner         = GetSafeHwnd();
		ofn.lpstrFilter       = szFilter;
		ofn.nMaxFile          = MAX_PATH ;
	//	ofn.nMaxFileTitle     = MAX_PATH ;
		ofn.lpstrDefExt       = TEXT ("bin") ;
		ofn.lpstrFile         = pstrFileName ;
	//	ofn.lpstrFileTitle    = pstrTitleName ;
		ofn.Flags             = OFN_FILEMUSTEXIST; 
		

		if(GetOpenFileName (&ofn))
		{
			TCHAR * relative_path = pstrFileName;

			if((relative_path = strstr(pstrFileName, Current_DirectoryBuffer)) != NULL)
			{
				relative_path = pstrFileName + strlen(Current_DirectoryBuffer) + 1;
				SetItemText(m_nIndex, m_nSubItem, relative_path);
			}
			else
				SetItemText(m_nIndex, m_nSubItem, pstrFileName);				
		}
		else
		{
			return;
		}
	}
	else
	{
		extern HINSTANCE _hInstance;


		BROWSEINFO pbi;
		
		memset ( &pbi, 0, sizeof ( pbi ));

		pbi.hwndOwner = GetSafeHwnd();
		pbi.pidlRoot = NULL;
		pbi.lpszTitle = __T("请选择资源树目录路径");
		pbi.ulFlags = BIF_RETURNONLYFSDIRS ;

		LPITEMIDLIST pidl;
		
		if((pidl = SHBrowseForFolder (&pbi)) != NULL)
		{
			TCHAR path[MAX_PATH];
			TCHAR *relative_path;

			SHGetPathFromIDList ( pidl, path );
       

			// free memory used
			IMalloc * imalloc = 0;
			if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
			{
				imalloc->Free ( pidl );
				imalloc->Release ( );
			}

			if((relative_path = strstr(path, Current_DirectoryBuffer)) != NULL)
			{
				relative_path = path + strlen(Current_DirectoryBuffer) + 1;
				SetItemText(m_nIndex, m_nSubItem, relative_path);
			}
			else
				SetItemText(m_nIndex, m_nSubItem, path);	
		}
		else
		{
			return;
		}
	}
}

⌨️ 快捷键说明

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