MFC Demo Script
MFC Demo Script
Have open:
Visual Studio
Windows explorer to C:\working\Microsoft\Tech Ed 2006\Europe\MFCWin\WinFormsDialog - Final
Open WinFormsDialog.sln
Run the application first thing. Mouse over the image in the centre of the dialog it is a bounce button.
This is a .NET control being used in an MFC app.
Click the button. Click OK on the message box. Click Cancel to close the dialog app.
Now show how its done. You can find-in-files for step to simplify moving around.
Open WinFormsDialogDlg.h which defines the dialog for this app. Show how its all MFC-ish.
Towards the bottom, see the use of CWinFormsControl (step 1) which is a template to wrap a .NET control.
Show the signature of the OnClick method which is a .NET-style event handling signature, not like usual
MFC message maps.
Below that show the new DELEGATE_MAP macros that connect the button event to this delegate-style
event handler.
Now open WinFormsDialogDlg.cpp.
Line 59 (step 2) show the DDX equivalence that binds this control, m_button, into the dialog class.
Line 157 (step 3) show the code to set the Image property and hook in the OnClick handler using the
MAKE_DELEGATE macro.
Then finally the code for OnClick which despite its signature is implemented in an MFC-ish way.
new MFC app - Kate
finish on wizard with all defaults
right click on solution, add new project, clr, winforms control library, PinkText
put a text box on the control and turn on accepts return, accepts tabs, turn on multiline, dock to top, stretch
down to most of control, background bright pink.
now back in mfc app, add a class, MFC Class, inherit from CView, call it PinkTextWrapper
build entire mfc app /clr - explain that real apps shouldn't do that (configuration properties, general)
now in PinkTextWrapper.h change CView - which you just said on the class wizard - to CWinFormsView.
add #include "afxwinforms.h" at the top of that file
and throughout the .cpp change CView to CWinFormsView (4 of them)
in the default ctor add base passing:
:CWinFormsView(PinkText::PinkTextControl::typeid)
add a project reference to the control project
now flip to Kate.cpp and in InitInstance find RUNTIME_CLASS(CKateView) and change it to
PinkTextWrapper.
add #include " PinkTextWrapper.h" at the top.
go ahead and run it and you'll see the text box at the bottom of the view.
Reset: delete the Kate project folder