Creating an editor window running the Matlab interpreter and exposing an Automation interface.

  1. Setup the project.

    Use the "MFC AppWizard(exe)". Call the project "MatlabInterfacingEngine".
    Install the "Automation" option.
    Install the "Single Documents" and "Document/View architecture support". Remove "Printing and print preview". Leave "Initial status bar".
    Change the basic view class to "CEditView".
    Install other options on your preference.

    Add the file libeng.lib (Matlab component) to your project.

  2. Declare and initialize the Document-class variables.

    1. Insert the following public variables.
      CMatlabInterfacingEngineView* CMatlabInterfacingEngineDoc::pView;
      Engine* CMatlabInterfacingEngineDoc::pEngine
    2. Include the statement
      class CMatlabInterfacingEngineView;
      before declaration of the CMatlabInterfacingEngineDoc.
    3. Include the statement
      #include <engine.h>
      in the file MatlabInterfacingEngineDoc.h
    4. Include the statement
      #include "MatlabInterfacingEngineView.h" in the file MatlabInterfacingEngineDoc.cpp.
    5. Go to Tools/Options/Directories and add the "include" path to the directory containing the file engine.h (Matlab component).
    6. Initialize the pEngine pointer in the constructor CMatlabInterfacingEngineDoc::CMatlabEditorWindowDoc().
    7. Initialize the pView pointer in the function CMatlabInterfacingEngineDoc::OnNewDocument().
    8. Add the clean up code to the destructor CMatlabInterfacingEngineDoc::~CMatlabInterfacingEngineDoc().

  3. Add the CEditViewStream files to the project.

    CEditOutputStream.h    CEditOutputStream.cpp
    Add the statement #include <CEditViewStream.h> to the file MatlabInterfacingEngineView.cpp.

  4. Implement initialization of the Matlab interpreter in the CEditView.

    1. Add a start up message in the CMatlabInterfacingEngine::OnInitialUpdate();
    2. Add and implement the function void CMatlabInterfacingEngineView::toPrompt( CEditViewStream& );
    3. Add and implement the function CString CMatlabInterfacingEngineView::promptString();
    4. Add the statement counter unsigned long CMatlabInterfacingEngineDoc::statementCounter;

  5. Capture <Ctrl>+<Enter>.

    1. Insert the variable bool CMatlabInterfacingEngineView::previousCtrlDown; and initialize it in the constructor of the class.
    2. Implement the message handler CMatlabInterfacingEngineView::OnKeyDown for the event WM_KEYDOWN.
    3. Implement the message handler CMatlabInterfacingEngineView::OnKeyUp for the event WM_KEYUP.
    4. Implement the message handler CmatlabInterfacingEngineView::OnChar for the event WM_CHAR.
    5. Include the statement #define WM_INTERPRET WM_USER+10 in the file MatlabInterfacingEngineView_h.html.
    6. Insert the line ON_MESSAGE(WM_INTERPRET,OnInterpret) in the message map of the file MatlabInterfacingEngineView.cpp outside of the brackets AFX_MSG_MAP.
    7. Insert the empty message handler OnInterpret.
    8. Insert the message handler prototype in the MatlabInterfacingEngineView.h.

  6. Implement the interpreter.

    1. Insert the initialization code in the doc class constructor.
    2. Insert variable matlabBuffer into the doc class.
    3. Implement the message handler void CMatlabInterfacingEngineView::OnInterpret()

  7. Attach the Automation interface.

    Use the View->ClassWizard->Automation menu to add the following methods to the class CMatlabInterfacingEngineDoc:
    1. short CMatlabInterfacingEngineDoc::evaluateString(LPCTSTR statement);
    2. short CMatlabInterfacingEngineDoc::getArray(LPCTSTR name, VARIANT FAR* putHere, short FAR* dim);
    3. BSTR CMatlabInterfacingEngineDoc::getLastOutput();
    4. short CMatlabInterfacingEngineDoc::getMatrix(LPCTSTR name, VARIANT FAR* putHere, short FAR* rows, short FAR* cols);
    5. short CMatlabInterfacingEngineDoc::getScalar(LPCTSTR name, VARIANT FAR* putHere);
    6. short CMatlabInterfacingEngineDoc::putArray(LPCTSTR name, const VARIANT FAR& value);
    7. short CMatlabInterfacingEngineDoc::putMatrix(LPCTSTR name, const VARIANT FAR& value);
    8. short CMatlabInterfacingEngineDoc::putScalar(LPCTSTR name, const VARIANT FAR& value);
      1
      Hosted by www.Geocities.ws