Você está na página 1de 12

PROGRAM :

// SpinnDlg.cpp : implementation file


//
#include "stdafx.h"
#include "Spinn.h"
#include "SpinnDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CAboutDlg dialog used for App About


class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);

// DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()

JERRY CHACKO

UR11CS042

// CSpinnDlg dialog

CSpinnDlg::CSpinnDlg(CWnd* pParent /*=NULL*/)


: CDialogEx(CSpinnDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_strEdit = _T("");
}
void CSpinnDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SPIN, m_cSpin);
// DDX_Control(pDX, IDC_EDIT, m_strEdit);
DDX_Text(pDX, IDC_EDIT, m_strEdit);
}
BEGIN_MESSAGE_MAP(CSpinnDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, &CSpinnDlg::OnDeltaposSpin)
END_MESSAGE_MAP()

// CSpinnDlg message handlers


BOOL CSpinnDlg::OnInitDialog()
{
CDialogEx::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)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);

JERRY CHACKO

UR11CS042

ASSERT(bNameValid);
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
m_cSpin.SetRange(1, 1000);
UDACCEL uda[3];
uda[0].nSec=0;
uda[0].nInc=1; //Start incrementing by One
uda[1].nSec=3;
uda[2].nInc=5; //After 3 seconds increment by 5
uda[3].nSec=5;
uda[3].nInc=20; //5 seconds later (or t+8) increment by 20
m_cSpin.SetAccel(3,uda); //the first argument is the number
//of elements in the array
m_strEdit="DEFAULT";
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSpinnDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::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.

JERRY CHACKO

UR11CS042

void CSpinnDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<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
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSpinnDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CSpinnDlg::OnDeltaposSpin(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
NM_UPDOWN* spin = (NM_UPDOWN*)pNMHDR;
switch((*spin).iPos+(*spin).iDelta){
case 1: m_strEdit="This"; break;
case 2: m_strEdit="is"; break;
case 3: m_strEdit="fun!"; break;
}
UpdateData(FALSE);
*pResult = 0;
}

JERRY CHACKO

UR11CS042

PROGRAM :
// diag_sampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "diag_sample.h"
#include "diag_sampleDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CAboutDlg dialog used for App About


class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);

// DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()

JERRY CHACKO

UR11CS042

// Cdiag_sampleDlg dialog

Cdiag_sampleDlg::Cdiag_sampleDlg(CWnd* pParent /*=NULL*/)


: CDialogEx(Cdiag_sampleDlg::IDD, pParent)
, m_var(0)
, ch(0)
, temp(0)
, m_s(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cdiag_sampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_var);
DDX_Text(pDX, IDC_EDIT2, m_s);
}
BEGIN_MESSAGE_MAP(Cdiag_sampleDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_1, &Cdiag_sampleDlg::On_1)
ON_BN_CLICKED(IDC_2, &Cdiag_sampleDlg::On_2)
ON_BN_CLICKED(IDC_3, &Cdiag_sampleDlg::On_3)
ON_BN_CLICKED(IDC_4, &Cdiag_sampleDlg::On_4)
ON_BN_CLICKED(IDC_5, &Cdiag_sampleDlg::On_5)
ON_BN_CLICKED(IDC_6, &Cdiag_sampleDlg::On_6)
ON_BN_CLICKED(IDC_7, &Cdiag_sampleDlg::On_7)
ON_BN_CLICKED(IDC_8, &Cdiag_sampleDlg::On_8)
ON_BN_CLICKED(IDC_9, &Cdiag_sampleDlg::On_9)
ON_BN_CLICKED(IDC_0, &Cdiag_sampleDlg::On_0)
ON_BN_CLICKED(IDC_equals, &Cdiag_sampleDlg::On_equals)
//
ON_BN_CLICKED(IDC_plus, &Cdiag_sampleDlg::On_plus)
ON_BN_CLICKED(IDC_minus, &Cdiag_sampleDlg::On_minus)
ON_BN_CLICKED(IDC_multiply, &Cdiag_sampleDlg::On_multiply)
ON_BN_CLICKED(IDC_divide, &Cdiag_sampleDlg::On_divide)
ON_BN_CLICKED(IDC_plus, &Cdiag_sampleDlg::On_plus)
END_MESSAGE_MAP()

JERRY CHACKO

UR11CS042

// Cdiag_sampleDlg message handlers


BOOL Cdiag_sampleDlg::OnInitDialog()
{
CDialogEx::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)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
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 Cdiag_sampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{

JERRY CHACKO

UR11CS042

CDialogEx::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 Cdiag_sampleDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<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
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR Cdiag_sampleDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

void Cdiag_sampleDlg::On_1()
{
// TODO: Add your control notification handler code here

JERRY CHACKO

UR11CS042

UpdateData(true);
m_var=m_var*10+1;
m_s=m_s+'1';
UpdateData(false);
}

void Cdiag_sampleDlg::On_2()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+2;
m_s=m_s+'2';
UpdateData(false);
}

void Cdiag_sampleDlg::On_3()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+3;
m_s=m_s+'3';
UpdateData(false);
}

void Cdiag_sampleDlg::On_4()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+4;
m_s=m_s+'4';
UpdateData(false);
}

void Cdiag_sampleDlg::On_5()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+5;
m_s=m_s+'5';
UpdateData(false);
}

JERRY CHACKO

UR11CS042

void Cdiag_sampleDlg::On_6()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+6;
m_s=m_s+'6';
UpdateData(false);
}

void Cdiag_sampleDlg::On_7()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+7;
m_s=m_s+'7';
UpdateData(false);
}

void Cdiag_sampleDlg::On_8()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+8;
m_s=m_s+'8';
UpdateData(false);
}

void Cdiag_sampleDlg::On_9()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+9;
m_s=m_s+'9';
UpdateData(false);
}

void Cdiag_sampleDlg::On_0()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_var=m_var*10+0;

JERRY CHACKO

UR11CS042

m_s=m_s+'0';
UpdateData(false);
}
void Cdiag_sampleDlg::On_plus()
{
// TODO: Add your control notification handler code here
UpdateData(true);
temp=m_var;
m_var=0;
m_s=m_s+'+';
ch=1;
UpdateData(false);
}
void Cdiag_sampleDlg::On_minus()
{
// TODO: Add your control notification handler code here
UpdateData(true);
temp=m_var;
m_var=0;
m_s=m_s+'-';
ch=2;
UpdateData(false);
}

void Cdiag_sampleDlg::On_multiply()
{
// TODO: Add your control notification handler code here
UpdateData(true);
temp=m_var;
m_var=0;
m_s=m_s+'*';
ch=3;
UpdateData(false);
}

void Cdiag_sampleDlg::On_divide()
{
// TODO: Add your control notification handler code here
UpdateData(true);
temp=m_var;
m_var=0;
m_s=m_s+'/';
ch=4;

JERRY CHACKO

UR11CS042

UpdateData(false);
}
void Cdiag_sampleDlg::On_equals()
{
// TODO: Add your control notification handler code here
UpdateData(true);
switch(ch)
{
case 1:
m_var=temp+m_var;
m_s="";
break;
case 2:
m_var=temp-m_var;
m_s="";
break;
case 3:
m_var=temp*m_var;
m_s="";
break;
case 4:
m_var=temp/m_var;
m_s="";
break;
}
//m_var=0;
UpdateData(false);
}

//void Cdiag_sampleDlg::On_plus()
//{
//
// TODO: Add your control notification handler code here
//
UpdateData(true);
//
temp=m_var;
//
m_var=0;
//
ch=1;
//
UpdateData(false);
//}

JERRY CHACKO

UR11CS042

Você também pode gostar