Upload
akhmal-haziq
View
217
Download
0
Embed Size (px)
Citation preview
8/11/2019 Assignment Lab 10
1/7
Screenshot of output:
8/11/2019 Assignment Lab 10
2/7
8/11/2019 Assignment Lab 10
3/7
8/11/2019 Assignment Lab 10
4/7
Coding:
// ElectricBillDlg.cpp : implementation file//
#include"stdafx.h"#include"ElectricBill.h"#include"ElectricBillDlg.h"#include"afxdialogex.h"#include#include#include
#ifdef_DEBUG#definenewDEBUG_NEW#endif
usingnamespacestd;
// CElectricBillDlg dialog
CElectricBillDlg::CElectricBillDlg(CWnd* pParent/*=NULL*/): CDialogEx(CElectricBillDlg::IDD, pParent)
{m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
voidCElectricBillDlg::DoDataExchange(CDataExchange* pDX){
CDialogEx::DoDataExchange(pDX);}
BEGIN_MESSAGE_MAP(CElectricBillDlg, CDialogEx)ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_DOMESTIC, &CElectricBillDlg::OnBnClickedDomestic)ON_BN_CLICKED(IDC_QUIT, &CElectricBillDlg::OnBnClickedQuit)ON_BN_CLICKED(IDC_CALCULATE, &CElectricBillDlg::OnBnClickedCalculate)
END_MESSAGE_MAP()
// CElectricBillDlg message handlers
BOOLCElectricBillDlg::OnInitDialog()
{CDialogEx::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically// when the application's main window is not a dialogSetIcon(m_hIcon, TRUE); // Set big iconSetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
returnTRUE; // 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.
8/11/2019 Assignment Lab 10
5/7
voidCElectricBillDlg::OnPaint(){
if(IsIconic()){
CPaintDCdc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND,reinterpret_cast(dc.GetSafeHdc()), 0);
// Center icon in client rectangleintcxIcon = GetSystemMetrics(SM_CXICON);intcyIcon = GetSystemMetrics(SM_CYICON);CRectrect;GetClientRect(&rect);intx = (rect.Width() - cxIcon + 1) / 2;inty = (rect.Height() - cyIcon + 1) / 2;
// Draw the icondc.DrawIcon(x, y, m_hIcon);
}else{
CDialogEx::OnPaint();}
}
// The system calls this function to obtain the cursor to display while the user drags// the minimized window.HCURSORCElectricBillDlg::OnQueryDragIcon(){
returnstatic_cast(m_hIcon);}
voidCElectricBillDlg::OnBnClickedDomestic(){
// TODO: Add your control notification handler code here}
voidCElectricBillDlg::OnBnClickedQuit(){
// TODO: Add your control notification handler code hereexit(0);
}
voidCElectricBillDlg::OnBnClickedCalculate(){
// TODO: Add your control notification handler code hereCButton* domesticButton=(CButton*)GetDlgItem(IDC_DOMESTIC);CButton* industrialButton=(CButton*)GetDlgItem(IDC_INDUSTRIAL);CButton* comercialButton=(CButton*)GetDlgItem(IDC_COMERCIAL);
if(domesticButton ->GetCheck()){
floatresult;floatkwh;
CStringtotal;
8/11/2019 Assignment Lab 10
6/7
kwh=GetDlgItemInt(IDC_CONSUMPTION);result=kwh*0.3166;total.Format (_T("%f"),result);SetDlgItemText(IDC_RESULT, total);
ofstreamElectricBill;
ElectricBill.open("../TotalPayment.txt",ios::out | ios::trunc);
if(ElectricBill.is_open()){
ElectricBill
8/11/2019 Assignment Lab 10
7/7
SetDlgItemText(IDC_NOTE, _T("Payment unable to record"));}
}
else{
SetDlgItemText(IDC_OUTPUT, _T("Please Insert A Number In ElectricConsumption And Choose One Option."));
}
}