2010年3月9日 星期二

(MFC)Thread- Afxbeginthread

先貼上我成功宣告的thread
光宣告就花了我好久的時間...
CChildView.cpp
UINT CChildView::WorkerThreadProc(LPVOID Param) //Sample function for using in AfxBeginThread
{
CChildView* pView = (CChildView*) Param;

return 0;
}

在要呼叫thread的地方寫上
AfxBeginThread(WorkerThreadProc,(LPVOID)this);
CChildView.h
static UINT WorkerThreadProc(LPVOID Param);

會用很久的原因在於我一直不想把WorkerThreadProc 宣告成成員function
我用成全域function 但是一直不能編譯成功
後來只好放棄改用成員function,但宣告成成員function一定要宣告成靜態
不然會一直編譯失敗...

2010年3月2日 星期二

CString:: right && CString ::left 用法

CString Left(int nCount)

Parameters

nCount
Specifies the number of characters to extract from this CString object.

Return Value

A CString object containing a copy of the specified range of characters. Note that the returned CString object may be empty.

Example

The following example demonstrates the use of CString::Left.

// example for CString::Left CString s(_T("abcdef")); ASSERT(s.Left(2) == _T("ab"));
left和right的用法是相同的
只是算個數的方向不同
left - 是從左數到右
right - 是從右數到左

CString cs = _T("abcdef");
字串.left(個數) =>ex. cs.left(2) = _T("ab");
字串.right(個數) =>ex. cs.right(2) = _T("ef");

ReverseFind 使用

最近會用到ReverseFind,之前有找一下資料
可是都會忘....

Return Value

The index of the last character in this CString object that matches the requested character; –1 if the character is not found.

Parameters

ch

The character to search for.

Remarks

Searches this CStringstrrchr. object for the last match of a substring. The function is similar to the run-time function

Example

// Example for CString::ReverseFind
CString s( "abcabc" );
ASSERT( s.ReverseFind( 'b') == 4 );

這是msdn上的解釋
我每次再回來看都是有點看不懂
所以我又上網找了一下別人的解釋

原來有一個跟ReverseFind 類似的字串符搜尋api 就是Find

CString str = "abcdbc";
int x1 = str.Find('b');
int x2 = str.ReverseFind('b');
x2 = 4;
x1 = 1;


後來我終於知道他們的差異在哪 T_T




Find 是找第一個'b'

ReverseFind 是找最後一個'b'