📄 variablesdlg.cpp
字号:
// VariablesDlg.cpp : implementation file
//
#include "stdafx.h"
#include "calculator.h"
#include "VariablesDlg.h"
#include "AddVariableDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVariablesDlg dialog
CVariablesDlg::CVariablesDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVariablesDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVariablesDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pParser = NULL;
}
void CVariablesDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVariablesDlg)
DDX_Control(pDX, IDC_EDIT_VALUE, m_ctrlVarValue);
DDX_Control(pDX, IDC_LIST_VARIABLES, m_ctrlListVariables);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVariablesDlg, CDialog)
//{{AFX_MSG_MAP(CVariablesDlg)
ON_LBN_SELCHANGE(IDC_LIST_VARIABLES, OnSelchangeListVariables)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVariablesDlg message handlers
BOOL CVariablesDlg::OnInitDialog()
{
CDialog::OnInitDialog();
LPCSTR szVarName = NULL;
if(m_pParser != NULL)
{
szVarName = m_pParser->GetFirstVariableName();
while(szVarName != NULL)
{
m_ctrlListVariables.AddString(szVarName);
szVarName = m_pParser->GetNextVariableName();
}
}
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CVariablesDlg::OnSelchangeListVariables()
{
CString strVarName;
VARIANT varValue;
varValue.vt = VT_NULL;
m_ctrlListVariables.GetText(m_ctrlListVariables.GetCurSel(),strVarName.GetBuffer(128));
strVarName.ReleaseBuffer();
if(m_pParser->GetVariableValue(strVarName, varValue))
{
CString strRez;
switch(varValue.vt)
{
case VT_R8:
{
strRez.Format("%f",varValue.dblVal);
break;
}
case VT_BSTR:
{
CString strRezult(varValue.bstrVal);
strRez.Format("\"%s\"",strRezult);
break;
}
case VT_DATE:
{
COleDateTime dte(varValue.date);
strRez = "{"+dte.Format()+"}";
break;
}
case VT_BOOL:
{
if(varValue.boolVal)
strRez = ".T.";
else
strRez = ".F.";
break;
}
default:
strRez = "Error result";
}
m_ctrlVarValue.SetWindowText(strRez);
}
else
m_ctrlVarValue.SetWindowText("Error");
}
void CVariablesDlg::OnButtonAdd()
{
CAddVariableDlg m_AddVariableDlg;
m_AddVariableDlg.m_pParser = m_pParser;
if(m_AddVariableDlg.DoModal() == IDOK)
{
m_ctrlListVariables.SetCurSel(m_ctrlListVariables.AddString(m_AddVariableDlg.m_strVarName));
OnSelchangeListVariables();
}
}
void CVariablesDlg::OnButtonDel()
{
m_pParser->Parse("0");
CString strVarName;
int nVar = m_ctrlListVariables.GetCurSel();
m_ctrlListVariables.GetText(nVar, strVarName);
if(!m_pParser->DelVariable(strVarName))
AfxMessageBox("The variable is not deleted.");
else
{
m_ctrlListVariables.DeleteString(nVar);
m_ctrlVarValue.SetWindowText("");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -