m_wndFontNames.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|
CBS_DROPDOWNLIST|CBS_SORT, rect, this, IDC_FONTNAMES);
其中rect中存放的是创建的位置,就是先利用CToolBar::SetButtonInfo()将某个按钮设置成合适的能容纳CComboBox控件的大小,然后由CToolBar::GetItemRect()函数获得该按钮的位置,并在这个位置创建CComboBox对象。
问题是我创建工具栏后,如果是固定模式的那么这个CComboBox控件可以正常显示,而一旦把工具栏设为浮动的就不能正常显示了,这是什么原因呢。请各位高手指点,谢谢!
5 个解决方案
#1
你不妨将整个create的代码都帖上来看看。
#2
我现在的工程中,是这么创建combobox的,目前浮动也没有问题。
bool CLabelChartToolBar::CreateComb()
{
#define COMBO_BOX_WIDTH 120
int index = 0;
CRect rect;
while(GetItemID(index)!= ID_LABEL_LIST)
index++;
SetButtonInfo(index,ID_LABEL_LIST, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
GetItemRect(index, &rect);
rect.top-=1;
rect.bottom += 200;
rect.left+=1;
if (!m_wndLabelChartComb.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, this, IDC_LABELCHART))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndLabelChartComb.ShowWindow(SW_SHOW);
m_wndLabelChartComb.SetCurSel(-1);
return true;
}
bool CLabelChartToolBar::CreateComb()
{
#define COMBO_BOX_WIDTH 120
int index = 0;
CRect rect;
while(GetItemID(index)!= ID_LABEL_LIST)
index++;
SetButtonInfo(index,ID_LABEL_LIST, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
GetItemRect(index, &rect);
rect.top-=1;
rect.bottom += 200;
rect.left+=1;
if (!m_wndLabelChartComb.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, this, IDC_LABELCHART))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndLabelChartComb.ShowWindow(SW_SHOW);
m_wndLabelChartComb.SetCurSel(-1);
return true;
}
#3
好的,谢谢,我看看。原来的代码是这样的:
int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!LoadToolBar(IDR_STYLE_BAR))
return -1;
//获得字体大小信息
CClientDC dc(this);
m_font.CreatePointFont(80, _T("MS Sans Serif"));
CFont *pOldFont = dc.SelectObject(&m_font);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
int cxChar = tm.tmAveCharWidth;
int cyChar = tm.tmHeight + tm.tmExternalLeading;
dc.SelectObject(pOldFont);
//将第8个位置的按钮大小设为32倍字符宽度
SetButtonInfo(8, IDC_FONTNAMES, TBBS_SEPARATOR, cxChar*32);//
CRect rect;
GetItemRect(8, &rect);
rect.bottom = rect.top + (cyChar*16);
if(!m_wndFontNames.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|
CBS_DROPDOWNLIST|CBS_SORT, rect, this, IDC_FONTNAMES))
return -1;
m_wndFontNames.SetFont(&m_font);
InitTypefaceList(&dc);
return 0;
}
int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!LoadToolBar(IDR_STYLE_BAR))
return -1;
//获得字体大小信息
CClientDC dc(this);
m_font.CreatePointFont(80, _T("MS Sans Serif"));
CFont *pOldFont = dc.SelectObject(&m_font);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
int cxChar = tm.tmAveCharWidth;
int cyChar = tm.tmHeight + tm.tmExternalLeading;
dc.SelectObject(pOldFont);
//将第8个位置的按钮大小设为32倍字符宽度
SetButtonInfo(8, IDC_FONTNAMES, TBBS_SEPARATOR, cxChar*32);//
CRect rect;
GetItemRect(8, &rect);
rect.bottom = rect.top + (cyChar*16);
if(!m_wndFontNames.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|
CBS_DROPDOWNLIST|CBS_SORT, rect, this, IDC_FONTNAMES))
return -1;
m_wndFontNames.SetFont(&m_font);
InitTypefaceList(&dc);
return 0;
}
#4
能把你的工具栏资源代码贴上来看看么?
#5
我看了一下,好像是SetButtonInfo(8, ID_FONT_NAMES, TBBS_SEPARATOR, cxChar*32);这个函数并没能改变相应位置按钮的大小,因此没能给CComboBox留出足够的空间来显示,我在资源后面加了很多SEPARATOR后把工具栏边的很长就可以显示了,但是为什么固定的工具栏可以正确运行呢?
#1
你不妨将整个create的代码都帖上来看看。
#2
我现在的工程中,是这么创建combobox的,目前浮动也没有问题。
bool CLabelChartToolBar::CreateComb()
{
#define COMBO_BOX_WIDTH 120
int index = 0;
CRect rect;
while(GetItemID(index)!= ID_LABEL_LIST)
index++;
SetButtonInfo(index,ID_LABEL_LIST, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
GetItemRect(index, &rect);
rect.top-=1;
rect.bottom += 200;
rect.left+=1;
if (!m_wndLabelChartComb.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, this, IDC_LABELCHART))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndLabelChartComb.ShowWindow(SW_SHOW);
m_wndLabelChartComb.SetCurSel(-1);
return true;
}
bool CLabelChartToolBar::CreateComb()
{
#define COMBO_BOX_WIDTH 120
int index = 0;
CRect rect;
while(GetItemID(index)!= ID_LABEL_LIST)
index++;
SetButtonInfo(index,ID_LABEL_LIST, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
GetItemRect(index, &rect);
rect.top-=1;
rect.bottom += 200;
rect.left+=1;
if (!m_wndLabelChartComb.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, this, IDC_LABELCHART))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndLabelChartComb.ShowWindow(SW_SHOW);
m_wndLabelChartComb.SetCurSel(-1);
return true;
}
#3
好的,谢谢,我看看。原来的代码是这样的:
int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!LoadToolBar(IDR_STYLE_BAR))
return -1;
//获得字体大小信息
CClientDC dc(this);
m_font.CreatePointFont(80, _T("MS Sans Serif"));
CFont *pOldFont = dc.SelectObject(&m_font);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
int cxChar = tm.tmAveCharWidth;
int cyChar = tm.tmHeight + tm.tmExternalLeading;
dc.SelectObject(pOldFont);
//将第8个位置的按钮大小设为32倍字符宽度
SetButtonInfo(8, IDC_FONTNAMES, TBBS_SEPARATOR, cxChar*32);//
CRect rect;
GetItemRect(8, &rect);
rect.bottom = rect.top + (cyChar*16);
if(!m_wndFontNames.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|
CBS_DROPDOWNLIST|CBS_SORT, rect, this, IDC_FONTNAMES))
return -1;
m_wndFontNames.SetFont(&m_font);
InitTypefaceList(&dc);
return 0;
}
int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!LoadToolBar(IDR_STYLE_BAR))
return -1;
//获得字体大小信息
CClientDC dc(this);
m_font.CreatePointFont(80, _T("MS Sans Serif"));
CFont *pOldFont = dc.SelectObject(&m_font);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
int cxChar = tm.tmAveCharWidth;
int cyChar = tm.tmHeight + tm.tmExternalLeading;
dc.SelectObject(pOldFont);
//将第8个位置的按钮大小设为32倍字符宽度
SetButtonInfo(8, IDC_FONTNAMES, TBBS_SEPARATOR, cxChar*32);//
CRect rect;
GetItemRect(8, &rect);
rect.bottom = rect.top + (cyChar*16);
if(!m_wndFontNames.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|
CBS_DROPDOWNLIST|CBS_SORT, rect, this, IDC_FONTNAMES))
return -1;
m_wndFontNames.SetFont(&m_font);
InitTypefaceList(&dc);
return 0;
}
#4
能把你的工具栏资源代码贴上来看看么?
#5
我看了一下,好像是SetButtonInfo(8, ID_FONT_NAMES, TBBS_SEPARATOR, cxChar*32);这个函数并没能改变相应位置按钮的大小,因此没能给CComboBox留出足够的空间来显示,我在资源后面加了很多SEPARATOR后把工具栏边的很长就可以显示了,但是为什么固定的工具栏可以正确运行呢?