在VC6。0中,怎样在状态栏上加上按钮,怎样在CTOOLBAR上加上组合框

wzwz 2001-07-22 03:41:42
...全文
93 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxiaohan 2001-12-19
  • 打赏
  • 举报
回复
1. 创建AppWizard工程文件设为toolbar,采用系统缺省设置。

2. 打开资源编辑器,选择工具条,在工具条中增加一个按钮,设置按钮 I D 为 I D_MY_COMBO_BOX 。 移动该按钮以使按钮处于适当的位置。

3. 从 C ToolBar 派 生出一个新类 C MyToolBar , 在 C MyToolBar 类 中增加一个成员变量 m_wndMyComboBox , 代码如下:

class CMyToolBar : public CToolBar
{
public:
CComboBox m_wndMyComboBox;
};

注意要将代码放在工程文件mainframe.h中“#endif // _MSC_VER > 1000”语句之后,类CMainFrame定义之前。

4. 将工程文件mainframe.h中的CToolBar变量m_wndToolBar用CMyToolBar变量m_wndToolBar代替。同时增加函数CreateMyComboToolBar()声明。代码如下:

protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CMyToolBar m_wndToolBar;
int CreateMyComboToolBar();

5. 在工程文件mainframe.cpp中的OnCreate()函数返回语句之前调用函数CreateMyToolBar();代码如下所示:

if(!CreateMyComboToolBar())
MessageBox("Create My Combo ToolBar Failure");

6. 以文本方式打开资源头文件resource.h,增加一个控制ID如下,注意该控制的ID值不要与其它控制或资源的ID值重复:

#define IDC_MY_COMBO 1111

7. 在工程文件mainframe.cpp中增加函数CreateMyToolBar();代码如下:

int MainFrame::CreateMyToolBar()
{
#define COMBO_BOX_WIDTH 80 //the width of the combo box
//set up the ComboBox control as a select box
//First get the index of the button's
position in the toolbar
int index = 0;
CRecr rect;
while(m_wndToolBar.GetItemID(index)!
= ID_MY_COMBO_BOX) index++;
//next convert that button to a
seperator and get its position
m_wndToolBar.SetButtonInfo(index,
ID_MY_COMBO_BOX, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
m_wndToolBar.GetItemRect(index, &rect);
//expand the rectangle to allow the
combo box room to drop down
rect.top+=2;
rect.bottom += 200;
// then .Create the combo box and show it
if (!m_wndToolBar.m_ wndMyComboBox.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, &m_wndToolBar, IDC_MY_COMBO))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndToolBar.m_wndMyComboBox.ShowWindow(SW_SHOW);
//adding string to the combo box
m_wndToolBar.m_wndMyComboBox.AddString("Fisrt Select");
m_wndToolBar.m_wndMyComboBox.AddString("Second Select");
m_wndToolBar.m_wndMyComboBox.AddString("Third Select");
m_wndToolBar.m_wndMyComboBox.AddString("Fourth Select");
m_wndToolBar.m_wndMyComboBox.AddString("Fifth Select");
m_wndToolBar.m_wndMyComboBox.SetCurSel(0);
}

ahphone 2001-07-23
  • 打赏
  • 举报
回复
http://www.csdn.net/dev/visual%20c++/source%20code/ToolBar/combo_in_flatbar.shtml.htm

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧