📄 atmdlg.cpp
字号:
// ATMDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ATM.h"
#include "ATMDlg.h"
#include "DlgExchange.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//为组件库初始化定义
#include <objbase.h>
extern BOOL g_IsAccountValid;
extern CString g_AccountID;
BOOL g_ExchangeType=FALSE; //交易类型,True为存钱,False为取钱
float g_CurrentFund=0.0; //当前余额
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CATMDlg dialog
CATMDlg::CATMDlg(CWnd* pParent /*=NULL*/)
: CDialog(CATMDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CATMDlg)
m_AccountID = _T("");
m_CurrentFund = _T("");
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CATMDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CATMDlg)
DDX_Text(pDX, IDC_Account, m_AccountID);
DDV_MaxChars(pDX, m_AccountID, 12);
DDX_Text(pDX, IDC_Money, m_CurrentFund);
DDV_MaxChars(pDX, m_CurrentFund, 12);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CATMDlg, CDialog)
//{{AFX_MSG_MAP(CATMDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_WithDraw, OnWithDraw)
ON_BN_CLICKED(IDC_Deposit, OnDeposit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CATMDlg message handlers
BOOL CATMDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
QueryCurrentFund();
return TRUE;
}
void CATMDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
CDialog::OnSysCommand(nID, lParam);
}
void CATMDlg::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();
}
HCURSOR CATMDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//===================================================
void CATMDlg::OnWithDraw()
{
g_ExchangeType = FALSE; //
CDlgExchange dlg;
dlg.DoModal();
QueryCurrentFund();
}
void CATMDlg::OnDeposit()
{
g_ExchangeType = TRUE; //
CDlgExchange dlg;
dlg.DoModal();
QueryCurrentFund();
}
void CATMDlg::QueryCurrentFund() //查询余额
{
HRESULT hr;
IAccount *IAccount; //指向接口的指针
COSERVERINFO srvinfo={0,L"192.168.0.2",NULL,0};
MULTI_QI MultiQI = {&IID_IUnknown,NULL,NOERROR};
hr=CoCreateInstanceEx(CLSID_Account, NULL, CLSCTX_REMOTE_SERVER,
&srvinfo, 1, &MultiQI);
if(hr!=0)
AfxMessageBox("COM组件创建失败!");
else
{
BSTR UserID = A2BSTR(g_AccountID);
float currentFund=0.0 ;
hr = IAccount->GetCurrentFund(UserID,¤tFund); // call method
g_CurrentFund = currentFund;
m_AccountID = g_AccountID;
m_CurrentFund.Format("%10.2f", currentFund);
hr = IAccount->Release(); //释放接口
}
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -