Click here to Skip to main content
15,891,372 members
Articles / Mobile Apps / Windows Mobile

RPN Dynamic Registration Model

Rate me:
Please Sign up or sign in to vote.
4.45/5 (5 votes)
5 Mar 2006CPOL5 min read 35.9K   165   14  
An article implementing RPN in a Pocket PC application.
// RPNSampleDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RPNSample.h"
#include "RPNSampleDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRPNSampleDlg dialog

CRPNSampleDlg::CRPNSampleDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRPNSampleDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRPNSampleDlg)
	m_strKey = _T("");
	m_strPPCId = _T("Sample");
	m_strRPN = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CRPNSampleDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRPNSampleDlg)
	DDX_Text(pDX, IDC_KEY, m_strKey);
	DDX_Text(pDX, IDC_PPC_ID, m_strPPCId);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRPNSampleDlg, CDialog)
	//{{AFX_MSG_MAP(CRPNSampleDlg)
	ON_BN_CLICKED(IDC_REGISTER_BUTTON, OnRegisterButton)
	ON_EN_CHANGE(IDC_PPC_ID, OnChangePpcId)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRPNSampleDlg message handlers

BOOL CRPNSampleDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

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



void CRPNSampleDlg::OnRegisterButton() 
{
UpdateData();
CString RegisterString;
RegisterString.Format(_T("%-.5d"),(int)(EvaluateRPN(m_strPPCId,111)));
if(	RegisterString.Find(m_strKey)==0)
{
	AfxMessageBox(_T("REGISTRATION CODE OK"));
}
else
{
	AfxMessageBox(_T("REGISTRATION FAILED"));

}
}



double CRPNSampleDlg::EvaluateRPN(CString RPN,double m_nVariant) 
{

	CString m_strRPN;
	double  m_nStringValue=0;
	int     StringPos=0;

	if(RPN.GetLength()>10)
	{
			m_strRPN=RPN.Left(5) + RPN.Right(5);
	}
	else m_strRPN=RPN;


	do
	{
		m_nStringValue += (double)m_strRPN.GetAt(StringPos);
		StringPos++;

	}while(StringPos <= m_strRPN.GetLength());


	m_nStringValue=m_nStringValue*5;  // c5*

	m_nStringValue+=m_nVariant;


	//  RPN = "i 0 == m_nVariant * key + c 5 * +" 


	return m_nStringValue;

}

void CRPNSampleDlg::OnChangePpcId() 
{
UpdateData();
m_strRPN.Format(_T("%-.5d"),(int)(EvaluateRPN(m_strPPCId,111)));
SetDlgItemText(IDC_RPN,m_strRPN);

}

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)


Written By
Software Developer
Canada Canada
I develop truck and automotive diagnostic software

Comments and Discussions