You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dotnet/hosting-a-windows-form-user-control-as-an-mfc-dialog-box.md
+21-22Lines changed: 21 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,22 @@
1
1
---
2
-
description: "Learn more about: Hosting a Windows Form User Control as an MFC Dialog Box"
3
2
title: "Hosting a Windows Form User Control as an MFC Dialog Box"
4
-
ms.date: "11/04/2016"
3
+
description: "Learn more about: Hosting a Windows Form User Control as an MFC Dialog Box"
4
+
ms.date: 11/04/2016
5
5
helpviewer_keywords: ["MFC [C++], Windows Forms support", "Windows Forms [C++], hosting as MFC Dialog", "hosting Windows Forms control [C++]"]
6
-
ms.assetid: 0434a9d7-8b14-48e6-ad69-9ba9a684677a
7
6
---
8
7
# Hosting a Windows Form User Control as an MFC Dialog Box
9
8
10
-
MFC provides the template class [CWinFormsDialog](../mfc/reference/cwinformsdialog-class.md) so that you can host a Windows Forms user control (<xref:System.Windows.Forms.UserControl>) in a modal or modeless MFC dialog box. `CWinFormsDialog` is derived from the MFC class [CDialog](../mfc/reference/cdialog-class.md), so the dialog box can be launched as modal or modeless.
9
+
MFC provides the template class [`CWinFormsDialog`](../mfc/reference/cwinformsdialog-class.md) so that you can host a Windows Forms user control (<xref:System.Windows.Forms.UserControl>) in a modal or modeless MFC dialog box. `CWinFormsDialog` is derived from the MFC class [`CDialog`](../mfc/reference/cdialog-class.md), so the dialog box can be launched as modal or modeless.
11
10
12
-
The process that `CWinFormsDialog` uses to host the user control is the similar to that described in [Hosting a Windows Form User Control in an MFC Dialog Box](../dotnet/hosting-a-windows-form-user-control-in-an-mfc-dialog-box.md). However, `CWinFormsDialog` manages the initialization and hosting of the user control so that it does not have to be programmed manually.
11
+
The process that `CWinFormsDialog` uses to host the user control is similar to that described in [Hosting a Windows Form User Control in an MFC Dialog Box](hosting-a-windows-form-user-control-in-an-mfc-dialog-box.md). However, `CWinFormsDialog` manages the initialization and hosting of the user control so that it does not have to be programmed manually.
13
12
14
13
### To create the MFC host application
15
14
16
15
1. Create an MFC Application project.
17
16
18
17
On the **File** menu, select **New**, and then click **Project**. In the **Visual C++** folder, select **MFC Application**.
19
18
20
-
In the **Name** box, enter `MFC03` and change the Solution setting to **Add to Solution**.Click **OK**.
19
+
In the **Name** box, enter `MFC03` and change the Solution setting to **Add to Solution**.Click **OK**.
21
20
22
21
In the **MFC Application Wizard**, accept all the defaults, and then click **Finish**. This creates an MFC application with a Multiple Document Interface.
23
22
@@ -29,21 +28,21 @@ The process that `CWinFormsDialog` uses to host the user control is the similar
29
28
30
29
1. Add a reference to the .NET control.
31
30
32
-
In **Solution Explorer**, right-click the **MFC03** project node and choose **Add**, **References**. In the **Property Page**, click **Add New Reference**, select WindowsControlLibrary1 (under the **Projects** tab), and click **OK**. This adds a reference in the form of a [/FU](../build/reference/fu-name-forced-hash-using-file.md) compiler option so that the program will compile; it also copies WindowsControlLibrary1.dll into the `MFC03` project directory so that the program will run.
31
+
In **Solution Explorer**, right-click the **MFC03** project node and choose **Add**, **References**. In the **Property Page**, click **Add New Reference**, select WindowsControlLibrary1 (under the **Projects** tab), and click **OK**. This adds a reference in the form of a [`/FU`](../build/reference/fu-name-forced-hash-using-file.md) compiler option so that the program will compile; it also copies `WindowsControlLibrary1.dll` into the `MFC03` project directory so that the program will run.
33
32
34
33
1. Add `#include <afxwinforms.h>` to *pch.h* (*stdafx.h* in Visual Studio 2017 and earlier), at the end of the existing `#include` statements.
35
34
36
35
1. Add a new class that subclasses `CDialog`.
37
36
38
-
Right click on project name and add an MFC class (called CHostForWinForm) that subclasses `CDialog`. Since you do not need the dialog box resource, you can delete the resource ID (select **Resource View**, expand the **Dialog** folder and delete `IDD_HOSTFORWINFORM` resource. Then, remove any references to the ID in code.).
37
+
Right click on project name and add an MFC class (called `CHostForWinForm`) that subclasses `CDialog`. Since you do not need the dialog box resource, you can delete the resource ID (select **Resource View**, expand the **Dialog** folder and delete `IDD_HOSTFORWINFORM` resource. Then, remove any references to the ID in code.).
39
38
40
-
1. Replace `CDialog` in CHostForWinForm.h and CHostForWinForm.cpp files with `CWinFormsDialog<WindowsControlLibrary1::UserControl1>`.
39
+
1. Replace `CDialog` in `CHostForWinForm.h` and `CHostForWinForm.cpp` files with `CWinFormsDialog<WindowsControlLibrary1::UserControl1>`.
41
40
42
-
1. Call DoModal on the CHostForWinForm class.
41
+
1. Call `DoModal` on the `CHostForWinForm` class.
43
42
44
-
In MFC03.cpp, add `#include "HostForWinForm.h"`.
43
+
In `MFC03.cpp`, add `#include "HostForWinForm.h"`.
45
44
46
-
Before the return statement in the definition of CMFC03App::InitInstance, add:
45
+
Before the return statement in the definition of `CMFC03App::InitInstance`, add:
47
46
48
47
```cpp
49
48
CHostForWinForm m_HostForWinForm;
@@ -58,15 +57,15 @@ The process that `CWinFormsDialog` uses to host the user control is the similar
58
57
59
58
Next you will add code to monitor the state of a control on the Windows Forms from the MFC application.
60
59
61
-
1. Add a handler for OnInitDialog.
60
+
1. Add a handler for`OnInitDialog`.
62
61
63
-
Display the **Properties** window (F4). In **Class View**, select CHostForWinForm. In the **Properties** window, select overrides and in the row for OnInitDialog, click in the left hand column and select \< Add >. This adds the following line to CHostForWinForm.h:
62
+
Display the **Properties** window (F4). In **Class View**, select `CHostForWinForm`. In the **Properties** window, select overrides and in the row for `OnInitDialog`, click in the left hand column and select \< Add >. This adds the following line to `CHostForWinForm.h`:
64
63
65
64
```cpp
66
65
virtual BOOL OnInitDialog();
67
66
```
68
67
69
-
1. Define OnInitDialog (in CHostForWinForm.cpp) as follows:
68
+
1. Define `OnInitDialog` (in `CHostForWinForm.cpp`) as follows:
70
69
71
70
```cpp
72
71
BOOL CHostForWinForm::OnInitDialog() {
@@ -76,7 +75,7 @@ The process that `CWinFormsDialog` uses to host the user control is the similar
76
75
}
77
76
```
78
77
79
-
1. Next add the OnButton1 handler. Add the following lines to the public section of the CHostForWinForm class in CHostForWinForm.h:
78
+
1. Next add the `OnButton1` handler. Add the following lines to the public section of the `CHostForWinForm` class in `CHostForWinForm.h`:
80
79
81
80
```cpp
82
81
virtualvoidOnButton1( System::Object^ sender, System::EventArgs^ e );
@@ -86,7 +85,7 @@ The process that `CWinFormsDialog` uses to host the user control is the similar
86
85
END_DELEGATE_MAP()
87
86
```
88
87
89
-
In CHostForWinForm.cpp, add this definition:
88
+
In `CHostForWinForm.cpp`, add this definition:
90
89
91
90
```cpp
92
91
void CHostForWinForm::OnButton1( System::Object^ sender, System::EventArgs^ e )
@@ -99,13 +98,13 @@ The process that `CWinFormsDialog` uses to host the user control is the similar
99
98
100
99
Next you will add code to display from the MFC code the value in the text box on the Windows Form.
101
100
102
-
1. In the public section of the CHostForWinForm class in CHostForWinForm.h, add the following declaration:
101
+
1. In the public section of the `CHostForWinForm` class in `CHostForWinForm.h`, add the following declaration:
103
102
104
103
```cpp
105
104
CString m_sEditBoxOnWinForm;
106
105
```
107
106
108
-
1. In the definition of DoDataExchange in CHostForWinForm.cpp, add the following three lines to the end of the function:
107
+
1. In the definition of `DoDataExchange` in `CHostForWinForm.cpp`, add the following four lines to the end of the function:
109
108
110
109
```cpp
111
110
if (pDX->m_bSaveAndValidate)
@@ -114,7 +113,7 @@ The process that `CWinFormsDialog` uses to host the user control is the similar
@@ -89,7 +89,7 @@ The articles in this section of the documentation explain a subset of the error
89
89
|[Compiler error C2571](compiler-error-C2571.md)|'*identifier*': virtual function cannot be in union '*union*'|
90
90
|[Compiler error C2572](compiler-error-C2572.md)|'*function*': redefinition of default argument: parameter *number*|
91
91
|[Compiler error C2573](compiler-error-C2573.md)|'*class*': cannot delete pointers to objects of this type; the class has no non-placement overload for 'operator delete'. Use ::delete, or add 'operator delete(void*)' to the class|
92
-
|[Compiler error C2574](compiler-error-C2574.md)|'*destructor*': cannot be declared static|
92
+
|[Compiler error C2574](compiler-error-C2574.md)|'*function*': cannot be declared static|
93
93
|[Compiler error C2575](compiler-error-C2575.md)|'*identifier*': only member functions and bases can be virtual|
94
94
|Compiler error C2576|'*identifier*': cannot introduce a new virtual method as 'public'. Consider making the method non-virtual, or change the accessibility to 'internal' or 'protected private'|
95
95
|[Compiler error C2577](compiler-error-C2577.md)|'*identifier*': a destructor/finalizer cannot have a return type|
Contains the `IOleInPlaceObjectWindowless`[IOleInPlaceObjectWindowless](/windows/win32/api/ocidl/nn-ocidl-ioleinplaceobjectwindowless) interface of the control.
724
+
Contains the [`IOleInPlaceObjectWindowless`](/windows/win32/api/ocidl/nn-ocidl-ioleinplaceobjectwindowless) interface of the control.
Copy file name to clipboardExpand all lines: docs/overview/what-s-new-for-visual-cpp-in-visual-studio.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,7 +220,7 @@ A partial list of new features:
220
220
-**Standard Library Enhancements**
221
221
- The formatted output implementation now includes `std::range_formatter` and formatters for `std::pair` and `std::tuple`.
222
222
- Added support for `std::println()` with no arguments. This prints a blank line as proposed in [P3142R0](https://wg21.link/P3142R0).
223
-
- Improved vectorization for several algorithms including `replace_copy()`, `replace_copy_if()`, `ranges::replace_copy`, `ranges::replace_copy_if`, `find_first_of()` and `ranges::find_first_of`, for 8-bit and 16-bit elements, `mismatch()`, `ranges::mismatch`, `count()``ranges::count`, `find()`, `ranges::find`, `ranges::find_last`, and `ranges::iota`.
223
+
- Improved vectorization for several algorithms including `replace_copy()`, `replace_copy_if()`, `ranges::replace_copy`, `ranges::replace_copy_if`, `find_first_of()` and `ranges::find_first_of`, for 8-bit and 16-bit elements, `mismatch()`, `ranges::mismatch`, `count()`,`ranges::count`, `find()`, `ranges::find`, `ranges::find_last`, and `ranges::iota`.
224
224
225
225
-**Game development in C++**
226
226
- You can now add common Unreal Engine class templates, modules, and plugins from within Visual Studio. For more information, see [Add Unreal Engine classes, modules, and plugins in Visual Studio](/visualstudio/gamedev/unreal/get-started/vs-tools-unreal-add-class-module-plugin).
0 commit comments