📄 activefemm.cpp
字号:
// ActiveFEMM.cpp : implementation file
//
#include "stdafx.h"
#include "femmview.h"
#include "lua.h"
#include "luadebug.h"
#include "luaconsoledlg.h"
#include "ActiveFEMM.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern lua_State *lua;
extern BOOL bLinehook;
extern BOOL lua_byebye;
//extern HANDLE hProc;
extern int m_luaWindowStatus;
extern CFemmviewApp theApp;
CString LuaResult;
/////////////////////////////////////////////////////////////////////////////
// ActiveFEMM
IMPLEMENT_DYNCREATE(ActiveFEMM, CCmdTarget)
ActiveFEMM::ActiveFEMM()
{
EnableAutomation();
EnableTypeLib();
// To keep the application running as long as an OLE automation
// object is active, the constructor calls AfxOleLockApp.
AfxOleLockApp();
}
ActiveFEMM::~ActiveFEMM()
{
// To terminate the application when all objects created with
// with OLE automation, the destructor calls AfxOleUnlockApp.
AfxOleUnlockApp();
}
void ActiveFEMM::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
// We have to close things in a funny way so that FEMM shuts down
// the way that it expects to. First, the call to AfxOleSetUserCtrl
// makes it so that the the application won't get closed when the
// base class version of OnFinalRelease gets called.
AfxOleSetUserCtrl(TRUE);
// Then, post a message to the main window requesting a shutdown.
// This is the way that FEMM likes to shut down. Since the message
// has been posted rather than sent, it will be acted upon after
// ActiveFEMM has shut itself down.
AfxGetMainWnd()->PostMessage(WM_CLOSE);
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(ActiveFEMM, CCmdTarget)
//{{AFX_MSG_MAP(ActiveFEMM)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(ActiveFEMM, CCmdTarget)
//{{AFX_DISPATCH_MAP(ActiveFEMM)
DISP_FUNCTION(ActiveFEMM, "call2femm", call2femm, VT_BSTR, VTS_BSTR)
DISP_FUNCTION(ActiveFEMM, "mlab2femm", mlab2femm, VT_BSTR, VTS_BSTR)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
// {EE5BB3DE-259D-400C-81D3-C31492BAC758}
static const GUID _tlid =
{ 0xEE5BB3DE, 0x259D, 0x400C, { 0x81, 0xD3, 0xC3, 0x14, 0x92, 0xBA, 0xC7, 0x58 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
IMPLEMENT_OLETYPELIB(ActiveFEMM, _tlid, _wVerMajor, _wVerMinor)
// Note: we add support for IID_IActiveFEMM to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {E208164C-7724-4879-9AA3-E0BBC98A1A2F}
static const IID IID_IActiveFEMM =
{ 0xe208164c, 0x7724, 0x4879, { 0x9a, 0xa3, 0xe0, 0xbb, 0xc9, 0x8a, 0x1a, 0x2f } };
BEGIN_INTERFACE_MAP(ActiveFEMM, CCmdTarget)
INTERFACE_PART(ActiveFEMM, IID_IActiveFEMM, Dispatch)
END_INTERFACE_MAP()
// {0765F1A1-9084-41AF-8678-B8B5C17041CF}
IMPLEMENT_OLECREATE(ActiveFEMM, "femmview.ActiveFEMM",0x0765F1A1,0x9084,0x41AF,0x86,0x78,0xB8,0xB5,0xC1,0x70,0x41,0xCF)
BOOL ActiveFEMM::GetDispatchIID(IID* pIID)
{
*pIID = IID_IActiveFEMM;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// ActiveFEMM message handlers
BSTR ActiveFEMM::call2femm(LPCTSTR luacmd)
{
// executes the line contained in luacmd
// and returns a string containing the results
// of the command with the results separated
// by newline characters.
CString strToLua;
strToLua=luacmd;
strToLua="actxprint(" + strToLua +")";
DoLuaCmd(strToLua);
return LuaResult.AllocSysString();
}
BSTR ActiveFEMM::mlab2femm(LPCTSTR luacmd)
{
// executes the line contained in luacmd
// and returns a string containing the results
// of the command formatted in matlab format.
// One would expect that all the results are
// real numbers, in which case we can eval()
// the result in matlab to get a vector of numbers.
CString strToLua;
strToLua=luacmd;
strToLua="lua2matlab(" + strToLua +")";
DoLuaCmd(strToLua);
return LuaResult.AllocSysString();
}
void ActiveFEMM::DoLuaCmd(CString strToLua)
{
LuaResult.Empty();
if(m_luaWindowStatus==SW_SHOW) bLinehook=1;
else bLinehook=2;
theApp.bActiveX=TRUE;
if (lua_dostring(lua,strToLua)!=0) LuaResult=theApp.LuaErrmsg;
theApp.bActiveX=FALSE;
lua_byebye=FALSE;
bLinehook=FALSE;
}
int ActiveFEMM::lua_to_string(lua_State *L)
{
CString s;
int n = lua_gettop(L);
LuaResult="";
for(int k=1;k<=n;k++)
{
s=lua_tostring(L,k);
LuaResult = LuaResult + s +"\n";
}
return 0;
}
int ActiveFEMM::lua_to_matlab(lua_State *L)
{
CString s;
int n = lua_gettop(L);
if(n>0){
LuaResult="[ ";
for(int k=1;k<=n;k++)
{
s=lua_tostring(L,k);
LuaResult = LuaResult + s + " ";
}
LuaResult += "]";
}
else LuaResult.Empty();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -