Пример #1
0
BOOL CRegKey::EnumValue(DWORD iValue,CString& strName,LPDWORD lpdwType,LPBYTE lpbData,LPDWORD lpcbData) const
{
	DWORD cb=2048;
	LONG ret=::RegEnumValue(m_hKey,iValue,strName.GetBuffer(2048),&cb,0,lpdwType,lpbData,lpcbData);
	strName.FreeExtra();
	return ret==ERROR_SUCCESS;
}
CString CRichEditCtrl::GetSelText() const
{
	CString str;
	::SendMessage(m_hWnd,EM_GETSELTEXT,0,(LPARAM)str.GetBuffer(1000));
	str.FreeExtra();
	return str;
}
Пример #3
0
BOOL CRegKey::EnumKey(DWORD iSubkey,CString& strName,LPSTR lpszClass,LPDWORD lpcchClass,PFILETIME lpftLastWrite) const
{
	DWORD cb=50,cb2=cb;
	LONG ret=::RegEnumKeyEx(m_hKey,iSubkey,strName.GetBuffer(cb),&cb2,0,lpszClass,lpcchClass,lpftLastWrite);
	while (ret==ERROR_MORE_DATA)
	{
		cb+=50;
		cb2=cb;
		ret=::RegEnumKeyEx(m_hKey,iSubkey,strName.GetBuffer(cb),&cb2,0,lpszClass,lpcchClass,lpftLastWrite);
	}
	strName.FreeExtra(cb2);
	return ret==ERROR_SUCCESS;
}
CString CTreeCtrl::GetItemText(HTREEITEM hItem) const
{
	CString str;
	TV_ITEM ti;
	ti.mask=TVIF_TEXT;
	ti.hItem=hItem;
	ti.pszText=str.GetBuffer(1000);
	ti.cchTextMax=1000;
	int nRet=(int)::SendMessage(m_hWnd,TVM_GETITEM,0,(LPARAM)&ti);
	if (nRet>0)
		str.FreeExtra(nRet);
	else
		str.Empty();
	return str;
}
BOOL CListCtrl::GetItemText(CString& str,int nItem, int nSubItem) const
{
	LV_ITEM li;
	ZeroMemory(&li,sizeof(LV_ITEM));
	li.mask=LVIF_TEXT;
	li.iItem=nItem;
	li.iSubItem=nSubItem;
	li.pszText=str.GetBuffer(1000);
	li.cchTextMax=1000;
	int nRet=(int)::SendMessage(m_hWnd,LVM_GETITEMTEXT,nItem,(LPARAM)&li);
	if (nRet==0)
		str.Empty();
	else 
		str.FreeExtra(nRet);
	return nRet>0;
}
Пример #6
0
void CCrystalTextBuffer::GetText(int nStartLine, int nStartChar, int nEndLine, int nEndChar, CString &text, LPCTSTR pszCRLF /*= NULL*/)
{
	ASSERT(m_bInit);	//	Text buffer not yet initialized.
						//	You must call InitNew() or LoadFromFile() first!
	ASSERT(nStartLine >= 0 && nStartLine < m_aLines.GetSize());
	ASSERT(nStartChar >= 0 && nStartChar <= m_aLines[nStartLine].m_nLength);
	ASSERT(nEndLine >= 0 && nEndLine < m_aLines.GetSize());
	ASSERT(nEndChar >= 0 && nEndChar <= m_aLines[nEndLine].m_nLength);
	ASSERT(nStartLine < nEndLine || nStartLine == nEndLine && nStartChar < nEndChar);
	
	if (pszCRLF == NULL)
		pszCRLF = crlf;
	int nCRLFLength = lstrlen(pszCRLF);
	ASSERT(nCRLFLength > 0);

	int nBufSize = 0;
	for (int L = nStartLine; L <= nEndLine; L ++)
	{
		nBufSize += m_aLines[L].m_nLength;
		nBufSize += nCRLFLength;
	}

	LPTSTR pszBuf = text.GetBuffer(nBufSize);
	LPTSTR pszCurPos = pszBuf;

	if (nStartLine < nEndLine)
	{
		int nCount = m_aLines[nStartLine].m_nLength - nStartChar;
		if (nCount > 0)
		{
			memcpy(pszBuf, m_aLines[nStartLine].m_pcLine + nStartChar, sizeof(TCHAR) * nCount);
			pszBuf += nCount;
		}
		memcpy(pszBuf, pszCRLF, sizeof(TCHAR) * nCRLFLength);
		pszBuf += nCRLFLength;
		for (int I = nStartLine + 1; I < nEndLine; I ++)
		{
			nCount = m_aLines[I].m_nLength;
			if (nCount > 0)
			{
				memcpy(pszBuf, m_aLines[I].m_pcLine, sizeof(TCHAR) * nCount);
				pszBuf += nCount;
			}
			memcpy(pszBuf, pszCRLF, sizeof(TCHAR) * nCRLFLength);
			pszBuf += nCRLFLength;
		}
		if (nEndChar > 0)
		{
			memcpy(pszBuf, m_aLines[nEndLine].m_pcLine, sizeof(TCHAR) * nEndChar);
			pszBuf += nEndChar;
		}
	}
	else
	{
		int nCount = nEndChar - nStartChar;
		memcpy(pszBuf, m_aLines[nStartLine].m_pcLine + nStartChar, sizeof(TCHAR) * nCount);
		pszBuf += nCount;
	}
	pszBuf[0] = 0;
	text.ReleaseBuffer();
	text.FreeExtra();
}
Пример #7
0
/**
 * @brief Get text of specified lines (ghost lines will not contribute to text).
 * 
 * @param nCrlfStyle determines the EOL type in the returned buffer.
 * If nCrlfStyle equals CRLF_STYLE_AUTOMATIC, we read the EOL from the line buffer
 * 
 * @note This function has its base in CrystalTextBuffer
 * CrystalTextBuffer::GetTextWithoutEmptys() is for a buffer with no ghost lines.
 * CrystalTextBuffer::GetText() returns text including ghost lines.
 * These two base functions never read the EOL from the line buffer, they
 * use CRLF_STYLE_DOS when nCrlfStyle equals CRLF_STYLE_AUTOMATIC.
 */
void CGhostTextBuffer::			/* virtual override */
GetTextWithoutEmptys(int nStartLine, int nStartChar, 
                 int nEndLine, int nEndChar, 
                 CString &text, CRLFSTYLE nCrlfStyle /*= CRLF_STYLE_AUTOMATIC */,
                 bool bExcludeInvisibleLines /*= true*/) const
{
	const size_t lines = m_aLines.size();
	ASSERT(nStartLine >= 0 && nStartLine < static_cast<intptr_t>(lines));
	ASSERT(nStartChar >= 0 && nStartChar <= GetLineLength(nStartLine));
	ASSERT(nEndLine >= 0 && nEndLine < static_cast<intptr_t>(lines));
	ASSERT(nEndChar >= 0 && nEndChar <= GetFullLineLength(nEndLine));
	ASSERT(nStartLine < nEndLine || nStartLine == nEndLine && nStartChar <= nEndChar);
	// some edit functions (copy...) should do nothing when there is no selection.
	// assert to be sure to catch these 'do nothing' cases.
//	ASSERT(nStartLine != nEndLine || nStartChar != nEndChar);

	// estimate size (upper bound)
	int nBufSize = 0;
	int i = 0;
	for (i = nStartLine; i <= nEndLine; ++i)
		nBufSize += (GetFullLineLength(i) + 2); // in case we insert EOLs
	LPTSTR pszBuf = text.GetBuffer(nBufSize);

	if (nCrlfStyle != CRLF_STYLE_AUTOMATIC)
	{
		// we must copy this EOL type only
		const CString sEol = GetStringEol (nCrlfStyle);

		for (i = nStartLine; i <= nEndLine; ++i)
		{
			// exclude ghost lines
			if ((GetLineFlags(i) & LF_GHOST) || (bExcludeInvisibleLines && (GetLineFlags(i) & LF_INVISIBLE)))
				continue;

			// copy the line, excluding the EOL
			int soffset = (i == nStartLine ? nStartChar : 0);
			int eoffset = (i == nEndLine ? nEndChar : GetLineLength(i));
			int chars = eoffset - soffset;
			LPCTSTR szLine = m_aLines[i].GetLine(soffset);
			CopyMemory(pszBuf, szLine, chars * sizeof(TCHAR));
			pszBuf += chars;

			// copy the EOL of the requested type
			if (i != ApparentLastRealLine())
			{
				CopyMemory(pszBuf, sEol, sEol.GetLength() * sizeof(TCHAR));
				pszBuf += sEol.GetLength();
			}
		}
	} 
	else 
	{
		for (i = nStartLine; i <= nEndLine; ++i)
		{
			// exclude ghost lines
			if ((GetLineFlags(i) & LF_GHOST) || (bExcludeInvisibleLines && GetLineFlags(i) & LF_INVISIBLE))
				continue;

			// copy the line including the EOL
			int soffset = (i == nStartLine ? nStartChar : 0);
			int eoffset = (i == nEndLine ? nEndChar : GetFullLineLength(i));
			int chars = eoffset - soffset;
			LPCTSTR szLine = m_aLines[i].GetLine(soffset);
			CopyMemory(pszBuf, szLine, chars * sizeof(TCHAR));
			pszBuf += chars;

			// check that we really have an EOL
			if (i != ApparentLastRealLine() && GetLineLength(i) == GetFullLineLength(i))
			{
				// Oops, real line lacks EOL
				// (If this happens, editor probably has bug)
				ASSERT(false);
				CString sEol = GetStringEol (nCrlfStyle);
				CopyMemory(pszBuf, sEol, sEol.GetLength() * sizeof(TCHAR));
				pszBuf += sEol.GetLength();
			}
		}
	}
	text.ReleaseBuffer(static_cast<int>(pszBuf - text));
	text.FreeExtra();
}