Tutorial de un Contador en Visual Studio

13
Disque tutorial para el contador Paso 1 Primero que nada quitas el todo esa cosa fea Luego agregas un botón, te debe de quedar así : Paso 2 Luego te metes al dlg.h Para agregar 2 variables, son las de la foto

description

Tutorial de un Contador en Visual Studio 2015Programacion avanzada.

Transcript of Tutorial de un Contador en Visual Studio

Page 1: Tutorial de un Contador en Visual Studio

Disque tutorial para el contador

Paso 1

Primero que nada quitas el todo esa cosa fea

Luego agregas un botón, te debe de quedar así :

Paso 2

Luego te metes al dlg.h

Para agregar 2 variables, son las de la foto

Page 2: Tutorial de un Contador en Visual Studio

public:

int m_conteo;

int m_num;

paso 3

agregas el timer,

nadamas sigue los pasos de estas fotos:

Page 3: Tutorial de un Contador en Visual Studio

Le picas al botoncillo ese que le puse la flecha amarilla luego pues te sale el menú ese de la siguiente foto, buscas el que dice WM_TIMER le picas a su caja, y le picas en add ontimer (así decía, pero pues es que en la foto pues ya se lo puse)

Page 4: Tutorial de un Contador en Visual Studio

Luego ya te vas al archivo de .cpp

Y en ese borras todo el código y copias el código siguiente, (si tu programa tiene otro nombre, asegúrate de cambiar el MFCApplication3 por el nombre de tu archivo, cambiarlo en todas las partes del código donde lo veas, para que funcione bien tú código

// MFCApplication3Dlg.cpp : implementation file

//

#include "stdafx.h"

#include "MFCApplication3.h"

Page 5: Tutorial de un Contador en Visual Studio

#include "MFCApplication3Dlg.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)

{

}

Page 6: Tutorial de un Contador en Visual Studio

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialogEx::DoDataExchange(pDX);

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)

END_MESSAGE_MAP()

// CMFCApplication3Dlg dialog

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

: CDialogEx(CMFCApplication3Dlg::IDD, pParent)

, m_conteo(0)

, m_num(0)

{

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CMFCApplication3Dlg::DoDataExchange(CDataExchange* pDX)

{

CDialogEx::DoDataExchange(pDX);

}

BEGIN_MESSAGE_MAP(CMFCApplication3Dlg, CDialogEx)

ON_WM_SYSCOMMAND()

Page 7: Tutorial de un Contador en Visual Studio

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication3Dlg::OnBnClickedButton1)

ON_WM_TIMER()

END_MESSAGE_MAP()

// CMFCApplication3Dlg message handlers

BOOL CMFCApplication3Dlg::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())

Page 8: Tutorial de un Contador en Visual Studio

{

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 CMFCApplication3Dlg::OnSysCommand(UINT nID, LPARAM lParam)

{

if ((nID & 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialogEx::OnSysCommand(nID, lParam);

}

}

Page 9: Tutorial de un Contador en Visual Studio

// 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 CMFCApplication3Dlg::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();

}

}

Page 10: Tutorial de un Contador en Visual Studio

// The system calls this function to obtain the cursor to display while the user drags

// the minimized window.

HCURSOR CMFCApplication3Dlg::OnQueryDragIcon()

{

return static_cast<HCURSOR>(m_hIcon);

}

void CMFCApplication3Dlg::OnBnClickedButton1()

{

// TODO: Add your control notification handler code here

SetTimer(1,1000,0);

}

void CMFCApplication3Dlg::OnTimer(UINT_PTR nIDEvent)

{

// TODO: Add your message handler code here and/or call default

int color [10][28]= {

{1,1,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1},//0

{0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1},//1

{1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1},//2

{1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1},//3

{1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1},//4

{1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1},//5

Page 11: Tutorial de un Contador en Visual Studio

{1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1},//6

{1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1},//7

{1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1},//8

{1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1},//9

};

CClientDC pDC(this);

pDC.TextOutW(200,30,_T("DISPLAY"));

CBrush brocha1(RGB(0,0,0));

CBrush*oldbrush=pDC.SelectObject(&brocha1);

pDC.Rectangle(200,50,350,275);

pDC.SelectObject(oldbrush);

//DRAWING CIRCLES

int x =220, y=60;

int i=0;

while (y<270)

{

while (x<335)

{

int val =color[m_conteo] [i]*255;

CBrush brocha2(RGB(val,val,0));

CBrush*oldbrush2=pDC.SelectObject(&brocha2);

pDC.Ellipse(x,y,x + 15, y +15);

++i;

x+=30;

}

x=220;

Page 12: Tutorial de un Contador en Visual Studio

y+=30;

}

++m_conteo;

if (m_conteo>9)

m_conteo=0;

m_num = m_conteo;

UpdateData (false);

CDialogEx::OnTimer(nIDEvent);

}