// Pledge1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Pledge1.h"
#include "Pledge1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPledge1Dlg dialog
CPledge1Dlg::CPledge1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CPledge1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPledge1Dlg)
m_AmountPledged = _T("1000");
m_Amount1 = _T("$500.00");
m_Amount2 = _T("$250.00");
m_Amount3 = _T("$250.00");
m_Message = _T("");
m_RateValue1 = _T("");
m_RateValue2 = _T("");
m_RateValue3 = _T("");
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPledge1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPledge1Dlg)
DDX_Control(pDX, IDC_SPIN_RATE3, m_Rate3);
DDX_Control(pDX, IDC_SPIN_RATE2, m_Rate2);
DDX_Control(pDX, IDC_SPIN_RATE1, m_Rate1);
DDX_Text(pDX, IDC_AMOUNT_PLEDGED, m_AmountPledged);
DDX_Text(pDX, IDC_AMOUNT1, m_Amount1);
DDX_Text(pDX, IDC_AMOUNT2, m_Amount2);
DDX_Text(pDX, IDC_AMOUNT3, m_Amount3);
DDX_Text(pDX, IDC_MESSAGE, m_Message);
DDX_Text(pDX, IDC_RATE_VALUE1, m_RateValue1);
DDX_Text(pDX, IDC_RATE_VALUE2, m_RateValue2);
DDX_Text(pDX, IDC_RATE_VALUE3, m_RateValue3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPledge1Dlg, CDialog)
//{{AFX_MSG_MAP(CPledge1Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPledge1Dlg message handlers
BOOL CPledge1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
this->m_Rate1.SetRange(0, 100);
this->m_Rate1.SetPos(50);
this->m_Rate2.SetRange(0, 100);
this->m_Rate2.SetPos(25);
this->m_Rate3.SetRange(0, 100);
this->m_Rate3.SetPos(25);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CPledge1Dlg::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 CPledge1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPledge1Dlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
UpdateData();
double AmountPledged,
Value1,
Value2,
Value3,
Amount1,
Amount2,
Amount3,
Rest;
int Rate1, Rate2, Rate3;
AmountPledged = atof(this->m_AmountPledged);
CSpinButtonCtrl *spnRate1, *spnRate2, *spnRate3;
// Identify the spin buttons of the dialog box using their IDentifiers
spnRate1 = reinterpret_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN_RATE1));
spnRate2 = reinterpret_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN_RATE2));
spnRate3 = reinterpret_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN_RATE3));
// Find out what spin button fired the event
if( reinterpret_cast<CSpinButtonCtrl *>(pScrollBar) == spnRate1 )
{
Value2 = atof(this->m_RateValue2);
Value3 = atof(this->m_RateValue3);
Rate2 = this->m_Rate2.GetPos();
Rate3 = this->m_Rate3.GetPos();
this->m_Rate1.SetRange(0, 100 - Rate3 - Rate2);
Value1 = atof(this->m_RateValue1);
Rate1 = this->m_Rate1.GetPos();
}
else if( reinterpret_cast<CSpinButtonCtrl *>(pScrollBar) == spnRate2 )
{
Value1 = atof(this->m_RateValue1);
Value3 = atof(this->m_RateValue3);
Rate1 = this->m_Rate1.GetPos();
Rate3 = this->m_Rate3.GetPos();
this->m_Rate2.SetRange(0, 100 - Rate1 - Rate3);
Value2 = atof(this->m_RateValue2);
Rate2 = this->m_Rate2.GetPos();
}
else if( reinterpret_cast<CSpinButtonCtrl *>(pScrollBar) == spnRate3 )
{
Value1 = atof(this->m_RateValue1);
Rate1 = this->m_Rate1.GetPos();
Value2 = atof(this->m_RateValue2);
Rate2 = this->m_Rate2.GetPos();
this->m_Rate3.SetRange(0, 100 - Rate1 - Rate2);
Value3 = atof(this->m_RateValue3);
Rate3 = this->m_Rate3.GetPos();
}
Amount1 = AmountPledged * Value1 / 100;
Amount2 = AmountPledged * Value2 / 100;
Amount3 = AmountPledged * Value3 / 100;
Rest = AmountPledged - Amount1 - Amount2 - Amount3;
this->m_Amount1.Format("$%.2f", Amount1);
this->m_Amount2.Format("$%.2f", Amount2);
this->m_Amount3.Format("$%.2f", Amount3);
if( Rest > 0 )
this->m_Message.Format("$%.2f still to be used", Rest);
else
this->m_Message = "";
UpdateData(FALSE);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
|