Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

CatchCulator

, 18 Oct 2005 CPOL
A tool used to catch and combine values output by different applications.
catchculator_demo.zip
TestValues2.exe
TestValues1.exe
CatchCulator.exe
catchculator_sourcecode.zip
CatchCulator.clw
CatchCulator.dsp
CatchCulator.dsw
res
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
bmp00003.bmp
bmp00004.bmp
bmp00005.bmp
bmp00006.bmp
bmp00007.bmp
bmp00008.bmp
bmp00009.bmp
bmp00010.bmp
CatchCulator.ico
catchd1.bmp
catchu1.bmp
catchu2.bmp
catchu3.bmp
d1u1.bmp
d1u2.bmp
d1u3.bmp
d2u1.bmp
d2u2.bmp
d2u3.bmp
d3u1.bmp
d3u2.bmp
d3u3.bmp
delitemu.bmp
delu1.bmp
delu2.bmp
delu3.bmp
display_1.bmp
display_2.bmp
display_3.bmp
grad.bmp
settimer.bmp
timerset.bmp
timeru2.bmp
timeru3.bmp
// Author: Dr. Mircea Puiu
// Created on: October 2005 for CodeProject
//
// CatchCulatorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CatchCulator.h"
#include "CatchCulatorDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCatchCulatorDlg dialog

CCatchCulatorDlg::CCatchCulatorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCatchCulatorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCatchCulatorDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_colorBkGnd = RGB(186, 198, 179);
	m_brushBkGnd.CreateSolidBrush(m_colorBkGnd);
	m_nTimerValue = 100; // msec
}

void CCatchCulatorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCatchCulatorDlg)
	DDX_Control(pDX, IDC_STATIC_DISPLAY3, m_display3);
	DDX_Control(pDX, IDC_STATIC_DISPLAY2, m_display2);
	DDX_Control(pDX, IDC_STATIC_DISPLAY1, m_display1);
	DDX_Control(pDX, IDC_TREE_CATCHES, m_treeCatches);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCatchCulatorDlg, CDialog)
	//{{AFX_MSG_MAP(CCatchCulatorDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SHOWWINDOW()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON_SHOW_CATCHER, OnButtonShowCatcher)
	ON_NOTIFY(TVN_ENDLABELEDIT, IDC_TREE_CATCHES, OnEndlabeleditTreeCatches)
	ON_BN_CLICKED(IDC_BUTTON_SHOW_D1, OnButtonShowD1)
	ON_BN_CLICKED(IDC_BUTTON_SHOW_D2, OnButtonShowD2)
	ON_BN_CLICKED(IDC_BUTTON_SHOW_D3, OnButtonShowD3)
	ON_BN_CLICKED(IDC_BUTTON_DEL_TREE, OnButtonDelTree)
	ON_BN_CLICKED(IDC_BUTTON_DEL_ITEM, OnButtonDelItem)
	ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_TREE_CATCHES, OnBeginlabeleditTreeCatches)
	ON_BN_CLICKED(IDC_BUTTON_TIMER, OnButtonTimer)
	ON_BN_CLICKED(IDC_BUTTON_SET_TIMER, OnButtonSetTimer)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCatchCulatorDlg message handlers

BOOL CCatchCulatorDlg::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

	// Load the bitmaps for the buttons
	m_buttonShowCatcher.AutoLoad(IDC_BUTTON_SHOW_CATCHER,	this);
	m_buttonDisplay1.	AutoLoad(IDC_BUTTON_SHOW_D1,		this);
	m_buttonDisplay2.	AutoLoad(IDC_BUTTON_SHOW_D2,		this);
	m_buttonDisplay3.	AutoLoad(IDC_BUTTON_SHOW_D3,		this);
	m_buttonDelTree.	AutoLoad(IDC_BUTTON_DEL_TREE,		this);
	m_buttonDelItem.	AutoLoad(IDC_BUTTON_DEL_ITEM,		this);
	m_buttonTimer.		AutoLoad(IDC_BUTTON_TIMER,			this);
	m_buttonSetTimer.	AutoLoad(IDC_BUTTON_SET_TIMER,		this);

	// Disable controls
	m_bByTimer = false;
	m_buttonSetTimer.EnableWindow(FALSE);

	// Set the IDs for the displays and scripts
	m_display1.ID = 1;	m_display1.m_dlgScript.m_nID = 1;
	m_display2.ID = 2;	m_display2.m_dlgScript.m_nID = 2;
	m_display3.ID = 3;	m_display3.m_dlgScript.m_nID = 3;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CCatchCulatorDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	dlgCatch.Create(IDD_DIALOG_SELECTOR);
}

HBRUSH CCatchCulatorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if ( nCtlColor != CTLCOLOR_EDIT)
	{
		hbr = (HBRUSH)m_brushBkGnd.GetSafeHandle();
		pDC->SetBkColor(m_colorBkGnd);
	}
	return hbr;
}

void CCatchCulatorDlg::OnButtonShowCatcher() 
{
	// TODO: Show the catcher modeless dialog
	dlgCatch.ShowWindow(SW_SHOW);
}

void CCatchCulatorDlg::OnBeginlabeleditTreeCatches(NMHDR* pNMHDR, LRESULT* pResult) 
{
	TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
	// TODO: Add your control notification handler code here
	m_strModifiedName = pTVDispInfo->item.pszText;
	m_strModifiedName.TrimLeft();
	m_strModifiedName.TrimRight();
	
	*pResult = 0;
}

void CCatchCulatorDlg::OnEndlabeleditTreeCatches(NMHDR* pNMHDR, LRESULT* pResult) 
{
	TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
	// TODO: Add your control notification handler code here
	CString strName = pTVDispInfo->item.pszText;
	// Cut the blanks at left and right, if any
	strName.TrimLeft();
	strName.TrimRight();
	// Set the tree item
	m_treeCatches.SetItemText(pTVDispInfo->item.hItem, strName.GetBuffer(0));
	// Modify the scripts
	ModifyNameInScript(&m_display1, m_strModifiedName, strName);
	ModifyNameInScript(&m_display2, m_strModifiedName, strName);
	ModifyNameInScript(&m_display3, m_strModifiedName, strName);
	// Update the script computation schemas
	m_display1.m_dlgScript.UpdateScript();
	m_display2.m_dlgScript.UpdateScript();
	m_display3.m_dlgScript.UpdateScript();
	// Update the displays
	OnButtonShowD1();
	OnButtonShowD2();
	OnButtonShowD3();
	
	*pResult = 0;
}

int CCatchCulatorDlg::GetOperationID(char *op)
{
	int			opID = -1;
	CString		strOp = op;

	if ( strOp == "+" ) opID = 1;
	else if ( strOp == "-" ) opID = 2;
	else if ( strOp == "*" ) opID = 3;
	else if ( strOp == "/" ) opID = 4;
	return opID;
}

void CCatchCulatorDlg::ProcessScript(CStaticDisplay *pDisplay)
{
	//Update (*pDisplay) according to the m_listToDo in the script dialog
	POSITION		pos, posCrt;
	Calculation		CL;
	CString			strType, strOperand;
	char			chValue[256];
	double			dV1, dV2;
	int				opID, varType;

	if ( pDisplay->m_dlgScript.m_listToDo.IsEmpty() )
	{
		// Nothing to display
		pDisplay->m_strDisplay = "";
		pDisplay->Invalidate(FALSE);
		return;
	}
	pos = pDisplay->m_dlgScript.m_listToDo.GetHeadPosition();
	// Do the computations according to the script (the m_listToDo)
	while ( pos )
	{
		posCrt = pos;
		CL = pDisplay->m_dlgScript.m_listToDo.GetNext(pos);
		// Left operand
		dV1 = 0.0;
		varType = -1;
		strType = CL.opL.Left(1);
		if ( strType == "1" ) varType = 1; // monitored variable
		else if ( strType == "2" ) varType = 2; // computed variable
		else if ( strType == "3" ) varType = 3; // constant
		strOperand = CL.opL.Right(CL.opL.GetLength() - 2);
		switch ( varType )
		{
			case 1:	// monitored variable
				dV1 = ValueOf(strOperand.GetBuffer(0));
				break;
			case 2:	// computed variable
				dV1 = pDisplay->m_dlgScript.ComputedValue(strOperand.GetBuffer(0));
				break;
			case 3:	// constant
				if ( strOperand.GetLength() > 255 ) strncpy(chValue, strOperand.GetBuffer(0), 255);
				else strcpy(chValue, strOperand.GetBuffer(0));
				sscanf(chValue, "%lf", &dV1);
				break;
		}
		// Right operand
		dV2 = 0.0;
		varType = -1;
		strType = CL.opR.Left(1);
		if ( strType == "1" ) varType = 1; // monitored variable
		else if ( strType == "2" ) varType = 2; // computed variable
		else if ( strType == "3" ) varType = 3; // constant
		strOperand = CL.opR.Right(CL.opR.GetLength() - 2);
		switch ( varType )
		{
			case 1:	// monitored variable
				dV2 = ValueOf(strOperand.GetBuffer(0));
				break;
			case 2:	// computed variable
				dV2 = pDisplay->m_dlgScript.ComputedValue(strOperand.GetBuffer(0));
				break;
			case 3:	// constant
				if ( strOperand.GetLength() > 255 ) strncpy(chValue, strOperand.GetBuffer(0), 255);
				else strcpy(chValue, strOperand.GetBuffer(0));
				sscanf(chValue, "%lf", &dV2);
				break;
		}
		// Perform the calculation
		opID = GetOperationID(CL.operation.GetBuffer(0));
		switch ( opID )
		{
			case 1: CL.result = dV1 + dV2;	break; // +
			case 2:	CL.result = dV1 - dV2;	break; // -
			case 3:	CL.result = dV1 * dV2;	break; // *
			case 4:	//								  /
				if ( dV2 == 0 )
				{
					// Division by 0
					pDisplay->m_strDisplay = "Division by 0";
					pDisplay->Invalidate(FALSE);
					return;
				}
				CL.result = dV1 / dV2;
				break;
		}
		// Update the sub-result
		pDisplay->m_dlgScript.m_listToDo.SetAt(posCrt, CL);
	} // next pos in list
	// Show the result
	CL = pDisplay->m_dlgScript.m_listToDo.GetTail();
	sprintf(chValue, pDisplay->m_strDisplayFormat.GetBuffer(0), CL.result);
	pDisplay->m_strDisplay = chValue;
	pDisplay->Invalidate(FALSE);
}

void CCatchCulatorDlg::OnButtonShowD1() 
{
	// TODO: Update display 1 according to the m_listToDo in the script dialog
	ProcessScript(&m_display1);
}

void CCatchCulatorDlg::OnButtonShowD2() 
{
	// TODO: Update display 2 according to the m_listToDo in the script dialog
	ProcessScript(&m_display2);
}

void CCatchCulatorDlg::OnButtonShowD3() 
{
	// TODO: Update display 3 according to the m_listToDo in the script dialog
	ProcessScript(&m_display3);
}

double CCatchCulatorDlg::ValueOf(char *varName)
{
	double		result = 0.0;
	HTREEITEM	hItem;
	CString		strItem, strName = varName;
	HWND		hWnd;
	CEdit		*pEdit;
	char		chValue[256];
	int			N;

	// Lool for [varName] in m_treeCatches
	if ( m_treeCatches.GetCount() < 1 ) return result;
	// Cut the blanks at left and right, if any
	strName.TrimLeft();
	strName.TrimRight();
	// Go through the tree
	hItem = m_treeCatches.GetRootItem();
	if ( !hItem ) return result;
	while ( hItem )
	{
		strItem = m_treeCatches.GetItemText(hItem);
		if ( strItem == strName )
		{
			hWnd = (HWND) m_treeCatches.GetItemData(hItem);
			if ( ::IsWindow(hWnd) )
			{
				N = ::GetWindowText(hWnd, chValue, 255);
				chValue[N] = 0; // make sure it's a null-terminated string
				strItem = chValue;
				if ( strItem == "" )
				{
					// This may be a CEdit control, so try to get its first line
					pEdit = (CEdit *)FromHandle(hWnd);
					N = pEdit->GetLine(0, chValue, 255);
					chValue[N] = 0; // null termination
				}
			}
			sscanf(chValue, "%lf", &result);
			break;
		}
		// Go to the next item in the tree
		hItem = m_treeCatches.GetNextItem(hItem, TVGN_NEXT);
	}
	return result;
}

HTREEITEM CCatchCulatorDlg::FindVariable(char *varName)
{
	// Return the HTREEITEM of [varName] or NULL if not found
	HTREEITEM	hItem = NULL;
	CString		strItem, strName = varName;
	
	if ( m_treeCatches.GetCount() < 1 ) return hItem;
	// Cut the blanks at left and right, if any
	strName.TrimLeft();
	strName.TrimRight();
	// Go through the tree
	hItem = m_treeCatches.GetRootItem();
	if ( !hItem ) return hItem;
	while ( hItem )
	{
		strItem = m_treeCatches.GetItemText(hItem);
		if ( strItem == strName ) break;
		hItem = m_treeCatches.GetNextItem(hItem, TVGN_NEXT);
	}
	return hItem;
}

void CCatchCulatorDlg::OnButtonDelTree() 
{
	// Delete the tree
	m_treeCatches.DeleteAllItems();

	// Delete the scripts
	m_display1.m_dlgScript.m_script.SetWindowText("");
		if ( !m_display1.m_dlgScript.m_listToDo.IsEmpty() ) m_display1.m_dlgScript.m_listToDo.RemoveAll();
	m_display2.m_dlgScript.m_script.SetWindowText("");
		if ( !m_display2.m_dlgScript.m_listToDo.IsEmpty() ) m_display2.m_dlgScript.m_listToDo.RemoveAll();
	m_display3.m_dlgScript.m_script.SetWindowText("");
		if ( !m_display3.m_dlgScript.m_listToDo.IsEmpty() ) m_display3.m_dlgScript.m_listToDo.RemoveAll();
	
	// Clear the display
	m_display1.m_strDisplay = "";
	m_display1.Invalidate(FALSE);
	m_display2.m_strDisplay = "";
	m_display2.Invalidate(FALSE);
	m_display3.m_strDisplay = "";
	m_display3.Invalidate(FALSE);
}

void CCatchCulatorDlg::RemoveScriptLinesFor(CStaticDisplay *pDisplay, CString &strSel)
{
	CString		strEdit, strL, strR, strCrLf;
	int			posString, posNext, L, posCrLf1, posCrLf2;
	char		chSeparators[] = "   +-*/";
	bool		isName, bScriptWasModified = false;

	chSeparators[0] = 13;
	chSeparators[1] = 10;
	chSeparators[2] = 0;	strCrLf = chSeparators;
	chSeparators[2] = ' ';
	pDisplay->m_dlgScript.m_script.GetWindowText(strEdit);
	strSel.TrimLeft();
	strSel.TrimRight();
	L = strSel.GetLength();
	if ( L < 1 ) return;
	posString = strEdit.Find(strSel.GetBuffer(0));
	while ( posString != -1)
	{
		isName = false;
		posNext = posString + L;
		// Look for the side characters
		strL = strEdit.Mid(posString - 1, 1);
		strR = strEdit.Mid(posNext, 1);
		if ( (strL == "") || (strL.FindOneOf(chSeparators) != -1) ) isName = true;
		if ( (strR != "") && (strR.FindOneOf(chSeparators) == -1) ) isName = false;
		if ( isName )
		{
			bScriptWasModified = true;
			// Delete the substring starting with CrLf (up to next CrLf)
			strL = strEdit.Left(posString);
			posCrLf1 = strL.ReverseFind(13);
			if ( posCrLf1 == -1 ) posCrLf1 = 0;
			strR = strEdit.Right(strEdit.GetLength() - posNext);
			posCrLf2 = strEdit.Find(13, posNext) - 1;
			if ( posCrLf2 < 0 ) posCrLf2 = strEdit.GetLength() - 1;
			strEdit.Delete(posCrLf1, posCrLf2 - posCrLf1 + 1);
			// Get the next string position
			posString = strEdit.Find(strSel.GetBuffer(0));
		}
		else
		{
			// Get the next string position
			posString = strEdit.Find(strSel.GetBuffer(0), posNext);
		}
	}
	// Remove any starting CrLf's
	L = strEdit.GetLength();
	if ( L > 0 )
	{
		strL = strEdit.Left(2);
		while ( strL == strCrLf )
		{
			L = strEdit.GetLength();
			strEdit = strEdit.Right(L - 2);
			strL = strEdit.Left(2);
		}
	}
	// Update the script dialog and the corresponding display
	pDisplay->m_dlgScript.m_script.SetWindowText(strEdit.GetBuffer(0));
	if ( bScriptWasModified )
	{
		pDisplay->m_strDisplay = "The script was modified";
		pDisplay->Invalidate(FALSE);
	}
	pDisplay->m_dlgScript.UpdateScript();
}

void CCatchCulatorDlg::OnButtonDelItem() 
{
	HTREEITEM	hSel;
	CString		strSel;

	if ( m_treeCatches.GetCount() < 1 ) return;

	// Get item text
	hSel = m_treeCatches.GetSelectedItem();
	if ( !hSel ) return;
	strSel = m_treeCatches.GetItemText(hSel);

	// Remove the tree item
	m_treeCatches.DeleteItem(hSel);

	// Remove all lines in script 1 containg this item text
	RemoveScriptLinesFor(&m_display1, strSel);

	// Remove all lines in script 2 containg this item text
	RemoveScriptLinesFor(&m_display2, strSel);

	// Remove all lines in script 3 containg this item text
	RemoveScriptLinesFor(&m_display3, strSel);
}

void CCatchCulatorDlg::ModifyNameInScript(CStaticDisplay *pDisplay, CString strOld, CString strNew)
{
	CString		strEdit, strL, strR;
	int			posString, posNext, L;
	char		chSeparators[] = "   +-*/";
	bool		isName;

	chSeparators[0] = 13;
	chSeparators[1] = 10;
	pDisplay->m_dlgScript.m_script.GetWindowText(strEdit);
	strOld.TrimLeft();
	strOld.TrimRight();
	L = strOld.GetLength();
	if ( L < 1 ) return;
	if ( strNew == "" ) strNew = "NoName";
	posString = strEdit.Find(strOld.GetBuffer(0));
	while ( posString != -1)
	{
		isName = false;
		posNext = posString + L;
		// Look for the side characters
		strL = strEdit.Mid(posString - 1, 1);
		strR = strEdit.Mid(posNext, 1);
		if ( (strL == "") || (strL.FindOneOf(chSeparators) != -1) ) isName = true;
		if ( (strR != "") && (strR.FindOneOf(chSeparators) == -1) ) isName = false;
		if ( isName )
		{
			// Replace the substring
			strL = strEdit.Left(posString);
			strR = strEdit.Right(strEdit.GetLength() - posString - L);
			strEdit = strL;
			strEdit += strNew;
			strEdit += strR;
			// Get the next string position
			posString = strEdit.Find(strOld.GetBuffer(0), posString + strNew.GetLength());
		}
		else
		{
			// Get the next string position
			posString = strEdit.Find(strOld.GetBuffer(0), posNext);
		}
	}
	// Update the script dialog
	pDisplay->m_dlgScript.m_script.SetWindowText(strEdit.GetBuffer(0));
}

void CCatchCulatorDlg::UpdateDisplay(int ID)
{
	switch ( ID )
	{
		case 1: OnButtonShowD1();	break;
		case 2: OnButtonShowD2();	break;
		case 3: OnButtonShowD3();	break;
	}
}

void CCatchCulatorDlg::OnButtonTimer() 
{
	// TODO: Toggle "Timer / Click" mode
	if ( m_bByTimer )
	{
		m_bByTimer = false;
		// Go to "Click" mode
		m_buttonDisplay1.EnableWindow(TRUE);
		m_buttonDisplay2.EnableWindow(TRUE);
		m_buttonDisplay3.EnableWindow(TRUE);
		m_buttonSetTimer.EnableWindow(FALSE);
		KillTimer(1);
	}
	else
	{
		m_bByTimer = true;
		// Go to "Timer" mode
		m_buttonDisplay1.EnableWindow(FALSE);
		m_buttonDisplay2.EnableWindow(FALSE);
		m_buttonDisplay3.EnableWindow(FALSE);
		m_buttonSetTimer.EnableWindow(TRUE);
		SetTimer(1, m_nTimerValue, NULL);
	}
}

void CCatchCulatorDlg::OnButtonSetTimer() 
{
	// TODO: Set the timer for the "Timer" mode
	CSetTimerDlg	dlg;

	switch ( m_nTimerValue )
	{
		case 1:		dlg.m_nValueIndex = 0;	break;
		case 5:		dlg.m_nValueIndex = 1;	break;
		case 10:	dlg.m_nValueIndex = 2;	break;
		case 20:	dlg.m_nValueIndex = 3;	break;
		case 50:	dlg.m_nValueIndex = 4;	break;
		case 100:	dlg.m_nValueIndex = 5;	break;
		case 200:	dlg.m_nValueIndex = 6;	break;
		case 500:	dlg.m_nValueIndex = 7;	break;
		case 1000:	dlg.m_nValueIndex = 8;	break;
		default:	dlg.m_nValueIndex = 5;
	}
	if ( dlg.DoModal() == IDOK )
	{
		KillTimer(1);
		m_nTimerValue = dlg.m_nValueIndex;
		switch ( dlg.m_nValueIndex )
		{
			case 0:		m_nTimerValue = 1;		break;
			case 1:		m_nTimerValue = 5;		break;
			case 2:		m_nTimerValue = 10;		break;
			case 3:		m_nTimerValue = 20;		break;
			case 4:		m_nTimerValue = 50;		break;
			case 5:		m_nTimerValue = 100;	break;
			case 6:		m_nTimerValue = 200;	break;
			case 7:		m_nTimerValue = 500;	break;
			case 8:		m_nTimerValue = 1000;	break;
			default:	m_nTimerValue = 100;
		}
		SetTimer(1, m_nTimerValue, NULL);
	}
}

void CCatchCulatorDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	switch ( nIDEvent )
	{
		case 1:
			// Automatic calculation
			OnButtonShowD1();
			OnButtonShowD2();
			OnButtonShowD3();
			break;
	}
	
	CDialog::OnTimer(nIDEvent);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mircea Puiu
Software Developer (Senior)
Europe Europe
More than 22 years of software development experience.
SCRUM Master nowadays

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 18 Oct 2005
Article Copyright 2005 by Mircea Puiu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid