|
| 1 | +--- |
| 2 | +description: "Learn more about: Use the Microsoft Visual Studio Add IDL MFC property wizard to add a method to an IDL interface in your MFC or ATL project" |
| 3 | +title: "Add an IDL MFC property" |
| 4 | +ms.date: "04/06/2022" |
| 5 | +f1_keywords: ["vc.codewiz.prop.overview"] |
| 6 | +helpviewer_keywords: ["interfaces, adding properties", "properties [C++], adding to interfaces", "names, add property wizard", "add property wizard", "stock properties, about stock properties", "stock properties"] |
| 7 | +ms.assetid: 37bd4db7-efd3-4faa-87ad-64902ed16a36 |
| 8 | +ms.custom: devdivchpfy22 |
| 9 | +--- |
| 10 | + |
| 11 | +# Add an IDL MFC property |
| 12 | + |
| 13 | +The **Add IDL MFC Property** wizard adds a method to an Interface Definition Library (IDL) interface defined in your Microsoft Framework Class (MFC) project. To use this wizard, you must be in an MFC Project, ActiveX project, or an ATL project that supports MFC. For example, if you have a Microsoft ActiveX control project, you can use the following procedure to add a method to an IDL interface in the solution. |
| 14 | + |
| 15 | +**To add an IDL MFC property to your interface** |
| 16 | + |
| 17 | +1. On the **View** menu, select **Class View**. |
| 18 | + |
| 19 | +1. In [Class View](/visualstudio/ide/viewing-the-structure-of-code), right-click the name of the interface to which you want to add the property. |
| 20 | + |
| 21 | + > [!NOTE] |
| 22 | + > You can also add properties to dispinterfaces, which, unless the project is attributed, are nested within the library node. |
| 23 | +
|
| 24 | +1. From the shortcut menu, choose **Add** > **Add Property**. |
| 25 | + |
| 26 | +1. In the **Add IDL MFC property** wizard, provide the information to create the property. |
| 27 | + |
| 28 | +1. Select **OK** to add the property. |
| 29 | + |
| 30 | +For MFC dispinterfaces, if you select **Member variable** as the implementation type, a method and a variable are added to the class that implements it. If you select **Get/Set methods** as the implementation type, two methods are added to the class that implements it. |
| 31 | + |
| 32 | +## User Interface element list |
| 33 | + |
| 34 | +The following section describes the **Add IDL MFC Property** wizard UI: |
| 35 | + |
| 36 | +:::image type="content" source="../reference/media/add-idl-mfc-property-wizard.png" alt-text="Add IDL MFC Property Wizard UI."::: |
| 37 | + |
| 38 | +- **Property name** |
| 39 | + |
| 40 | + Sets the name of the property. For MFC dispinterfaces associated with ActiveX controls, you can supply your own name or you can select a stock property name from the predefined list. If you provide your own property name, the **Stock** implementation type is unavailable. For more information about a description of the stock properties in the list, see [stock properties](#stock-properties). |
| 41 | + |
| 42 | + |Interface type|Description| |
| 43 | + |--------------------|-----------------| |
| 44 | + |ATL dual interface, custom interface, and local custom interface|Provide a property name.| |
| 45 | + |MFC dispinterface, MFC ActiveX control dispinterface|Provide a property name or select a stock property from the list. If you select a property from the list, the appropriate value appears in the **Property type** box. You can change this type, depending on your selection under **Implementation type**.| |
| 46 | + |
| 47 | +- **Property type** |
| 48 | + |
| 49 | + Sets the type of property you're adding. For MFC dispinterfaces, provide your own type or select from the predefined list. If you provide a stock implementation of a property, **Property type** is set to the stock type and is unavailable for change. |
| 50 | + |
| 51 | +- **Variable name** |
| 52 | + |
| 53 | + This UI element is available only for MFC dispinterfaces. Available only if you specify **Member variable** under **Implementation type**. Sets the name of the member variable with which the property is associated. By default, the variable name is set to `m_`*PropertyName*. You can edit this name. |
| 54 | + |
| 55 | +- **Notification function** |
| 56 | + |
| 57 | + This UI element is available only for MFC dispinterfaces. Available only if you specify **Member variable** under **Implementation type**. Sets the name of the notification function called if the property changes. By default, the name of the notification function is set to `On`*PropertyName*`Changed`. You can edit this name. |
| 58 | + |
| 59 | +- **Get function** |
| 60 | + |
| 61 | + This UI element is available only for MFC dispinterfaces. Available only if you specify **Get/Set methods** under **Implementation type**. Sets the name of the function to get the property. By default, the name of the `Get` function is set to `Get`*PropertyName*. You can edit this name. If you delete the name, the function [GetNotSupported](../../mfc/reference/colecontrol-class.md#getnotsupported) is inserted into the interface dispatch map. The `Get`*PropertyName* function specifies that the property as readable. |
| 62 | + |
| 63 | +- **Set function** |
| 64 | + |
| 65 | + This UI element is available only for MFC dispinterfaces. Available only if you specify **Get/Set methods** under **Implementation type**. Sets the name of the function to set the property. By default, the name of the `Set` function is set to `Set`*PropertyName*. You can edit this name. If you delete the name, the function [SetNotSupported](../../mfc/reference/colecontrol-class.md#setnotsupported) is inserted into the interface dispatch map. The `Set`*PropertyName* function specifies that the property is writable. |
| 66 | + |
| 67 | +- **Implementation type** |
| 68 | + |
| 69 | + This UI element is available only for MFC dispinterfaces. Specifies how to implement the property you're adding. |
| 70 | + |
| 71 | + |Implementation type|Description| |
| 72 | + |-------------------------|-----------------| |
| 73 | + |**Stock**|Specifies a default implementation for the property selected in **Property name**. For more information, see [stock properties](#stock-properties).<br /><br /> If you specify **Stock**, then **Property type**, **Parameter type**, and **Parameter name** are dimmed.| |
| 74 | + |**Member variable**|Specifies the property is added as a member variable. You can add custom properties or most stock properties as member variables. You can't specify **Member variable** for the `Caption`, `hWnd`, and `Text` properties.<br /><br /> Provides default names under **Variable name** and **Notification function**. You can edit this name.| |
| 75 | + |**Get/Set methods**|Specifies the property is added as `Get`*PropertyName* and `Set`*PropertyName* functions, by default. These names appear under **Get function** and **Set function**.<br /><br /> You can change the default **Property type**, which passes a value for the Get function. You can specify parameters for the `Get` and `Set` functions.| |
| 76 | + |
| 77 | +- **Default property** |
| 78 | + |
| 79 | + This selection is available only for MFC dispinterface. Sets this property as the default for the interface. An interface can have only one default property; once you specify the default property, for any other properties you add to the interface, this box is unavailable. |
| 80 | + |
| 81 | +- **Parameters** |
| 82 | + |
| 83 | + Displays the method's parameters and its types. The wizard updates the **Parameters** list as you add parameters. |
| 84 | + |
| 85 | +- **+** |
| 86 | + |
| 87 | + Add a parameter. In **Parameters**, type the parameter type and name. For example, `int x`, and choose **OK**. |
| 88 | + |
| 89 | +- **x** |
| 90 | + |
| 91 | + Removes the selected parameter from the **Parameters** list. |
| 92 | + |
| 93 | +- **Pencil icon** |
| 94 | + |
| 95 | + Edit the selected parameter. |
| 96 | + |
| 97 | +- `id` |
| 98 | + |
| 99 | + Sets the numerical ID that identifies the property. This option isn't available for properties of custom interfaces. For more information, see [id](/windows/win32/Midl/id) in the *MIDL Reference*. |
| 100 | + |
| 101 | +- `helpcontext` |
| 102 | + |
| 103 | + Specifies a context ID that lets the user view information about this property in the Help file. For more information, see [helpcontext](/windows/win32/Midl/helpcontext) in the *MIDL Reference*. |
| 104 | + |
| 105 | +- `helpstring` |
| 106 | + |
| 107 | + Specifies a character string that's used to describe the element to which it applies. By default, it's set to **`property`** *Property name*. For more information, see [helpstring](/windows/win32/Midl/helpstring) in the *MIDL Reference*. |
| 108 | + |
| 109 | +## Stock properties |
| 110 | + |
| 111 | +If you're adding a property to an MFC dispinterface using the **Add IDL MFC Property** wizard, you can choose a stock property from the **Property name** list. These properties are as follows: |
| 112 | + |
| 113 | +|Property name|Description| |
| 114 | +|-------------------|-----------------| |
| 115 | +|`Appearance`|Returns or sets a value that determines the appearance of the control. The control's `Appearance` property can include or omit three-dimensional display effects. This property is an ambient read/write property.| |
| 116 | +|`BackColor`|Returns or sets the control's ambient `BackColor` property to either a palette (RGB) color or a predefined system color. By default, its value corresponds to the foreground color of the control's container. This property is an ambient read/write property.| |
| 117 | +|`BorderStyle`|Returns or sets the border style for a control. This property is a read/write property.| |
| 118 | +|`Caption`|Returns or sets the control's `Caption` property. The caption is the title of the window. `Caption` has no **Member variable** implementation type.| |
| 119 | +|`Enabled`|Returns or sets the control's `Enabled` property. An enabled control can respond to user-generated events.| |
| 120 | +|`Font`|Returns or sets the control's ambient font. Null if the control has no font.| |
| 121 | +|`ForeColor`|Returns or sets the control's ambient `ForeColor` property.| |
| 122 | +|`hWnd`|Returns or sets the control's `hWnd` property. `hWnd` has no **Member variable** implementation type.| |
| 123 | +|`ReadyState`|Returns or sets the control's `ReadyState` property. A control can be uninitialized, initialized, loading, interactive, or complete. For more information, see [READYSTATE](/previous-versions/aa768362\(v=vs.85\)) in the *Internet SDK*.| |
| 124 | +|`Text`|Returns or sets the text contained in a control. `Text` has no **Member variable** implementation type.| |
| 125 | + |
| 126 | +## See Also |
| 127 | + |
| 128 | +[Add Property](../../ide/adding-a-property-visual-cpp.md) |
0 commit comments