分享方式:


CWinFormsControl 類別

提供裝載 Windows Form 控制項的基本功能。

語法

template<class TManagedControl>
class CWinFormsControl : public CWnd

參數

TManagedControl
要顯示在 MFC 應用程式中的 .NET Framework Windows Forms 控制件。

成員

公用建構函式

名稱 描述
CWinFormsControl::CWinFormsControl 建構 MFC Windows Forms 控制件包裝函式物件。

公用方法

名稱 描述
CWinFormsControl::CreateManagedControl 在 MFC 容器中建立 Windows Forms 控件。
CWinFormsControl::GetControl 擷取 Windows Forms 控件的指標。
CWinFormsControl::GetControlHandle 擷取 Windows Forms 控件的句柄。

公用運算子

名稱 描述
CWinFormsControl::operator -> 取代表達式中的 CWinFormsControl::GetControl
CWinFormsControl::operator TManagedControl^ 將類型轉換成 Windows Forms 控制件的指標。

備註

類別 CWinFormsControl 提供裝載 Windows Form 控制項的基本功能。

如需使用 Windows Forms 的詳細資訊,請參閱 在 MFC 中使用 Windows Form 使用者控制件。

您的 MFC 程式代碼不應該快取視窗句柄(通常儲存在 m_hWnd中)。 某些 Windows Forms 控件屬性需要使用 DestroyWindowCreateWindow來終結並重新建立基礎 Win32Window。 MFC Windows Forms 實作會處理控件的 DestroyCreate 事件,以更新 m_hWnd 成員。

注意

MFC Windows Forms 整合僅適用於動態連結 MFC 的專案(定義 AFXDLL 的專案)。

需求

標頭: afxwinforms.h

CWinFormsControl::CreateManagedControl

在 MFC 容器中建立 Windows Forms 控件。

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 Forms 控制件會取代靜態控件,並假設其位置、迭置順序和樣式(僅限第二個多載)。

pParentWnd
父視窗的指標。

nID
要指派給新建立控件的資源標識符。

pControl
與 CWinFormsControl 物件相關聯之 Windows Forms 控件的實例(僅限第四個多載)。

傳回值

如果成功,則傳回非零值。 如果失敗,則傳回零。

備註

這個方法會在 MFC 容器中具現化 .NET Framework Windows Forms 控件。

方法的第一個多載會接受 .NET Framework 數據類型 pType ,讓 MFC 可以具現化此類型的新物件。 pType 必須是 Type 數據類型。

方法的第二個多載會根據 TManagedControl 類別的 CWinFormsControl 樣板參數建立 Windows Forms 控件。 控件的大小和位置是以傳遞至 方法的結構為基礎 RECT 。 只有 dwStyle 才對樣式很重要。

方法的第三個多載會建立一個 Windows Forms 控件,以取代靜態控件,終結它並假設其位置、z 順序和樣式。 靜態控件僅做為 Windows Forms 控件的佔位符。 建立控件時,這個多載會結合 dwStyle 中的樣式與靜態控件的資源樣式。

方法的第四個多載可讓您傳入 MFC 將包裝的已具現化 Windows Forms 控件 pControl 。 它的類型必須與 類別的CWinFormsControl樣板參數相同TManagedControl

如需使用 Windows Form 控制件的範例,請參閱 在 MFC 中使用 Windows Form 使用者控制件。

CWinFormsControl::CWinFormsControl

建構 MFC Windows Forms 控制件包裝函式物件。

CWinFormsControl();

備註

當您呼叫 CWinFormsControl::CreateManagedControl 時,會具現化 Windows Forms 控件。

CWinFormsControl::GetControl

擷取 Windows Forms 控件的指標。

inline TManagedControl^ GetControl() const;

傳回值

傳回 Windows Forms 控制件的指標。

範例

請參閱 CWinFormsControl::CreateManagedControl

CWinFormsControl::GetControlHandle

擷取 Windows Forms 控件的句柄。

inline HWND GetControlHandle() const;

傳回值

傳回 Windows Forms 控制件的句柄。

備註

GetControlHandle 是可傳回儲存在 .NET Framework 控件屬性中的視窗句柄的協助程式方法。 在呼叫 CWnd::Attach 期間,視窗句柄值會複製到 CWnd::m_hWnd

CWinFormsControl::operator ->

取代表達式中的 CWinFormsControl::GetControl

inline TManagedControl^  operator->() const;

備註

此運算子提供方便的語法,以取代 GetControl 表達式中。

如需 Windows Forms 的詳細資訊,請參閱 在 MFC 中使用 Windows Form 使用者控件。

CWinFormsControl::operator TManagedControl^

將類型轉換成 Windows Forms 控制件的指標。

inline operator TManagedControl^() const;

備註

這個運算符會傳遞 CWinFormsControl<TManagedControl> 至接受 Windows Forms 控件指標的函式。

另請參閱

CWinFormsDialog 類別
CWinFormsView 類別