用ctoolbarctrl动态创建了一个toolbar,发现各个button的大小都是同时变化的,我现在要求有一个button比其它button宽一点。找了很多资料好像都没有。于是我试图再创建一个toolbar,紧跟着第一个toolbar(在同一水平线上),结果是第二个toolbar上的button不响应click事件,看起来好像是被第一个toolbar档住了(如果不在水平线上,就可以正确的响应click事件)
哪位可以告诉我怎么样才能在toolbar上实现不等宽的button,或者是如果解决我那个不响应click事件的问题也行。
哪位可以告诉我怎么样才能在toolbar上实现不等宽的button,或者是如果解决我那个不响应click事件的问题也行。
解决方案 »
- 关于MFC中对话框是否存在以及如何销毁的问题
- 用copyfile复制大文件时候时间比较长,能否让界面出现:复制进度对话框?就是我们在windows复制文件时候出现的那个框?可以直接调用吗?
- return (void**)((BYTE*)p + m_nNextOffset); 问题
- 子视图问题
- 系统服务 应用程序 交互
- 各位大哥大姐帮帮我,Mutex不会用!
- CListCtrl无法显示图片
- 用VC写Outlook 2003插件,如何在邮件中插入图片
- 在类里面 对数组的定义和使用
- VC把我的Word杀了,救命
- 请问如何把使用capCreateCaptureWindow创建的视频窗口中当前时刻的影像保存为jpg格式静态图像?
- 我给公司提建议,改善工作环境
memset(&btn, 0, sizeof(TBBUTTON));
btn.fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
然后调用CToolBarCtrl::AddButtons选择了TBSTYLE_AUTOSIZE,button的宽度就和文本长度自适应
tbbi.dwMask = TBIF_BYINDEX | TBIF_SIZE;
tbbi.cx = 100;再调用
m_wndToolBar.SendMessage(TB_SETBUTTONINFO, 1, (LPARAM)&tbbi); // MFC或者
// SendMessage(hwndToolBar, TB_SETBUTTONINFO, 1, (LPARAM)&tbbi); // SDK
BOOL CVisualStylesDlg::CreateToolBar()
{
BOOL bReturn = FALSE; //Get the postion we'll put the toolbar
CRect rtPosition;
CWnd* pWnd = this->GetDlgItem(IDC_STATIC_POS);
pWnd->GetWindowRect(&rtPosition);
this->ScreenToClient(rtPosition); m_pToolBar = new CToolBarCtrl();
ASSERT(m_pToolBar);
if(m_pToolBar)
{
bReturn = m_pToolBar->Create(WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_NODIVIDER|TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_CUSTOMERASE, rtPosition, this, IDR_TOOLBAR1);
if(!bReturn)
return bReturn;
m_pToolBar->AddBitmap(3, IDR_TOOLBAR1); //add button definitions
m_pTbButton = new TBBUTTON[3];
ASSERT(m_pTbButton);
m_pTbButton[0].dwData = NULL;
m_pTbButton[0].fsState = TBSTATE_ENABLED;
m_pTbButton[0].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE ;
m_pTbButton[0].iBitmap = 0;
m_pTbButton[0].idCommand = ID_SELECTFILE_BACK;
m_pTbButton[0].iString = -1; m_pTbButton[1].dwData = NULL;
m_pTbButton[1].fsState = TBSTATE_ENABLED;
m_pTbButton[1].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE ;
m_pTbButton[1].iBitmap = 1;
m_pTbButton[1].idCommand = ID_SELECTFILE_UP;
m_pTbButton[1].iString = -1; m_pTbButton[2].dwData = NULL;
m_pTbButton[2].fsState = TBSTATE_ENABLED;
m_pTbButton[2].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE ;
m_pTbButton[2].iBitmap = 2;
m_pTbButton[2].idCommand = ID_SELECTFILE_SWITCHVIEW ;
m_pTbButton[2].iString = -1;
bReturn = m_pToolBar->AddButtons(3, m_pTbButton);
if(!bReturn)
return bReturn;
}
return bReturn;
}
1、使用 AppWizard 创建一个 MDI 工程。
2、在 CMainFrame::OnCreate() 函数的末尾添加我上述的代码。
3、编译运行。可以看到第二个按钮变宽的效果的。
tbbi.dwMask = TBIF_BYINDEX | TBIF_STYLE;
tbbi.fsStyle |= BTNS_WHOLEDROPDOWN;
m_wndToolBar.SendMessage(TB_SETBUTTONINFO, 1, (LPARAM)&tbbi);
//添加一按钮
TBBUTTON btn;
memset(&btn, 0, sizeof(TBBUTTON));
btn.fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
btn.iString = 10;
btn.idCommand = ID_FILE_SAVE;
btn.iBitmap = 2;
CToolBarCtrl &o = m_wndToolBar.GetToolBarCtrl();
o.AddButtons( 1, &btn );//修改ID_FILE_NEW按钮宽度
TBBUTTONINFO info;
memset(&info, 0, sizeof(TBBUTTONINFO));
info.cbSize = sizeof(TBBUTTONINFO);
info.dwMask = TBIF_SIZE;
info.cx = 40;
o.SetButtonInfo(ID_FILE_NEW,&info);
| CCS_NODIVIDER|TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_CUSTOMERASE, rtPosition, this, IDR_TOOLBAR1);
....... m_pTbButton[1].dwData = NULL;
m_pTbButton[1].fsState = TBSTATE_ENABLED;
m_pTbButton[1].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE ;
m_pTbButton[1].iBitmap = 1;
m_pTbButton[1].idCommand = 0;//ID_SELECTFILE_UP;
char buf[]="YoungW";
m_pTbButton[1].iString =(INT_PTR)buf;
前面二个是16*16的,后来一个是16*24的。不知道如何解决。其实不用不等的位图也行,只要那图后面加个小箭头,我知道按钮有那样的风格,但那种风格中间是有条线的,我是希望有个小箭头,但是那个button还是一个整体。
真的谢谢各位了。
不过我已经试过了,正是吾所想要的,呵呵。多谢了。
不过那个button不响应click,找原因中....
Version 5.80. Specifies that the button will have a drop-down arrow, but not as a separate section. Buttons with this style behave the same, regardless of whether the TBSTYLE_EX_DRAWDDARROWS extended style is set.It's strange.
If the main part of the button is clicked, the toolbar control sends a WM_COMMAND message with the button's ID. The application normally responds by launching the first command on the menu。难道我屐得去处理TBN_DROPDOWN吗?
2、向其中插入如下代码:
LPNMHDR pnmh = (LPNMHDR)lParam;
if(pnmh->code == TBN_DROPDOWN)
{
RECT rc;
int iIndex = ::SendMessage(pnmh->hwndFrom, TB_COMMANDTOINDEX, ID_FILE_OPEN, 0);
::SendMessage(pnmh->hwndFrom, TB_GETITEMRECT, iIndex, (LPARAM)&rc);
::MapWindowPoints(pnmh->hwndFrom, HWND_DESKTOP, (LPPOINT)&rc, 2);
CMenu* pMenu = GetSystemMenu(FALSE);
pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rc.left, rc.bottom, this);
*pResult = TBDDRET_DEFAULT;
return TRUE;
}
3、编译运行。可以看到,在点击工具栏上的打开文件按钮时,会把窗口的系统菜单显示出来。
好了,终于圆满的完成了我的东西,现在结贴给分。
nIndex = CommandToIndex(ID_PLACEHOLDER_ZOOM);
SetButtonInfo(nIndex, ID_PLACEHOLDER_ZOOM, TBBS_SEPARATOR, 100);