A little help
Hi, I''m hoping you can help me out. I working on a program were, there are five edit boxes. One is for a first name, another second, third hours worked, the fourth pay rate, and the last is total pay. Then there are three button across the bottom, calculate total pay, Clear screen, and Exit. When you click the calculate total pay button, it''s supposed take the users input for hours worked, and pay rate then multiply them, and show the answer in the total pay box. But I don''t know how to do this. I hope you can help me. Oh, I''m using C++. Thanks!
veni vidi vici"Be excellent to Each other" Bill and Ted
Are you using win32 programming or MFC?
For win32 use the GetDlgItemText and SetDlgItemText
For MFC its GetWindowText and SetWindowText methods of the CEdit class but Im not sure (don't use MFC as much as I should )
Whoops forgot, then use atoi to change string to number then itoa to convert the answer back to a string to set in the edit box when you are done.
[edited by - Drazgal on February 20, 2003 7:55:39 AM]
For win32 use the GetDlgItemText and SetDlgItemText
For MFC its GetWindowText and SetWindowText methods of the CEdit class but Im not sure (don't use MFC as much as I should )
Whoops forgot, then use atoi to change string to number then itoa to convert the answer back to a string to set in the edit box when you are done.
[edited by - Drazgal on February 20, 2003 7:55:39 AM]
check out UpdateData function in msdn (if using MFC in VC++)
using class wizard, add a member variable for the CEdit control. in Value type (NOT Control), with float/CString whatever type you want..
in your Calculate button function, call with UpdateData(TRUE) to retrieve values from your CEdits to member variable, and call UpdateData(FALSE) to write new values to CEdit from the member variable.
using class wizard, add a member variable for the CEdit control. in Value type (NOT Control), with float/CString whatever type you want..
in your Calculate button function, call with UpdateData(TRUE) to retrieve values from your CEdits to member variable, and call UpdateData(FALSE) to write new values to CEdit from the member variable.
-----------my quote is under construction
Yes, I'm using MFC, and thanks for the reply's. But could you right in English, I'm not a C++ language expert. Thanks alot!!
[edited by - fencingone on February 20, 2003 8:27:30 AM]
[edited by - fencingone on February 20, 2003 8:27:30 AM]
veni vidi vici"Be excellent to Each other" Bill and Ted
Okay, I added code for the Calcualte total pay button but I''m getting a ton of errors, and I don''t know why. Please help me out. If you could just tell me how to fix this, I will be very greatfull. I know it''s alot(well for me). My code is at the bottom. thanks alot!!!
// Exercise 1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Exercise 1.h"
#include "Exercise 1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CExercise1Dlg dialog
CExercise1Dlg::CExercise1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CExercise1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExercise1Dlg)
m_sFName = _T("");
m_sLName = _T("");
m_sHWorked = 0.0f;
m_sPRate = 0.0f;
m_sTPay = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExercise1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExercise1Dlg)
DDX_Text(pDX, IDC_FNAME, m_sFName);
DDX_Text(pDX, IDC_LNAME, m_sLName);
DDX_Text(pDX, IDC_HWORKED, m_sHWorked);
DDX_Text(pDX, IDC_PRATE, m_sPRate);
DDX_Text(pDX, IDC_TPAY, m_sTPay);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExercise1Dlg, CDialog)
//{{AFX_MSG_MAP(CExercise1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_CALTOTALPAY, OnCaltotalpay)
ON_BN_CLICKED(IDC_CLEARSCREEN, OnClearscreen)
ON_BN_CLICKED(IDC_CALCTOTAL, OnCalctotal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExercise1Dlg message handlers
BOOL CExercise1Dlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CExercise1Dlg::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 CExercise1Dlg::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(▭);
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 CExercise1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CExercise1Dlg::OnExit()
{
// TODO: Add your control notification handler code here
////////////////////
//MY CODE ENDS HERE
////////////////////
//Exit the program
OnOK();
////////////////////
//MY CODE ENDS HERE
////////////////////
}
void CExercise1Dlg::OnClearscreen()
{
// TODO: Add your control notification handler code here
//////////////////////
//MY CODE STARTS HERE
//////////////////////
// clear the edit boxes
m_sFName, m_sLName, m_sHWorked, m_sPRate, m_sTPay = "";
//Update the screen
UpdateData (FALSE);
////////////////////
//MY CODE ENDS HERE
////////////////////
}
void CExercise1Dlg::OnCalctotal()
{
// TODO: Add your control notification handler code here
//////////////////////
//MY CODE STARTS HERE
//////////////////////
UpdateData(TRUE);
m_sTPay=m_sPRate*m_sHWorked;
UpdateData(FALSE);
////////////////////
//MY CODE ENDS HERE
////////////////////
}
// Exercise 1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Exercise 1.h"
#include "Exercise 1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CExercise1Dlg dialog
CExercise1Dlg::CExercise1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CExercise1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExercise1Dlg)
m_sFName = _T("");
m_sLName = _T("");
m_sHWorked = 0.0f;
m_sPRate = 0.0f;
m_sTPay = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExercise1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExercise1Dlg)
DDX_Text(pDX, IDC_FNAME, m_sFName);
DDX_Text(pDX, IDC_LNAME, m_sLName);
DDX_Text(pDX, IDC_HWORKED, m_sHWorked);
DDX_Text(pDX, IDC_PRATE, m_sPRate);
DDX_Text(pDX, IDC_TPAY, m_sTPay);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExercise1Dlg, CDialog)
//{{AFX_MSG_MAP(CExercise1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_CALTOTALPAY, OnCaltotalpay)
ON_BN_CLICKED(IDC_CLEARSCREEN, OnClearscreen)
ON_BN_CLICKED(IDC_CALCTOTAL, OnCalctotal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExercise1Dlg message handlers
BOOL CExercise1Dlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CExercise1Dlg::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 CExercise1Dlg::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(▭);
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 CExercise1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CExercise1Dlg::OnExit()
{
// TODO: Add your control notification handler code here
////////////////////
//MY CODE ENDS HERE
////////////////////
//Exit the program
OnOK();
////////////////////
//MY CODE ENDS HERE
////////////////////
}
void CExercise1Dlg::OnClearscreen()
{
// TODO: Add your control notification handler code here
//////////////////////
//MY CODE STARTS HERE
//////////////////////
// clear the edit boxes
m_sFName, m_sLName, m_sHWorked, m_sPRate, m_sTPay = "";
//Update the screen
UpdateData (FALSE);
////////////////////
//MY CODE ENDS HERE
////////////////////
}
void CExercise1Dlg::OnCalctotal()
{
// TODO: Add your control notification handler code here
//////////////////////
//MY CODE STARTS HERE
//////////////////////
UpdateData(TRUE);
m_sTPay=m_sPRate*m_sHWorked;
UpdateData(FALSE);
////////////////////
//MY CODE ENDS HERE
////////////////////
}
veni vidi vici"Be excellent to Each other" Bill and Ted
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement