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

📄 mylistctrl.cpp

📁 SQLBig5BugTool 宽字符操作问题
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}
		
		for(l=0;l<m_CopyOnSelectedColumnNameList.size();l++)
		{
			if(0!=l)
			{
				strTxtAll+=m_strCopyOnSelectedColumnSeperator;
			}
			strTxt="";
			if(!GetItemTextByName(nItem,m_CopyOnSelectedColumnNameList[l].c_str(),strTxt))
			{
			};
			
			strTxtAll+=strTxt;
		}
	}
	if(strTxtAll.IsEmpty())
	{
		AfxMessageBox("没有选中的项");
		return ;
	}	
	
	CopyTextToClipboard(GetSafeHwnd(),strTxtAll);
}

void CMyListCtrl::SetCopySelectedColumnInfo(
											const char* pszColumnNameList,
											const BOOL  bCopyHeader,
											const char* pszColumnSeperator
											)
{
	ParseString(pszColumnNameList,";",m_CopyOnSelectedColumnNameList);
	
	ASSERT(m_CopyOnSelectedColumnNameList.size()>0);
	
	m_strCopyOnSelectedColumnSeperator=pszColumnSeperator;
	
	ASSERT(!m_strCopyOnSelectedColumnSeperator.IsEmpty());
	
	m_bCopyHeader=bCopyHeader;
}

void CMyListCtrl::SelectAllItems()
{
	for(long l=0;l<GetItemCount();l++)
	{
		SetItemState(l,LVIS_SELECTED,LVIS_SELECTED);
	}
}

void CMyListCtrl::SetIItemColorModifier(IItemColorModifier *pIItemColorModifier)
{
	m_pIItemColorModifier=pIItemColorModifier;
}


BOOL SetResourceString(
					   LPCTSTR szModuleFilePath, 
					   const DWORD dwResId,
					   LPCTSTR szNewString,
					   WORD wIDLanguage
					   )
{
	HANDLE h = ::BeginUpdateResource(szModuleFilePath,FALSE);
	if(!h)
	{
		// BeginUpdateResource failed
		return FALSE;
	}
	if(strlen(szNewString)>1024)
	{
		return FALSE;
	}
	WCHAR wcsNewString[1024]={0,};
	MultiByteToWideChar(CP_ACP, NULL, szNewString,-1, wcsNewString, _countof(wcsNewString));
	
	/*
	CString sNewString = szNewString;
	int iCharCount = sNewString.GetLength() + 1;
	LPWSTR pUnicodeString = new WCHAR[iCharCount];
	if(!pUnicodeString)
	{
	// new failed
	return FALSE;
	}
	DWORD dwUnicodeCharCount = 
	MultiByteToWideChar(CP_ACP, NULL, sNewString.GetBuffer(0), 
	-1, pUnicodeString, iCharCount);
	HGLOBAL hGlob =
	GlobalAlloc(GHND, (dwUnicodeCharCount + 4) * sizeof(WCHAR) );
	if(!hGlob)
	{
	// GlobalAlloc failed
	delete pUnicodeString;
	return FALSE;
	}
	LPWSTR pBufStart = (LPWSTR)GlobalLock(hGlob);
	if(!pBufStart)
	{
	// GlobalLock failed
	GlobalFree(hGlob);
	delete pUnicodeString;
	return FALSE;
	}
	LPWSTR pBuf = pBufStart;
	pBuf++;
	// offset to make it string ID=1. Increment by more
	// to change to a different string ID
	
	  // next 2 bytes is string length
	  *(pBuf++) = (WCHAR)dwUnicodeCharCount-1;
	  for(int i=0; i<(int)dwUnicodeCharCount-1; i++)
	  // remaining bytes are string in wide chars (2 bytes each)
	  *(pBuf++) = pUnicodeString[i];
	  delete pUnicodeString;
	  if(++dwUnicodeCharCount % 1)
	  // make sure we write an even number
	  dwUnicodeCharCount++;
	*/
	
	BOOL bSuccess = ::UpdateResource(
		h, RT_STRING, MAKEINTRESOURCE(dwResId), 
		wIDLanguage, 
		wcsNewString, (wcslen(wcsNewString)+1) * sizeof(WCHAR)
		);
	
	::EndUpdateResource(h, FALSE); // write changes 
	return bSuccess; 
}

BOOL SelectListCtrlItems(
						 STRING_LIST&	StrList,
						 CMyListCtrl*	pListCtrl,
						 const char*	pszColName
						 )
{
	long lColIndex=pListCtrl->FindColumnIndex(pszColName);
	if(lColIndex<0)
	{
		return FALSE;
	}
	
	for(long l=0;l<pListCtrl->GetItemCount();l++)
	{
		CString strTxt=pListCtrl->GetItemText(l,lColIndex);
		if(StrList.end()!=std::find(StrList.begin(),StrList.end(),(const char*)strTxt))
		{
			pListCtrl->SetItemState(l,LVIS_SELECTED,LVIS_SELECTED);
		}
	}
	return TRUE;
}

BOOL GetListCtrlSelectedItems(
							  CMyListCtrl*	pListCtrl,
							  const char*	pszColName,
							  STRING_LIST&	StrList,
							  const BOOL		bClearStrList
							  )
{
	if(bClearStrList)
	{
		StrList.clear();
	}
	long lColIndex=pListCtrl->FindColumnIndex(pszColName);
	if(lColIndex<0)
	{
		return FALSE;
	}
	POSITION pos=pListCtrl->GetFirstSelectedItemPosition();
	long lItem=-1;
	while(pos)
	{
		lItem=pListCtrl->GetNextSelectedItem(pos);
		
		CString strTxt=pListCtrl->GetItemText(lItem,lColIndex);
		
		StrList.push_back((const char*)strTxt);
	}
	return TRUE;
}

BOOL CMyListCtrl::SaveAllAsHTML(
								const char* pszColumnNameList,
								const char *pszHTMLFilePath,
								const char* pszFontName,
								const DWORD dwFontSize
								)
{
	STRING_LIST ColumnNameList;
	ParseString(pszColumnNameList,";",ColumnNameList);
	
	CStdioFile f;
	if(!f.Open(pszHTMLFilePath,CFile::typeText|CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone))
	{
		return FALSE;
	}
	f.WriteString("<html>");
	f.WriteString("\n");
	f.WriteString("<header>");
	f.WriteString("\n");
	f.WriteString("</header>");
	f.WriteString("\n");
	f.WriteString("<body>");
	f.WriteString("\n");
	f.WriteString(FormatString(
		"<table BORDER=1  style=\"face:%s font-family:%s  size:%dpt\"> ",
		pszFontName,
		pszFontName,
		dwFontSize
		).c_str());
	f.WriteString("\n");
	
	long l=0;
	//////
	f.WriteString("<tr>");
	f.WriteString("\n");
	
	for(l = 0; l < ColumnNameList.size(); l++)
	{  
		f.WriteString("<td>");
		
		f.WriteString(ColumnNameList[l].c_str());
		
		f.WriteString("</td>");
		f.WriteString("\n");
	}
	f.WriteString("</tr>");
	f.WriteString("\n");
	
	//
	for(long k=0;k<GetItemCount();k++)
	{
		COLORREF clrTextBk=RGB(0,0,0);
		
		if(m_pIItemColorModifier)
		{
			clrTextBk = m_pIItemColorModifier->GetItemColor(this,k);
		}
		
		CString strRow=FormatString(
			"<tr style=\"background:RGB(%u,%u,%u)\">",
			GetRValue(clrTextBk),
			GetGValue(clrTextBk),
			GetBValue(clrTextBk)			
			).c_str();
		
		f.WriteString(strRow);
		
		f.WriteString("\n");
		
		for(l = 0; l < ColumnNameList.size(); l++)
		{
			CString strTxt=GetItemTextByName(k,ColumnNameList[l].c_str());
			
			f.WriteString("<td>");
			f.WriteString(FormatString(
				"<font style=\"color:RGB(%u,%u,%u) \">",
				GetRValue(GetTextColor()),
				GetGValue(GetTextColor()),
				GetBValue(GetTextColor())
				).c_str());
			
			f.WriteString(strTxt);
			
			f.WriteString("</font>");
			f.WriteString("</td>");
			f.WriteString("\n");
		}
		
		
		f.WriteString("</tr>");
		f.WriteString("\n");
	}
	f.WriteString("</table>");
	f.WriteString("\n");
	
	f.WriteString("</body>");
	f.WriteString("\n");
	
	f.WriteString("</html>");
	f.WriteString("\n");
	return TRUE;
}
								
void CMyListCtrl::DisableDeleteShortKey(const BOOL bDisableDeleteShortKey)
{
	m_bDisableDeleteShortKey=bDisableDeleteShortKey;
}

void CMyListCtrl::SetEnsureVisible(const BOOL bEnsureVisible)
{
	m_bEnsureVisible=bEnsureVisible;
}

void CMyListCtrl::DeleteAllSelectedItems()
{	
	POSITION pos = GetFirstSelectedItemPosition();
	while(pos)
	{
		int nItem = GetNextSelectedItem(pos);
		
		DeleteItem(nItem);

		pos = GetFirstSelectedItemPosition();
	}
}

void CMyListCtrl::AddColumnText(const char *pszColumn, STRING_LIST &TxtList,const BOOL bClearBeforeInsert)
{
	if(bClearBeforeInsert)
	{
		DeleteAllItems();
	}
	
	for(long l=0;l<TxtList.size();l++)
	{
		long lRow=AddRow();

		SetItemTextByName(lRow,pszColumn,TxtList[l].c_str());
	}
}

BOOL CMyListCtrl::SetRowText(const LONG lRow, STRING_LIST &RowTxtList)
{
	if(lRow<0)
	{
		return FALSE;
	}
	if(lRow>=GetItemCount())
	{
		return FALSE;
	}
	
	if(!GetHeaderCtrl()->GetSafeHwnd())
	{
		return FALSE;
	}
	
	long l=0;
	long lCount = Header_GetItemCount(GetHeaderCtrl()->GetSafeHwnd());

	if(lCount!=RowTxtList.size())
	{
		return FALSE;
	}
	
	for(l = 0; l < lCount; l++)
	{  
		SetItemText(lRow,l,RowTxtList[l].c_str());
	}
	return TRUE;
}

BOOL CMyListCtrl::GetRowText(const LONG lRow, STRING_LIST &RowTxtList)
{
	RowTxtList.clear();

	if(lRow<0)
	{
		return FALSE;
	}
	if(lRow>=GetItemCount())
	{
		return FALSE;
	}
	
	if(!GetHeaderCtrl()->GetSafeHwnd())
	{
		return FALSE;
	}
	
	long l=0;
	long lCount = Header_GetItemCount(GetHeaderCtrl()->GetSafeHwnd());
	
	for(l = 0; l < lCount; l++)
	{  
		CString strTxt=GetItemText(lRow,l);
		RowTxtList.push_back((const char*)strTxt);
	}
	return TRUE;
}

BOOL CMyListCtrl::GetColumnText(const char *pszColumn, STRING_LIST &TxtList,const BOOL bSelectedOnly)
{
	TxtList.clear();
	
	long lIndex=FindColumnIndex(
		pszColumn
		);
	if(lIndex<0)
	{
		return FALSE;
	}

	CString strTxt;

	if(bSelectedOnly)
	{
		POSITION pos=GetFirstSelectedItemPosition();
		while(pos)
		{
			long lItem=GetNextSelectedItem(pos);
			
			strTxt=GetItemText(lItem,lIndex);
			TxtList.push_back((const char*)strTxt);
		}
	}
	else
	{
		for(long l=0;l<GetItemCount();l++)
		{
			strTxt=GetItemText(l,lIndex);
			TxtList.push_back((const char*)strTxt);
		}
	}
	
	return TRUE;
}

void CMyListCtrl::SetIToolTip(IToolTip *pIToolTip)
{
	m_pIToolTip=pIToolTip;
}


BOOL CMyListCtrl::SwapLine(const long lLine1, const long lLine2,const bool bAutoSelectLine2)
{
	if(lLine1==lLine2)
	{
		return TRUE;
	}
	STRING_LIST RowTxtList1;
	STRING_LIST RowTxtList2;

	if(!GetRowText(lLine1,RowTxtList1))
	{
		return FALSE;
	};
	if(!GetRowText(lLine2,RowTxtList2))
	{
		return FALSE;
	};
	
	if(!SetRowText(lLine1,RowTxtList2))
	{
		return FALSE;
	};
	if(!SetRowText(lLine2,RowTxtList1))
	{
		return FALSE;
	};

	OnSwapLine(lLine1,lLine2);

	if(bAutoSelectLine2)
	{
		SetItemState(lLine1,0,LVIS_SELECTED|LVIS_FOCUSED);
		SetItemState(lLine2,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
	}
	return TRUE;
}

void CMyListCtrl::OnSwapLine(const long lLine1, const long lLine2)
{

}

⌨️ 快捷键说明

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