D
Dan Smith
Right now the only way to use a WinForms control in MFC is to enable COM
Interop for the control and use it in MFC as you would any ActiveX control.
While this works, COM Interop is a pain, and an ActiveX control isn't as
straight-forward as a CWnd-derived object. It also means that I have to
split my code into two projects. Going the other way (using MFC in
WinForms) is only possible by exposing MFC objects as ActiveX controls,
which probalby means adding ATL to an existing MFC project.
Is any of this going to be easier/cleaner in Whidbey? What I have in mind
is something like (I'm sure I don't have all the new syntax right):
generic<typename FORM> where FORM : System::Windows::Forms::Control
ref class CControlWrapper : public CWnd
{
private:
// lots of magic code to make a System::Windows::Forms::Control object
look like a CWnd
protected:
FORM* m_WinFormControl;
};
ref class CMyControl : public CControlWrapper<MyApp::MyUserControl>
{
public:
void Method1() {
m_WinFormControl->Method1();
}
};
This would make using CMyControl as easy as any other CWnd-derived object;
which would make it much easier to integrate WinForms controls into an
existing MFC application. Going the other way would be nice too, as there
are MFC-based controls available (I'm specifically thinking of
http://codejock.com).
Can anybody comment?
Thanks,
Dan
Interop for the control and use it in MFC as you would any ActiveX control.
While this works, COM Interop is a pain, and an ActiveX control isn't as
straight-forward as a CWnd-derived object. It also means that I have to
split my code into two projects. Going the other way (using MFC in
WinForms) is only possible by exposing MFC objects as ActiveX controls,
which probalby means adding ATL to an existing MFC project.
Is any of this going to be easier/cleaner in Whidbey? What I have in mind
is something like (I'm sure I don't have all the new syntax right):
generic<typename FORM> where FORM : System::Windows::Forms::Control
ref class CControlWrapper : public CWnd
{
private:
// lots of magic code to make a System::Windows::Forms::Control object
look like a CWnd
protected:
FORM* m_WinFormControl;
};
ref class CMyControl : public CControlWrapper<MyApp::MyUserControl>
{
public:
void Method1() {
m_WinFormControl->Method1();
}
};
This would make using CMyControl as easy as any other CWnd-derived object;
which would make it much easier to integrate WinForms controls into an
existing MFC application. Going the other way would be nice too, as there
are MFC-based controls available (I'm specifically thinking of
http://codejock.com).
Can anybody comment?
Thanks,
Dan