http://www.codeproject.com/KB/shell/ietoolbartutorial.aspx它这个是设置的第一个按钮的位置, Toolbar也只让你设置第一个按钮的位置. 它将按钮的位置设置到右边, 以后再加入进去的按钮也还是在右边, 所有的都在右边了TB_SETINDENT Message--------------------------------------------------------------------------------Sets the indentation for the first button in a toolbar control. Syntax To send this message, call the SendMessage function as follows. lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) TB_SETINDENT, // message ID (WPARAM) wParam, // = (WPARAM) (INT) iIndent; (LPARAM) lParam // = 0; not used, must be zero );
上图这个是用什么控件来实现的呢??看着不像TOOLBAR又不像是按钮。
http://hi.baidu.com/xiaoxiaodianzi/album/item/cfa719ded2630fe4b7fd482a.html
看了, Codeproject上的所有Toolbar的项目都看了, 结果都没我想要的内容
部长的意思是用microsoft statusbar control控件?? 看样子很像,就用它试试
它将按钮的位置设置到右边, 以后再加入进去的按钮也还是在右边, 所有的都在右边了TB_SETINDENT Message--------------------------------------------------------------------------------Sets the indentation for the first button in a toolbar control. Syntax
To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) TB_SETINDENT, // message ID (WPARAM) wParam, // = (WPARAM) (INT) iIndent; (LPARAM) lParam // = 0; not used, must be zero );
http://hi.csdn.net/attachment/201007/5/418291_1278317571CGtC.jpg
-------------------------------
这样就达到了你的右对齐效果啊, 你只要把EDIT控件的大小填满空白区域,所有的按钮就会被挤到右边了。
能否把你的代码发给我看下,我帮你分析分析。[email protected]
IE上的用的TOOLBAR, 也就是个TOOLBAR.
ZeroMemory((void*)&Button, sizeof(TBBUTTON));
Button.idCommand = IDM_GETQUOTE;
Button.fsState = TBSTATE_ENABLED;
// Button.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT;
Button.dwData = 0;
Button.iString = iIndex;
Button.iBitmap = 0;
::SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)&Button);如果继续添加其它按钮,显示会有问题,必须先把IE toolbar先隐藏再显示才能显示出其它的按钮。有人说知道怎么解决,但没有说出来,不知道楼主能否把真相大白天下?
不会呀, 动态添加按钮一样没问题, 只要把Toolbar的样式设置好了就没问题.我的代码:
/* */
void CXXToolbar::Insert_Button(LPCTSTR srText, int nImg, UINT nCmd, int nIndex, UINT nStyle)
{
int nStr = (int)::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)srText); TBBUTTON Button;
ZeroMemory((void*)&Button, sizeof(TBBUTTON));
Button.iString = nStr;
Button.iBitmap = nImg;
Button.idCommand = nCmd;
Button.fsState = TBSTATE_ENABLED;
Button.fsStyle = nStyle; ::SendMessage(m_hWnd, TB_INSERTBUTTON,
(nIndex == -1) ? Get_Button_Count() : nIndex,
(LPARAM)&Button);
}调用的时候:
Insert_Button(_T("Options"), 4, IDM_CONFIG);
Insert_Button(_T("Login"), 5, IDM_LOGIN);
添加一个按钮这个问题, 我好像也遇到一次, 我一次加入了4个Button, 但显示的时候只有一个, 测试发现是Toolbar的一样式有问题, 就是所有的Button, 不是水平排列的, 全是垂直排列的
嗯, http://www.codeproject.com/KB/shell/ietoolbartutorial.aspx的代码中, 创建Toolbar的时候有这么一个样式: TBSTYLE_WRAPABLE (大概的效果就是将所有的按钮显示在不同的行)去掉后, 全都显示在同一行了. 项目代码不太好传, 大概的效果我上面都说得差不多了, Toolbar左右都分布有按钮. 不知百度, GOOGLE是怎么实现的.
但我用Spy++看百度工具条时, 发现它只有一个toolbar.2. 自己写个toolbar, 想怎样就怎样. (系统的toolbar不让控件每个按钮的RECT)不过, 最好还是用系统的, 如果系统存在这种可行方案的话
按钮下拉箭头: 可以这样,
SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);添加按钮的时候使用 BTNS_DROPDOWN, 或者 BTNS_WHOLEDROPDOWN菜单很好实现的.
另外BTNS_WHOLEDROPDOWN属性添加上去了,鼠标按下去没反应,是不是还需要添加什么消息响应?
我的正常按钮消息是通过ONCOMAND消息响应的,但是下拉菜单按钮消息好像是什么ONNOTIFYREFLE什么的,不知道怎么获取?
确实没反应, 应该要响应什么事件吧, 我没试过, 不过Codeproject上有个项目用过这个的...