is there a way to calculate an amount
on visual c++ ?
using a dialog box mfc(exe)
is there a way to calculate an amount
on visual c++ ?
using a dialog box mfc(exe)
hello its me Wayko
could you be more specific?
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
i want to subtract the current year 2001 from a year that a person inputs on a edit box.
i called the edit box IDC_YEAR and the the member variable is m_Year
i added the m_Age as a double
i want m_Age to represnt 2001
hello its me Wayko
you need to make this part of the class to work as it is.
Code:#include <stdlib.h> void ClassNameHere::MakeCalcuation(void) { char Buf[21]; char* stopper; CWnd* Item = GetDlgItem(IDC_YEAR); Item.GetWindowText(Buf,20); m_Age = 2001 - strtod(buf,stopper); }
Last edited by no-one; 10-09-2001 at 12:52 PM.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
this is my code i don't see where i am going wrong
the answer suppose to subtract m_Age which is set to 2001 and m_Year where the user insert the number. after they hit submit they should get a popup window that states you are x amount years old but i get you are 0.00 years old
// ageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "age.h"
#include "ageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAgeDlg dialog
CAgeDlg::CAgeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAgeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAgeDlg)
m_Year = NULL;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//initialize m_Age field
m_Age = 2001;
}
void CAgeDlg:: DoDataExchange(CDataExchange* pDX)
{
CDialog:: DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAgeDlg)
DDX_Control(pDX, IDC_SUBMIT, m_Submit);
DDX_Text(pDX, IDC_year, m_Year);
DDV_MaxChars(pDX, m_Year, 9999);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAgeDlg, CDialog)
//{{AFX_MSG_MAP(CAgeDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_year, OnChangeyear)
ON_BN_CLICKED(IDC_SUBMIT, OnCancel)
ON_BN_CLICKED(IDC_Submit1, OnSubmit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAgeDlg message handlers
BOOL CAgeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
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 CAgeDlg::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 CAgeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAgeDlg::OnChangeyear()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CAgeDlg::OnCancel()
{
// TODO: Add your control notification handler code here
CString s;
s.Format("You are %.2f years old", m_Age);
MessageBox(s, "Your age is...");
CDialog::OnCancel();
}
void CAgeDlg::OnSubmit()
{
// 1.
CalculateAge();
// 2.
CString s;
s.Format("You are %.2f years old", m_Age);
}
void CAgeDlg::CalculateAge()
{
if (m_Year < 2001)
{
m_Age -= m_Year;
}
}
hello its me Wayko
change the OnSubmit() function to this
Code:void CAgeDlg::OnSubmit() { // 1. char Buf[21]; char* stopper; // Get a pointer to the EditBox Control CWnd* Item = GetDlgItem(IDC_YEAR); // Get its Text 20 characters max Item.GetWindowText(Buf,20); // convert the string to a double m_Year = strtod(buf,stopper); CalculateAge(); // 2. CString s; s.Format("You are %.2f years old", m_Age); }
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
or use the GetDlgItemInt to simplify your code
Code:void CAgeDlg::OnSubmit() { // 1. m_Year = GetDlgItemInt(IDC_YEAR); CalculateAge(); // 2. CString s; s.Format("You are %.2f years old", m_Age); }
..or just call UpdateData() -
Code:void CAgeDlg::OnSubmit() { // 1. UpdateData(TRUE); CalculateAge(); // 2. CString s; s.Format("You are %.2f years old", m_Age); }
zen