TB_ADDSTRING
在工具栏的数据结构中,有一个字符串列表,在添加或者插入工具栏按钮的时候,可以使用这个列表中的字符串作为按钮文字。TB_ADDSTRING 消息用来向工具栏的字符串列表添加一个或多个新的字符串。
TB_ADDSTRING
wParam = (WPARAM) (HINSTANCE) hinst;
lParam = (LPARAM) MAKELONG(idString, 0 );
wParam = (WPARAM) (HINSTANCE) hinst;
lParam = (LPARAM) MAKELONG(idString, 0 );
Parameters
hinst
Handle to the module instance with an executable file that contains the string resource. If idString instead points to a character array with one or more strings, set this parameter to NULL.
idString
Resource identifier for the string resource. If hinst is set to NULL, idString points to a character array with one or more null-terminated strings. The last string in the array must be terminated with two null characters.
Return Values
Returns the index of the first new string if successful, or -1 otherwise.
Remarks
上面的内容 Copy 自 MSDN,尽管我知道大家英语水平都挺不错的,但我还是画蛇添足地给大家解释一下。按照 MSDN 的意思,TB_ADDSTRING 的参数存在以下两种组合方式:
方式一:
wParam = (HINSTANCE)hinst; // 包含字符串资源的模块句柄
lParam = (MAKELONG)(idString, 0); // 一个字符串资源的资源 ID
lParam = (MAKELONG)(idString, 0); // 一个字符串资源的资源 ID
在 MFC 的 CToolBarCtrl 中,我们可以找到与之对应的封装函数 CToolBarCtrl::AddString(),其实现如下:
int
CToolBarCtrl::AddString(UINT nStringID)
{
ASSERT(::IsWindow(m_hWnd));
HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE((nStringID >> 4 ) + 1 ),
RT_STRING);
ASSERT(hInst != NULL);
return ( int )::SendMessage(m_hWnd, TB_ADDSTRING, (W
{
ASSERT(::IsWindow(m_hWnd));
HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE((nStringID >> 4 ) + 1 ),
RT_STRING);
ASSERT(hInst != NULL);
return ( int )::SendMessage(m_hWnd, TB_ADDSTRING, (W