www.pudn.com > myopenforcal.zip > SimpleOpenFCDlg.cpp
// SimpleOpenFCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SimpleOpenFC.h"
#include "SimpleOpenFCDlg.h"
#include "math.h" //使用数学函数;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HINSTANCE OpenForcalDll;
//得到初始化动态库函数的地址;
typedef bool (* pInitDll)(char *,char *);
pInitDll pInitDllp;
//得到释放动态库函数的地址;
typedef void (* pFreeDll)(void);
pFreeDll pFreeDllp;
//得到编译函数的地址;
typedef void (* pCOMPLEXfun) (_complex );
typedef void (* pDOUBLEfun) (double );
typedef void (* pLONGfun) (long );
typedef void (* pDllMessage) (char *);
void outl(long);
void outd(double);
void outc(_complex);
void DllMessage(char *);
typedef int (* pComFor) (char *,char *&,pLONGfun ,pDOUBLEfun ,pCOMPLEXfun ,pDllMessage);
pComFor pComForp;
//得到计算函数的地址;
typedef int (* pExeFor) (long ,long ,int);
pExeFor pExeForp;
//保存输出窗口的地址;
CEdit *pout;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSimpleOpenFCDlg dialog
CSimpleOpenFCDlg::CSimpleOpenFCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSimpleOpenFCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSimpleOpenFCDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSimpleOpenFCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSimpleOpenFCDlg)
DDX_Control(pDX, IDC_out, m_out);
DDX_Control(pDX, IDC_text, m_text);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSimpleOpenFCDlg, CDialog)
//{{AFX_MSG_MAP(CSimpleOpenFCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_cal, Oncal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSimpleOpenFCDlg message handlers
BOOL CSimpleOpenFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
OpenForcalDll=NULL;
OpenForcalDll=LoadLibrary("OpenForcal.dll");
if(OpenForcalDll)
{pComForp=(pComFor) GetProcAddress(OpenForcalDll,"ComFor");
pExeForp=(pExeFor) GetProcAddress(OpenForcalDll,"ExeFor");
pInitDllp=(pInitDll) GetProcAddress(OpenForcalDll,"InitDll");
pInitDllp(NULL,NULL);
pFreeDllp=(pFreeDll) GetProcAddress(OpenForcalDll,"FreeDll");
}
else
{AfxMessageBox("找不到动态库OpenForcal.dll,请将OpenForcal.dll放到Windows的搜索路径内!",MB_OK,0);}
pout=&m_out;//保存输出窗口的地址;
return TRUE; // return TRUE unless you set the focus to a control
}
void CSimpleOpenFCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSimpleOpenFCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSimpleOpenFCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSimpleOpenFCDlg::Oncal()
{
// TODO: Add your control notification handler code here
CString textstr;
int n;
char *err_str="",ch[32];
m_text.GetWindowText(textstr);
if(OpenForcalDll)
{n=pComForp((char *)(LPCTSTR)textstr,err_str,outl,outd,outc,DllMessage);
if(n)
{m_out.ReplaceSel(err_str);
m_out.ReplaceSel("\r\n编译错误代码:");
m_out.ReplaceSel(itoa(n,ch,10));
}
pExeForp(0,-1,2);
}
}
BOOL CSimpleOpenFCDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if(OpenForcalDll)
{pFreeDllp();
FreeLibrary(OpenForcalDll);
}
return CDialog::DestroyWindow();
}
/////////////////////////////////////////////
void outl(long ll)
{char ch[32];
pout->ReplaceSel("i:");
pout->ReplaceSel(ltoa(ll,ch,10));
pout->ReplaceSel("\r\n");
}
void outd(double dd)
{char ch[32];
pout->ReplaceSel(gcvt(dd,16,ch));
pout->ReplaceSel("\r\n");
}
void outc(_complex cc)
{char ch[32];
pout->ReplaceSel("c:");
pout->ReplaceSel(gcvt(cc.x,16,ch));
if(cc.y>=0.0) pout->ReplaceSel("+");
pout->ReplaceSel(gcvt(cc.y,16,ch));
pout->ReplaceSel("i\r\n");
}
void DllMessage(char *ch) {pout->ReplaceSel(ch); pout->ReplaceSel("\r\n");}
///////////////////////////////