CWinFormsControl 类

提供用于承载 Windows 窗体控件的基本功能。

语法

template<class TManagedControl>
class CWinFormsControl : public CWnd

参数

TManagedControl
要在 MFC 应用程序中显示的 .NET Framework Windows 窗体控件。

成员

公共构造函数

名称 描述
CWinFormsControl::CWinFormsControl 构造 MFC Windows 窗体控件包装器对象。

公共方法

名称 描述
CWinFormsControl::CreateManagedControl 在 MFC 容器中创建 Windows 窗体控件。
CWinFormsControl::GetControl 检索指向 Windows 窗体控件的指针。
CWinFormsControl::GetControlHandle 检索 Windows 窗体控件的句柄。

公共运算符

“属性” 描述
CWinFormsControl::operator -> 替换表达式中的 CWinFormsControl::GetControl
CWinFormsControl::operator TManagedControl^ 将类型强制转换为指向 Windows 窗体控件的指针。

备注

CWinFormsControl 类提供用于承载 Windows 窗体控件的基本功能。

有关使用 Windows 窗体的详细信息,请参阅在 MFC 中使用 Windows 窗体用户控件

MFC 代码不应缓存窗口句柄(通常存储在 m_hWnd 中)。 某些 Windows 窗体控件属性要求使用 DestroyWindowCreateWindow 销毁并重新创建基础 Win32 Window。 MFC Windows 窗体实现处理控件的 DestroyCreate 事件以更新 m_hWnd 成员。

注意

MFC Windows 窗体集成仅适用于与 MFC 动态链接的项目(其中定义了 AFXDLL)。

要求

标头:afxwinforms.h

CWinFormsControl::CreateManagedControl

在 MFC 容器中创建 Windows 窗体控件。

inline BOOL CreateManagedControl(
    System::Type^ pType,
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    int nID)
inline BOOL CreateManagedControl(
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    int nID);

inline BOOL CreateManagedControl(
    DWORD dwStyle,
    int nPlaceHolderID,
    CWnd* pParentWnd);

inline BOOL CreateManagedControl(
    typename TManagedControl^ pControl,
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    int nID);

参数

pType
要创建的控件的数据类型。 必须是 Type 数据类型。

dwStyle
要应用于控件的窗口样式。 指定窗口样式的组合。 目前仅支持以下样式:WS_TABSTOP、WS_VISIBLE、WS_DISABLED 和 WS_GROUP。

rect
一个 RECT 结构,定义控件的左上角和右下角的坐标(仅第一个重载)。

nPlaceHolderID
放置在资源编辑器中的静态占位符控件的句柄。 新创建的 Windows 窗体控件将替换静态控件,假设其位置、z 顺序和样式(仅第二个重载)。

pParentWnd
指向父窗口的指针。

nID
要分配给新创建的控件的资源 ID 号。

pControl
要与 CWinFormsControl 对象关联的 Windows 窗体控件的实例(仅第四个重载)。

返回值

如果成功,则返回非零值。 如果不成功,则返回零。

注解

此方法将实例化 MFC 容器中的 .NET Framework Windows 窗体控件。

此方法的第一个重载接受 .NET Framework 数据类型 pType,使 MFC 可以实例化此类型的新对象。 pType 必须是 Type 数据类型

此方法的第二个重载基于 CWinFormsControl 类的 TManagedControl 模板参数创建 Windows 窗体控件。 控件的大小和位置基于传递给方法的 RECT 结构。 只有 dwStyle 对样式很重要

此方法的第三个重载创建替换静态控件的 Windows 窗体控件,销毁它并假定其位置、z 顺序和样式。 静态控件仅用作 Windows 窗体控件的占位符。 创建控件时,此重载将 dwStyle 中的样式与静态控件的资源样式组合在一起

此方法的第四个重载允许传入 MFC 将包装的已实例化的 Windows 窗体控件 pControl。 它必须与 CWinFormsControl 类的 TManagedControl 模板参数具有相同的类型。

有关使用 Windows 窗体控件的示例,请参阅在 MFC 中使用 Windows 窗体用户控件

CWinFormsControl::CWinFormsControl

构造 MFC Windows 窗体控件包装器对象。

CWinFormsControl();

备注

Windows 窗体控件在你调用 CWinFormsControl::CreateManagedControl 时实例化。

CWinFormsControl::GetControl

检索指向 Windows 窗体控件的指针。

inline TManagedControl^ GetControl() const;

返回值

返回指向 Windows 窗体控件的指针。

示例

请参阅 CWinFormsControl::CreateManagedControl

CWinFormsControl::GetControlHandle

检索 Windows 窗体控件的句柄。

inline HWND GetControlHandle() const;

返回值

返回 Windows 窗体控件的句柄。

备注

GetControlHandle 是一个帮助程序方法,返回存储在 .NET Framework 控件属性中的窗口句柄。 在对 CWnd::Attach 调用期间,窗口句柄值将复制到 CWnd::m_hWnd

CWinFormsControl::operator ->

替换表达式中的 CWinFormsControl::GetControl

inline TManagedControl^  operator->() const;

注解

此运算符提供了一种方便的语法,用于替换表达式中的 GetControl

有关 Windows 窗体的详细信息,请参阅在 MFC 中使用 Windows 窗体用户控件

CWinFormsControl::operator TManagedControl^

将类型强制转换为指向 Windows 窗体控件的指针。

inline operator TManagedControl^() const;

备注

此运算符将 CWinFormsControl<TManagedControl> 传递给接受指向 Windows 窗体控件的指针的函数。

另请参阅

CWinFormsDialog 类
CWinFormsView 类