我正在尝试在 MFC 应用程序下托管 WPF 窗口。我创建了一个 CCustomEditor 类来包装 WPF 窗口。它具有以下创建方法。
BOOL CCustomEditor::Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd)
{
if (objInterop == NULL)
{
DialogWindow ^myWindow = gcnew DialogWindow(pParentWnd);
CUnmanagedCustomEditor *objProxy = new CUnmanagedCustomEditor();
objInterop = objProxy;
System::String ^strClassName = msclr::interop::marshal_as<System::String ^>(lpszWindowName);
HwndSourceParameters^ sourceParams = gcnew HwndSourceParameters(strClassName);
sourceParams->PositionX = rect.left;
sourceParams->PositionY = rect.top;
sourceParams->ParentWindow = System::IntPtr(pParentWnd->GetSafeHwnd());
sourceParams->WindowStyle = dwStyle;
objProxy->m_hwndSource= gcnew HwndSource(*sourceParams);
objProxy->m_wpfUC = myWindow;
objProxy->m_hwndSource->RootVisual = objProxy->m_wpfUC;
// we need to attach a handle since it is a window control
Attach((HWND) objProxy->m_hwndSource->Handle.ToPointer());
}
return TRUE;
}
我遇到的问题是:
DialogWindow ^myWindow = gcnew DialogWindow(pParentWnd);
我意识到不能将 CWnd 直接视为 System.Windows.Window 但我不确定需要进行哪种转换。