當前位置:首頁 » 操作系統 » cstring源碼

cstring源碼

發布時間: 2023-07-01 14:17:57

Ⅰ 有框架的網頁,如何讀取框架里的源碼

用chtmlview打帶框架網頁寫面函數
BOOL CHtmlView::GetFrameSource( IDispatch *pDisp, CString& refString )
{
BOOL bRetVal = FALSE;
HRESULT hr = S_OK;
if ( pDisp != NULL )
{
CComQIPtr pBrowser = pDisp;
if ( pBrowser != NULL )
{
IDispatch *pDispDoc = NULL;
hr = pBrowser->get_Document(&pDispDoc);
if ( !( FAILED(hr) || !pDisp ) )
{
CComQIPtr pStmInit = pDisp;
if ( !pStmInit )
{
HGLOBAL hMemory;
hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if (hMemory != NULL)
{
CComQIPtr spPSI = pDispDoc;
if( spPSI != NULL)
{
CComPtr spStream;
if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPSI->Save(spStream, FALSE);
LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if (pstr != NULL)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.
bRetVal = TRUE;
TRY
{
refString = pstr;
}
CATCH_ALL(e)
{
bRetVal = FALSE;
DELETE_EXCEPTION(e);
}
END_CATCH_ALL

if(bRetVal == FALSE)
GlobalFree(hMemory);
else
GlobalUnlock(hMemory);
}
}
}
}
}
}
RELEASE(pDispDoc);
}
}
return bRetVal;
}

能用DocumentComplete我知道獲pDisp像DocumentComplete才能獲框架各頁pDisp沒通用性我想要實現像GetSource功能要網頁載完畢任意刻獲框架html源文件!

Ⅱ C++如何調用vb寫的COM組件要附源碼【不是vb調c++ 而是c++調vb】

1.我的VB工程代碼如下:
1)新建工程名為Project1的VB工程,介面為Class1,定義兩個成員變數a和b
2)在Class1中添加代碼
Public a As Integer
Public b As Integer
Private Sub Class_Initialize()
a = 5
b = 9
End Sub
2.我的VC工程代碼如沒伏下:
1)在stdafx.h文件中寫如下代碼
#include <comdef.h>
#import "C:\\Documents and Settings\\user\\桌面卜慎\\VB\型察敬\Project1.dll"
using namespace Project1;
2)在CPP源文件中寫如下調用COM代碼
::CoInitialize(NULL);
_Class1Ptr c1 = NULL;
c1.CreateInstance("Project1.Class1");
short sA = c1->a;
short sB = c1->b;
CString str = _T("");
str.Format(_T("a=%d, b=%d"),sA,sB);
::CoUninitialize();

Ⅲ MFC的CString的數據結構

java裡面的StringBuilder更類似,不是java里String那樣的不變對象。CString採用的是順序存儲。源代碼用了條件編譯,可讀性不好。
class CString
{
public:
// Constructors

// constructs empty CString
CString();
// constructor
CString(const CString& stringSrc);
// from a single character
CString(TCHAR ch, int nRepeat = 1);
// from an ANSI string (converts to TCHAR)
CString(LPCSTR lpsz);
// from a UNICODE string (converts to TCHAR)
CString(LPCWSTR lpsz);
// subset of characters from an ANSI string (converts to TCHAR)
CString(LPCSTR lpch, int nLength);
// subset of characters from a UNICODE string (converts to TCHAR)
CString(LPCWSTR lpch, int nLength);
// from unsigned characters
CString(const unsigned char* psz);

// Attributes & Operations

// get data length
int GetLength() const;
// TRUE if zero length
BOOL IsEmpty() const;
// clear contents to empty
void Empty();

// return single character at zero-based index
TCHAR GetAt(int nIndex) const;
// return single character at zero-based index
TCHAR operator[](int nIndex) const;
// set a single character at zero-based index
void SetAt(int nIndex, TCHAR ch);
// return pointer to const string
operator LPCTSTR() const;

// overloaded assignment

// ref-counted from another CString
const CString& operator=(const CString& stringSrc);
// set string content to single character
const CString& operator=(TCHAR ch);
#ifdef _UNICODE
const CString& operator=(char ch);
#endif
// string content from ANSI string (converts to TCHAR)
const CString& operator=(LPCSTR lpsz);
// string content from UNICODE string (converts to TCHAR)
const CString& operator=(LPCWSTR lpsz);
// string content from unsigned chars
const CString& operator=(const unsigned char* psz);

// string concatenation

// concatenate from another CString
const CString& operator+=(const CString& string);

// concatenate a single character
const CString& operator+=(TCHAR ch);
#ifdef _UNICODE
// concatenate an ANSI character after converting it to TCHAR
const CString& operator+=(char ch);
#endif
// concatenate a UNICODE character after converting it to TCHAR
const CString& operator+=(LPCTSTR lpsz);

friend CString AFXAPI operator+(const CString& string1,
const CString& string2);
friend CString AFXAPI operator+(const CString& string, TCHAR ch);
friend CString AFXAPI operator+(TCHAR ch, const CString& string);
#ifdef _UNICODE
friend CString AFXAPI operator+(const CString& string, char ch);
friend CString AFXAPI operator+(char ch, const CString& string);
#endif
friend CString AFXAPI operator+(const CString& string, LPCTSTR lpsz);
friend CString AFXAPI operator+(LPCTSTR lpsz, const CString& string);

// string comparison

// straight character comparison
int Compare(LPCTSTR lpsz) const;
// compare ignoring case
int CompareNoCase(LPCTSTR lpsz) const;
// NLS aware comparison, case sensitive
int Collate(LPCTSTR lpsz) const;
// NLS aware comparison, case insensitive
int CollateNoCase(LPCTSTR lpsz) const;

// simple sub-string extraction

// return nCount characters starting at zero-based nFirst
CString Mid(int nFirst, int nCount) const;
// return all characters starting at zero-based nFirst
CString Mid(int nFirst) const;
// return first nCount characters in string
CString Left(int nCount) const;
// return nCount characters from end of string
CString Right(int nCount) const;

// characters from beginning that are also in passed string
CString SpanIncluding(LPCTSTR lpszCharSet) const;
// characters from beginning that are not also in passed string
CString SpanExcluding(LPCTSTR lpszCharSet) const;

// upper/lower/reverse conversion

// NLS aware conversion to uppercase
void MakeUpper();
// NLS aware conversion to lowercase
void MakeLower();
// reverse string right-to-left
void MakeReverse();

// trimming whitespace (either side)

// remove whitespace starting from right edge
void TrimRight();
// remove whitespace starting from left side
void TrimLeft();

// trimming anything (either side)

// remove continuous occurrences of chTarget starting from right
void TrimRight(TCHAR chTarget);
// remove continuous occcurrences of characters in passed string,
// starting from right
void TrimRight(LPCTSTR lpszTargets);
// remove continuous occurrences of chTarget starting from left
void TrimLeft(TCHAR chTarget);
// remove continuous occcurrences of characters in
// passed string, starting from left
void TrimLeft(LPCTSTR lpszTargets);

// advanced manipulation

// replace occurrences of chOld with chNew
int Replace(TCHAR chOld, TCHAR chNew);
// replace occurrences of substring lpszOld with lpszNew;
// empty lpszNew removes instances of lpszOld
int Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
// remove occurrences of chRemove
int Remove(TCHAR chRemove);
// insert character at zero-based index; concatenates
// if index is past end of string
int Insert(int nIndex, TCHAR ch);
// insert substring at zero-based index; concatenates
// if index is past end of string
int Insert(int nIndex, LPCTSTR pstr);
// delete nCount characters starting at zero-based index
int Delete(int nIndex, int nCount = 1);

// searching

// find character starting at left, -1 if not found
int Find(TCHAR ch) const;
// find character starting at right
int ReverseFind(TCHAR ch) const;
// find character starting at zero-based index and going right
int Find(TCHAR ch, int nStart) const;
// find first instance of any character in passed string
int FindOneOf(LPCTSTR lpszCharSet) const;
// find first instance of substring
int Find(LPCTSTR lpszSub) const;
// find first instance of substring starting at zero-based index
int Find(LPCTSTR lpszSub, int nStart) const;

// simple formatting

// printf-like formatting using passed string
void AFX_CDECL Format(LPCTSTR lpszFormat, ...);
// printf-like formatting using referenced string resource
void AFX_CDECL Format(UINT nFormatID, ...);
// printf-like formatting using variable arguments parameter
void FormatV(LPCTSTR lpszFormat, va_list argList);

// formatting for localization (uses FormatMessage API)

// format using FormatMessage API on passed string
void AFX_CDECL FormatMessage(LPCTSTR lpszFormat, ...);
// format using FormatMessage API on referenced string resource
void AFX_CDECL FormatMessage(UINT nFormatID, ...);

// input and output
#ifdef _DEBUG
friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,
const CString& string);
#endif
friend CArchive& AFXAPI operator<<(CArchive& ar, const CString& string);
friend CArchive& AFXAPI operator>>(CArchive& ar, CString& string);

// load from string resource
BOOL LoadString(UINT nID);

#ifndef _UNICODE
// ANSI <-> OEM support (convert string in place)

// convert string from ANSI to OEM in-place
void AnsiToOem();
// convert string from OEM to ANSI in-place
void OemToAnsi();
#endif

#ifndef _AFX_NO_BSTR_SUPPORT
// OLE BSTR support (use for OLE automation)

// return a BSTR initialized with this CString's data
BSTR AllocSysString() const;
// reallocates the passed BSTR, copies content of this CString to it
BSTR SetSysString(BSTR* pbstr) const;
#endif

// Access to string implementation buffer as "C" character array

// get pointer to modifiable buffer at least as long as nMinBufLength
LPTSTR GetBuffer(int nMinBufLength);
// release buffer, setting length to nNewLength (or to first nul if -1)
void ReleaseBuffer(int nNewLength = -1);
// get pointer to modifiable buffer exactly as long as nNewLength
LPTSTR GetBufferSetLength(int nNewLength);
// release memory allocated to but unused by string
void FreeExtra();

// Use LockBuffer/UnlockBuffer to turn refcounting off

// turn refcounting back on
LPTSTR LockBuffer();
// turn refcounting off
void UnlockBuffer();

// Implementation
public:
~CString();
int GetAllocLength() const;

protected:
LPTSTR m_pchData; // pointer to ref counted string data

// implementation helpers
CStringData* GetData() const;
void Init();
void AllocCopy(CString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
void AllocBuffer(int nLen);
void AssignCopy(int nSrcLen, LPCTSTR lpszSrcData);
void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data, int nSrc2Len, LPCTSTR lpszSrc2Data);
void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
void CopyBeforeWrite();
void AllocBeforeWrite(int nLen);
void Release();
static void PASCAL Release(CStringData* pData);
static int PASCAL SafeStrlen(LPCTSTR lpsz);
static void FASTCALL FreeData(CStringData* pData);
};

熱點內容
編程忌諱 發布:2025-03-20 04:58:35 瀏覽:425
國家知識產權專利資料庫 發布:2025-03-20 04:54:29 瀏覽:414
win7怎麼給文件夾設密碼 發布:2025-03-20 04:52:38 瀏覽:723
安卓手機電影怎麼投屏到ipad上 發布:2025-03-20 04:27:23 瀏覽:677
蘋果安卓基於什麼開發 發布:2025-03-20 04:20:52 瀏覽:520
演算法化是 發布:2025-03-20 03:48:20 瀏覽:771
拆二代訪問 發布:2025-03-20 03:47:34 瀏覽:63
隨機數排序c語言 發布:2025-03-20 03:35:31 瀏覽:498
當前頁面腳本發生錯誤類型不匹配 發布:2025-03-20 03:26:47 瀏覽:993
strutsajax上傳圖片 發布:2025-03-20 03:25:03 瀏覽:386