简单,我可以给你两种方法 一种是在toolbar上动态create一个edit 一种是在toolbar上装在一个含有edit得对话框资源 比较简单! 主要代码如下: --------------------------- int CPersonToolBar::CreateToolBar(CWnd *pParent) { int index=0; CRect rect;
if (!this->CreateEx(pParent, TBSTYLE_FLAT|TBSTYLE_LIST, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !this->LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create }
//实现热点图像 CImageList img; if(!img.Create(IDB_MAINFRAME,25,0,RGB(128,128,128))) { TRACE0("Failed to load hot images\n"); return -1; } this->GetToolBarCtrl().SetHotImageList(&img); img.Detach(); int i; // Add text to each button of toolbar for( i = 0; i < this->GetCount(); i++) { UINT id = this->GetItemID(i); CString s; if(!s.LoadString(id)) continue; int j = s.Find(_T('\n')); if(j < 0) continue; s = s.Right(s.GetLength() - j - 1); this->SetButtonText(i,s); } // Adjust sizes to include text this->GetItemRect(0,&rect); this->SetSizes(rect.Size(),CSize(25,25)); //expands the ID_FILE_NEW button to have a list menu! this->GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS); i=this->CommandToIndex(ID_FILE_NEW); UINT id,style; int image; this->GetButtonInfo(i,id,style,image); this->SetButtonInfo(i,ID_FILE_NEW,TBSTYLE_BUTTON | TBSTYLE_DROPDOWN,image); // Adjust sizes to include text CRect rect; this->GetItemRect(0,&rect); this->SetSizes(rect.Size(),CSize(25,25)); //End of expanding while(this->GetItemID(index)!=IDC_INDICATOR) index++; this->SetButtonInfo(index,IDC_INDICATOR,TBBS_SEPARATOR,120); this->GetItemRect(index,&rect); rect.InflateRect(CSize(-2,-2)); //use the style :ES_MULTILINE to enable the RETURN key! if(!this->m_wndSearchEdit.Create( WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN |WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT, rect,this,IDC_TOOLBAR_EDIT)) return -1; //Modify the window style to be 3D style! long dwStyle=::GetWindowLong(this->m_wndSearchEdit.m_hWnd,GWL_STYLE); dwStyle=dwStyle|WS_EX_CLIENTEDGE; ::SetWindowLong(this->m_wndSearchEdit.m_hWnd,GWL_EXSTYLE,dwStyle); while(this->GetItemID(index)!=IDC_TOOLDIALOG) index++; this->SetButtonInfo(index,IDC_TOOLDIALOG,TBBS_SEPARATOR,260); this->GetItemRect(index,&rect);
一种是在toolbar上动态create一个edit
一种是在toolbar上装在一个含有edit得对话框资源
比较简单!
主要代码如下:
---------------------------
int CPersonToolBar::CreateToolBar(CWnd *pParent)
{
int index=0;
CRect rect;
if (!this->CreateEx(pParent, TBSTYLE_FLAT|TBSTYLE_LIST, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!this->LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
//实现热点图像
CImageList img;
if(!img.Create(IDB_MAINFRAME,25,0,RGB(128,128,128)))
{
TRACE0("Failed to load hot images\n");
return -1;
} this->GetToolBarCtrl().SetHotImageList(&img);
img.Detach(); int i;
// Add text to each button of toolbar
for( i = 0; i < this->GetCount(); i++)
{
UINT id = this->GetItemID(i);
CString s;
if(!s.LoadString(id)) continue;
int j = s.Find(_T('\n'));
if(j < 0) continue;
s = s.Right(s.GetLength() - j - 1);
this->SetButtonText(i,s);
} // Adjust sizes to include text
this->GetItemRect(0,&rect);
this->SetSizes(rect.Size(),CSize(25,25)); //expands the ID_FILE_NEW button to have a list menu!
this->GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
i=this->CommandToIndex(ID_FILE_NEW);
UINT id,style;
int image;
this->GetButtonInfo(i,id,style,image);
this->SetButtonInfo(i,ID_FILE_NEW,TBSTYLE_BUTTON | TBSTYLE_DROPDOWN,image);
// Adjust sizes to include text CRect rect;
this->GetItemRect(0,&rect);
this->SetSizes(rect.Size(),CSize(25,25));
//End of expanding while(this->GetItemID(index)!=IDC_INDICATOR)
index++;
this->SetButtonInfo(index,IDC_INDICATOR,TBBS_SEPARATOR,120);
this->GetItemRect(index,&rect);
rect.InflateRect(CSize(-2,-2)); //use the style :ES_MULTILINE to enable the RETURN key!
if(!this->m_wndSearchEdit.Create(
WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN |WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT,
rect,this,IDC_TOOLBAR_EDIT))
return -1; //Modify the window style to be 3D style!
long dwStyle=::GetWindowLong(this->m_wndSearchEdit.m_hWnd,GWL_STYLE);
dwStyle=dwStyle|WS_EX_CLIENTEDGE;
::SetWindowLong(this->m_wndSearchEdit.m_hWnd,GWL_EXSTYLE,dwStyle); while(this->GetItemID(index)!=IDC_TOOLDIALOG)
index++;
this->SetButtonInfo(index,IDC_TOOLDIALOG,TBBS_SEPARATOR,260);
this->GetItemRect(index,&rect);
if(!this-> m_ToolDialog.Create(IDD_TOOLBAR_DIALOG,this))
return -1;
this->m_ToolDialog.MoveWindow(rect);
this->m_ToolDialog.ShowWindow(SW_SHOW);
return 0;
}
[email protected]
先在工具条上做一个空的控扭IDM_EDIT。int nCount=m_wndToolBar.GetCount(); //定义一个工具条的变量用来取按扭的个数 //用一个循环来取按扭的个数
for(int i=0;i<nCount;i++)
{
if(m_wndToolBar.GetItemID(i)==IDM_EDIT) break;
}
ASSERT(i<nCount); //必须要取到
m_wndToolBar.SetButtonInfo(i,IDM_EDIT,TBBS_SEPARATOR,120); //把IDM EDIT变成一个分割条,
//相当于开辟一块区域
RECT rect;
m_wndToolBar.GetItemRect(i,&rect); //大小为工具条的大小
rect.top++;//样式控制
rect.bottom--;
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_BORDER ,rect,&m_wndToolBar,500);