strtok()
功能:查找由在第二个串中指定的分界符分隔开的单词
例子:
Ex1. strtok("0736-8888888","-"); 返回字符串 "0736"
Ex2. strtok("0736-8888888","6-"); 返回字符串 "073"
Ex3. strtok("0736-8888888","&"); 返回字符串 "NULL"
首先看下MSDN上的解释:
char *strtok( char *strToken, const char *strDelimit );
Parameters
strToken
String containing token or tokens.
strDelimit
Set of delimiter characters.
Return Value
Returns a pointer to the next token found in strToken. They return NULL when no more tokens are found. Each call modifies strToken by substituting a NULL character for each delimiter that is encountered.
简单的说,就是函数返回第一个分隔符分隔的子串后,将第一参数设置为NULL,函数将返回剩下的子串。
下面我们来看一个例子:
int main()
{
char test1[] = "feng,ke,wei";
char *test2 = "feng,ke,wei";
char *p;
p = strtok(test1, ",");
while(p)
{
printf("%s\n", p);
p = strtok(NULL, ",");
}
return 0;
}
运行结果:
feng
ke
wei
----------------------------------
CTreeCtrl::SelectItem
Call this function to select the given tree view item.
BOOL SelectItem( HTREEITEM hItem );
Parameters
-
hItem
-
Handle of a tree item.
Return Value---Nonzero if successful; otherwise 0.
Remarks---If hItem is NULL, then this function selects no item.
Example
// The pointer to my tree control.
extern CTreeCtrl* pmyTreeCtrl;
// The point to test.
extern CPoint myPoint;// Select the item that is at the point myPoint.
UINT uFlags;
HTREEITEM hItem = pmyTreeCtrl->HitTest(myPoint, &uFlags);if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
pmyTreeCtrl->SelectItem(hItem);
}
-------------------------------------------
CTreeCtrl::HitTest
Call this function to determine the location of the specified point relative to the client area of a tree view control.
HTREEITEM HitTest(
CPoint pt,
UINT* pFlags = NULL
) const;
HTREEITEM HitTest(
TVHITTESTINFO* pHitTestInfo
) const;
Parameters
-
pt
-
Client coordinates of the point to test.
-
pFlags
-
Pointer to an integer that receives information about the results of the hit test. It can be one or more of the values listed under the flags member in the Remarks section.
-
pHitTestInfo
-
Address of a TVHITTESTINFO structure that contains the position to hit test and that receives information about the results of the hit test.
Return Value---The handle of the tree view item that occupies the specified point or NULL if no item occupies the point.
Remarks---When this function is called, the pt parameter specifies the coordinates of the point to test. The function returns the handle of the item at the specified point or NULL if no item occupies the point. In addition, the pFlags parameter contains a value that indicates the location of the specified point.
Example
// The pointer to my tree control.
extern CTreeCtrl* pmyTreeCtrl;
// The point to test.
extern CPoint myPoint;// Select the item that is at the point myPoint.
UINT uFlags;
HTREEITEM hItem = pmyTreeCtrl->HitTest(myPoint, &uFlags);if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
pmyTreeCtrl->Select(hItem, TVGN_CARET);
}