making two timers

February 18, 2009 at 00:30:48
Specs: Windows XP
--------------------Configuration: basic modem - Win32 Debug--------------------
Compiling...
basic modemDlg.cpp
C:\Documents and Settings\Alfa Romeo\Desktop\rehan_psmTesting\Copy of rehan_testing-18.2\basic modem\basic modemDlg.cpp(382) : error C2043: illegal break
C:\Documents and Settings\Alfa Romeo\Desktop\rehan_psmTesting\Copy of rehan_testing-18.2\basic modem\basic modemDlg.cpp(386) : error C2046: illegal case
C:\Documents and Settings\Alfa Romeo\Desktop\rehan_psmTesting\Copy of rehan_testing-18.2\basic modem\basic modemDlg.cpp(402) : error C2043: illegal break
Error executing cl.exe.

basic modem.exe - 3 error(s), 0 warning(s)


when i run my program...there are several errors...can you all check my program?this is basic modem program that use two timers..the secong timer will start counting after several function.Here are the coding:


// basic modemDlg.cpp : implementation file
//

#include "stdafx.h"
#include "basic modem.h"
#include "basic modemDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int count = 0;
int count2 = 0;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CBasicmodemDlg dialog

CBasicmodemDlg::CBasicmodemDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBasicmodemDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBasicmodemDlg)
m_command = _T("");
m_tx = _T("");
m_rx = _T("");
m_sCount = _T("");
m_callsign = _T("");
m_sCount2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBasicmodemDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBasicmodemDlg)
DDX_Text(pDX, IDC_EDIT1, m_command);
DDX_Text(pDX, IDC_EDIT2, m_tx);
DDX_Text(pDX, IDC_EDIT3, m_rx);
DDX_Control(pDX, IDC_MSCOMM1, m_mscomm);
DDX_Text(pDX, IDC_STATICCOUNT, m_sCount);
DDX_Control(pDX, IDC_INET1, m_inet);
DDX_Text(pDX, IDC_callsign, m_callsign);
DDX_Text(pDX, IDC_COUNT2, m_sCount2);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBasicmodemDlg, CDialog)
//{{AFX_MSG_MAP(CBasicmodemDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnEnter)
ON_BN_CLICKED(IDC_BUTTON2, OnSend)
ON_BN_CLICKED(IDC_BUTTON5, OnUnlink)
ON_BN_CLICKED(IDC_BUTTON4, OnClear)
ON_BN_CLICKED(IDC_BUTTON3, OnClose)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON6, Ontest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBasicmodemDlg message handlers

BOOL CBasicmodemDlg::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
m_mscomm.SetCommPort (1);
m_mscomm.SetSettings ("9600,n,8,1");
m_mscomm.SetPortOpen (TRUE);

//display
m_sCount.Format("%d", count);

m_callsign = "9MUTMX01";

//Update dialog
UpdateData(FALSE);

//start timer
SetTimer (ID_COUNT_TIMER, 1000, NULL);


//////////////////////////////
///MY CODE ENDS HERE
//////////////////////////////



return TRUE; // return TRUE unless you set the focus to a control
}

void CBasicmodemDlg::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 CBasicmodemDlg::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 CBasicmodemDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CBasicmodemDlg::OnEnter()
{
UpdateData();

CString data;
data = m_command;
m_mscomm.SetOutput(COleVariant(data));

data = 13;
m_mscomm.SetOutput(COleVariant(data));
m_command = "";
UpdateData(FALSE);
}

void CBasicmodemDlg::OnSend()
{

UpdateData();

CString data;
transmit();
data = m_tx;
m_mscomm.SetOutput(COleVariant(data));
data = 13;
m_mscomm.SetOutput(COleVariant(data));
receive();
m_tx = "";
UpdateData(FALSE);

}

void CBasicmodemDlg::transmit()
{
UpdateData();

CString data;

data = 3;
m_mscomm.SetOutput(COleVariant(data));
data = 84;
m_mscomm.SetOutput(COleVariant(data));
UpdateData(FALSE);

}

void CBasicmodemDlg::receive()
{
UpdateData();

CString data;

data = 3;
m_mscomm.SetOutput(COleVariant(data));
data = 69;
m_mscomm.SetOutput(COleVariant(data));

UpdateData(FALSE);
}


BEGIN_EVENTSINK_MAP(CBasicmodemDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CBasicmodemDlg)
ON_EVENT(CBasicmodemDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CBasicmodemDlg::OnOnCommMscomm1()
{

UpdateData();
CString data;
CString str;
COleVariant myVar;

myVar = m_mscomm.GetInput ();
data = myVar.bstrVal ;

m_rx = m_rx + data;


UpdateData(FALSE);
}

void CBasicmodemDlg::OnUnlink()
{

UpdateData();
CString data;

data = 3;
m_mscomm.SetOutput(COleVariant(data));
data = 88;
m_mscomm.SetOutput(COleVariant(data));

UpdateData(FALSE);
}

void CBasicmodemDlg::OnClear()
{

UpdateData();

m_rx = "";
UpdateData(FALSE);
}

void CBasicmodemDlg::OnClose()
{

OnOK();
}

void CBasicmodemDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

////////////////////////
///MY CODE START HERE
////////////////////////

//UpdateData(TRUE);

switch (nIDEvent)

//start the first timer
case ID_COUNT_TIMER:


//Increment the timer
count++;

//display
m_sCount.Format("%d", count);

//Update dialog
UpdateData(FALSE);

if (count == 10)
{
KillTimer(ID_COUNT_TIMER);

UpdateData(TRUE);


checkData();

//start second timer
SetTimer(ID_COUNT_TIMER2, 1000, NULL);

if (m_tx == "")
{
MessageBox ("No message from server");
}

else
{
linked();
}

}

break;


//the second timer
case ID_COUNT_TIMER2:


ID_COUNT_TIMER2;


//Increment the count
count2++;

//format the count
m_sCount2.Format("%d", count2);

//Update the dialog
UpdateData(FALSE);


break;

// count =0;

//start timer
//SetTimer (ID_COUNT_TIMER, 1000, NULL);

UpdateData(FALSE);

///////////////////////
/////MY CODE ENDS HERE
///////////////////////

CDialog::OnTimer(nIDEvent);
}

void CBasicmodemDlg::checkData()
{
UpdateData();

COleVariant sUrl="http://hfmail.fke.utm.my/msg/message";
COleVariant sType = "0"; //receive string
COleVariant sRcv;

sRcv = m_inet.OpenURL(sUrl,sType);
m_tx = sRcv.bstrVal;


UpdateData(FALSE);


//KillTimer(ID_COUNT_TIMER);

UpdateData();

return;
}

void CBasicmodemDlg::linked()
{
UpdateData();

CString data;
data = "pactor "+m_callsign;
m_mscomm.SetOutput(COleVariant(data));

data = 13;
m_mscomm.SetOutput(COleVariant(data));

UpdateData(FALSE);
}

void CBasicmodemDlg::Ontest()
{

UpdateData();

CString temp,temp1;

temp=m_rx.Right(11);
temp1=temp.Left(8);

MessageBox(temp1);


UpdateData(FALSE);
}

void CBasicmodemDlg::analysis()
{

UpdateData();

UpdateData(FALSE);
}


See More: making two timers

Report •


#1
February 18, 2009 at 02:54:13
You forgot the "{ . . . }" on your switch case in CBasicmodemDlg::OnTimer()

Report •

#2
February 19, 2009 at 16:45:55
thanks...after i edit it, the error had gone but it pop up a message box which inform that my program encountered a problem...what do you think is the problem?

Report •

Related Solutions


Ask Question