0

我已经盯着这个文档 5 个小时了。我根本无法连接这些步骤。如果各位大神能帮我解惑。

这是网站: http: //msdn.microsoft.com/EN-US/library/bb983718 (VS.110).aspx

所以我的问题如下: - 在第 5 号,它要求我“设置这些参数如下:”,它甚至没有提到任何关于在哪里?在哪里实现构造函数,为什么要使用CMFCToolbarComboBoxButton?当它已经在第 4 步要求我派生一个名为 CFindComboButton 的类时。我不应该为那个做一个构造函数吗?

- 在第 4 号(抱歉问题的无组织编号),我所做的是使用添加类(不是类向导),然后我选择了 MFC 类。然后我输入所谓的 CFindComboButton 和 Base 类作为 CMFCToolBarComboBoxButton。我在这个上做错了吗?我必须为 ID ID_EDIT_FIND_COMBO 做任何事情吗?

-当我在字符串表中注册 ID_EDIT_FIND_COMBO 时,我不完全知道我做了什么。我只是为将来的实施注册了一个 id 吗?或者是别的什么?

- 所以我不能执行第 5 步,我跳到第 6 步。它只要求我在 CFindComboButton 的属性的覆盖部分中查找 CreateCombo 方法。好吧,我只能找到 3 个覆盖。它们都不是 CreateCombo 方法。那么从那里,你可以说我迷路了。

我是 mfc 的菜鸟,所以你可能想考虑一下。

4

2 回答 2

1

Even though your question is a bit jump-led up, let me try and answer so that it works for you.

  1. Create two class - one derived from CComboBox (call it CFindComboBox) and another from CMFCToolBarComboBoxButton (call it CFindComboBoxButton). First class will implement the Combobox that will be shown when you click the drop down button in the toolbar. This drop down button is implemented by CFindComboBoxButton. Hope this is clear.

  2. Now define the constructor for the CFindComboBoxButton as CFindComboBoxButton(UNIT nID, int nImage, DWORD dwStyles) using three parameters as explained below:

    • Command ID of the button which will be ID_EDIT_FIND_COMBO (or anything you want to define it as). This will get defined in the String Table. Just add a new entry in String Table with ID_EDIT_FIND_COMBO as ID and a placeholder string. Don't omit the string value else the ID will not get defined. The string value can be anything as it wont be used anywhere.
    • Second parameter will just be a call to CCommandManager::GetCmdImage(ID_EDIT_FIND). This will return the default image used to show the drop down for combobox. In case you want to use your own custom image you can create one and instead pass the ID of that.
    • Third parameter is the styles you want to use. They are defined at http://msdn.microsoft.com/EN-US/library/7h63bxbe(v=vs.110).aspx but you can use the default value (CBS_DROPDOWNLIST) to start with.
  3. Override the CreateCombo method of CMFCToolBarComboBoxButton and add its implementation to CFindComboBoxButton. In this method create and return a pointer to CFindComboBox (CComboBox derived class).

I hope this clears all the confusion and you should be on your way to have a custom Combobox embedded inside a toolbar.

于 2012-07-29T16:54:11.777 回答
0

看看 VisualStudioDemo 示例:http: //msdn.microsoft.com/en-us/library/bb983983%28v=vs.90%29.aspx

你可以在那里找到 CFindComboButton 实现

于 2013-07-11T08:11:57.457 回答