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

A comprehensive CE class library to replace ATL and MFC

, 4 Oct 2000 CPOL
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.
kgwince-old.zip
WinCe
BeamEx
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
Install
BeamEx.inf
BeamEx.ini
BeamEx.MIPS_PPCBW.CAB
BeamEx.MIPS_PPCColor.CAB
BeamEx.SH3_PPCColor.CAB
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeLib
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.old
CeLib.plg
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
dbView
bitmap1.bmp
bmp00001.bmp
db5.bmp
dbView.aps
DbView.dsp
dbView.dsw
dbView.old
dbView.plg
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
Install
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
mssccprj.scc
vssver.scc
ftpView
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
FtpView.old
ftpView.plg
FtpView.vcl
FtpView.vcp
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
Install
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
options.bmp
options1.bmp
seperato.bmp
vssver.scc
Setup
ico101.ico
Setup.aps
Setup.dsp
setup.ico
Setup.plg
WinCe.dsw
WinLib.dsw
kgwince.zip
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
BeamEx.vcl
BeamEx.vcp
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
BeamEx.inf
BeamEx.ini
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeFtp.vcp
CeFtp.vcw
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.plg
CeLib.vcl
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
bitmap1.bmp
bitmap2.bmp
bmp00001.bmp
db5.bmp
DbView.dsp
dbView.dsw
dbView.plg
DbView.vcl
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
menu1_5.bmp
mssccprj.scc
vssver.scc
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
ftpView.plg
FtpView.vcl
FtpView.vcp
FtpView.vcw
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
newmenu.bmp
options.bmp
options1.bmp
rcdata1.bin
seperato.bmp
toolbar1.bmp
vssver.scc
WinCe.dsw
WinCe.vcw
#include "StdAfx.h"
#include <commdlg.h>

#include "BeamExMain.h"
#include "BeamEx.h"

//#include "CeReg.h"

#include <afxres.h>
#include "resource.h"

#include "BeamExPages.h"

const TCHAR g_szScenarioDb[] = _T("BeamEx Scenarios");
const TCHAR g_szScenarioDef[] = _T("__Default__");

#if defined(_WIN32_WCE_POCKETPC)
	SHACTIVATEINFO s_saiDlgBox;
	SHACTIVATEINFO s_sai;
#endif


///////////////////////////////////////////////////////////////////////////////
//
// Short global functions
//
///////////////////////////////////////////////////////////////////////////////
HICON LoadSmall(HINSTANCE hInst, UINT nResID)
{
	return (HICON) ::LoadImage(hInst, MAKEINTRESOURCE(nResID), IMAGE_ICON, 16, 16, 0);
}

///////////////////////////////////////////////////////////////////////////////
//
//
///////////////////////////////////////////////////////////////////////////////

class CeOptionsDlg: public CeDialog
{
protected:
	virtual BOOL OnInitDialog()
	{
		CeString str;
		str.LoadString(IDS_OPTIONS, g_hInst);
		::SetDlgItemText(m_hWnd, IDC_OPTIONS, str);

		return CeDialog::OnInitDialog();
	}
};


///////////////////////////////////////////////////////////////////////////////
//
//
///////////////////////////////////////////////////////////////////////////////
BOOL CeScenarioListDlg::OnInitDialog()
{
#ifdef _WIN32_PPC_
	CeShowSip(TRUE);
#endif

	BOOL bRet = CeDialog::OnInitDialog();

	if (m_bSave)
	{
		SetWindowText(_T("Save Scenario As"));
	}
	else
	{
		SetWindowText(_T("Open Scenario"));
	}

	HWND hList = GetDlgItem(IDC_SCENARIO_LIST);

	// Setup the columns
	LVCOLUMN col;

	col.mask = LVCF_FMT | LVCF_TEXT; 
	col.fmt = LVCFMT_LEFT;
	col.pszText = _T("Scenario");
	ListView_InsertColumn(hList, 0, &col);

	CeDb db;
	if (! db.Open(g_szScenarioDb))
		return bRet;

	// Add materials
	LVITEM item;
	item.lParam = 0;

	CeDbRecord rec;
	CEOID oidRec = db.SeekFirst();
	for (int nRow = 0; 0 != oidRec; oidRec = db.SeekNext(), nRow++)
	{
		if (!db.ReadRec(rec))
			continue;

		CeString str;

		// Add scenarios
		rec.GetIdVal(BEAMSCENE_NAME, str);

		if (str == g_szScenarioDef)
			// skip default
			continue;

		item.mask     = LVIF_TEXT | LVIF_PARAM;
		item.iItem    = nRow;
		item.lParam   = rec.m_oid;
		item.iSubItem = 0;
		item.pszText  = (LPTSTR) (LPCTSTR) str;

		int nItem = ListView_InsertItem(hList, &item);
	}

	// Adjust the width so the second
	CeRect rc;
	::GetClientRect(hList, rc);
	ListView_SetColumnWidth(hList, 0, rc.Width());

	// LVS_EX_CHECKBOXES
	ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);

	int nItem = 0;
	if (! m_str.IsEmpty())
	{
		LVFINDINFO lvfi;
		lvfi.flags = LVFI_STRING;
		lvfi.psz = m_str;
		nItem = ListView_FindItem(hList, -1, &lvfi);
		if (nItem < 0)
			nItem = 0;
	}

	// select the new default
	ListView_SetItemState(hList, nItem, LVIS_SELECTED, LVIS_SELECTED);
	ListView_EnsureVisible(hList, nItem, FALSE);
	
#ifdef _WIN32_PPC_
	CeMoveOurWindowBasedOnSip(*this);
#endif

	return bRet;
}

BOOL CeScenarioListDlg::OnCommand(WPARAM wParam, LPARAM lParam, bool& bHandled)
{
	if (lParam && EN_CHANGE == HIWORD(wParam) && IDC_EDIT_SCENARIONAME == LOWORD(wParam))
	{
		HWND hList = GetDlgItem(IDC_SCENARIO_LIST);

		m_str.GetWindowText((HWND) lParam);
		int nItem = 0;
		if (! m_str.IsEmpty() && ! m_bChanging)
		{
			TRACE0("OnCommand: Edit Change\n");

			LVFINDINFO lvfi;
			lvfi.flags = LVFI_PARTIAL|LVFI_STRING;
			lvfi.psz = m_str;
			nItem = ListView_FindItem(hList, -1, &lvfi);
			if (nItem >= 0)
			{
				m_bChanging = true;
				// select the new default
				ListView_SetItemState(hList, nItem, LVIS_SELECTED, LVIS_SELECTED);
				ListView_EnsureVisible(hList, nItem, FALSE);
				m_bChanging = false;
			}
		}

		bHandled = true;
		return TRUE;
	}

	CeDialog::OnCommand(wParam, lParam, bHandled);
}


LRESULT CeScenarioListDlg::OnNotify(int nCtrlId, LPNMHDR pNMH, bool& bHandled)
{
	HWND hList = GetDlgItem(IDC_SCENARIO_LIST);

	if (IDC_SCENARIO_LIST == nCtrlId && ! m_bChanging)
	{
		//if (pNMH->code == NM_DBLCLK)
		//{
		//	OnOK();
		//	bHandled = true;
		//	return 0;
		//}
		//else
		if (pNMH->code == LVN_ITEMCHANGED)
		{
			// change the edit control values when selection changes
			NMLISTVIEW* pNMLV = (NMLISTVIEW*) pNMH;
			// populate the lower edit controls
			// when the selection changes
			if ((pNMLV->uChanged & LVIF_STATE) && (pNMLV->uNewState & LVIS_SELECTED))
			{
				TRACE0("OnNotify: List Item Changed\n");

				CeString str;
				ListView_GetItemText(hList, pNMLV->iItem, 0, str.GetBufferSetLength(64), 64);
				str.ReleaseBuffer();

				m_bChanging = true;
				SetDlgItemText(IDC_EDIT_SCENARIONAME, str);
				m_bChanging = false;
			}

			bHandled = true;
			return 0;
		}
	}
}

void CeScenarioListDlg::OnOK()
{
	HWND hList = GetDlgItem(IDC_SCENARIO_LIST);
	HWND hEdit = GetDlgItem(IDC_EDIT_SCENARIONAME);

	CeString str(hEdit);

	LVFINDINFO lvfi;
	lvfi.flags = LVFI_STRING;
	lvfi.psz = str;

	int nItem = ListView_FindItem(hList, -1, &lvfi);

	if (m_bSave)
	{
		// verify the edit control text is NOT selected in the list
		// to validate the existance of the scenario
		if (nItem >= 0)
		{
			int nRet = MessageBox(_T("The existing scenario exists, overwrite it?"),
				_T("Replace Scenario"), MB_YESNO);
			if (IDNO == nRet)
				return;
		}
	}
	else
	{
		// verify the edit control text is selected in the list
		// to validate the existance of the scenario
		if (nItem < 0)
		{
			MessageBox(_T("A valid scenario must be selected to open."),
				_T("Open Scenario"));
			return;
		}

		m_str = str;
	}

#ifdef _WIN32_PPC_
	CeShowSip(FALSE);
#endif

	CeDialog::OnOK();
}

void CeScenarioListDlg::OnCancel()
{
#ifdef _WIN32_PPC_
	CeShowSip(FALSE);
#endif
	m_str.Empty();

	CeDialog::OnCancel();
}

///////////////////////////////////////////////////////////////////////////////
//
// CeAboutDlg = Dialog for displaying information about the product
//
///////////////////////////////////////////////////////////////////////////////

class CeAboutDlg: public CeScrollDialog
{
private:
	int m_nIcon;
	CeChildMgr m_mgr;
	CeRect m_rcOrig;

public:
	CeAboutDlg()
		{ m_nIcon = 0; }
	virtual BOOL OnInitDialog();
	virtual void OnTimer( UINT nTimer, bool& bHandled );
	virtual void OnSize( UINT nType, int cx, int cy, bool& bHandled );
};

#define IDT_ANIM_ICON	100

BOOL CeAboutDlg::OnInitDialog()
{
	// allow controls to be created
	BOOL bRet = CeScrollDialog::OnInitDialog();

	GetClientRect(&m_rcOrig);

	// 
	CeString strDisclaimer;
	strDisclaimer.LoadString( IDS_DISCLAIMER, g_hInst);
	SetDlgItemText(IDC_DISCLAIMER, strDisclaimer);

	SetTimer(IDT_ANIM_ICON, 1000);

	m_mgr.Manage( GetDlgItem(IDC_NAME_STATIC), AL_ANCHOR_RIGHT | AL_ADJUST_WIDTH );
	m_mgr.Manage( GetDlgItem(IDC_DISCLAIMER), AL_ANCHOR_RIGHT | AL_ANCHOR_BOTTOM | AL_ADJUST_WIDTH | AL_ADJUST_HEIGHT );

	// size the window to fill the visible area
	HWND hWnd = GetWindow( GW_OWNER );
	if (hWnd)
	{
		CeRect rc;
		::GetWindowRect(hWnd, rc);
		// rc.left += rc.Width() / 2;
		MoveWindow(rc, TRUE);
	}

#ifdef _WIN32_WCE_POCKETPC
	// Create a Done button and size it.  
	SHINITDLGINFO shidi;
	shidi.dwMask = SHIDIM_FLAGS;
	shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
	shidi.hDlg = m_hWnd;

	SHInitDialog(&shidi);
#endif

	return bRet;
}

void CeAboutDlg::OnSize( UINT nType, int cx, int cy, bool& bHandled )
{
	CeScrollDialog::OnSize(nType, cx, cy, bHandled);

	if (cx < m_rcOrig.Width())
		cx = m_rcOrig.Width();

	if (cy < m_rcOrig.Height())
		cy = m_rcOrig.Height();

	m_mgr.OnSize(nType, cx, cy);

	bHandled = true;
}


void CeAboutDlg::OnTimer( UINT nTimer, bool& bHandled )
{
	if (IDT_ANIM_ICON == nTimer)
	{
		HICON hIcon = (HICON) ::LoadIcon(g_hInst, MAKEINTRESOURCE(m_nIcon + IDI_SCENE_1));
		::SendMessage(GetDlgItem(IDC_ANIM_ICON), STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);

		m_nIcon = (m_nIcon + 1) % 5;
	}
}

///////////////////////////////////////////////////////////////////////////////
//
// CeWndDLMain = frame window class
//
///////////////////////////////////////////////////////////////////////////////

TCHAR* g_szSmallTips[] =
{
	NULL, // skipping menu
	_T("Open"),
	_T("Save"),
	_T("Options"),
	_T("About BeamEx"),
};


CeBeamExMain::CeBeamExMain()
{
	m_nFirstStd = -1;
	m_nFirstLocal = -1;
}

CeBeamExMain::~CeBeamExMain()
{
}

BOOL CeBeamExMain::OnCommand(WPARAM wParam, LPARAM lParam, bool& bHandled)
{
	int wmId    = LOWORD(wParam); 
	int wmEvent = HIWORD(wParam); 

	bHandled = true;

	// Parse the menu selections:
	switch (wmId)
	{
	case IDM_ABOUT:			OnAbout();			break;
	case ID_FILE_OPTIONS:	OnOptions();		break;
	case ID_FILE_OPEN:		OnOpen();			break;

	case ID_FILE_SAVE:		OnSave();			break;
	case ID_FILE_SAVEAS:	OnSaveAs();			break;

	case ID_FILE_CLOSE:		OnFileClose();		break;

	// Posted from pages...
	case ID_FILE_CALC:		OnCalc();			break;

	case IDOK:				DestroyWindow();	break;

	default:				bHandled = false;	break;
	}

	return 0;
}

TBBUTTON g_tb[] = 
{
	{0, 0,               TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
	{0, ID_FILE_OPEN,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
	{0, ID_FILE_SAVE,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
	{0, ID_FILE_OPTIONS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
	{0, IDM_ABOUT,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
};

BOOL CeBeamExMain::OnCreate(LPCREATESTRUCT lpCS, bool& bHandled)
{
	// set up the preferences saved
//	CeRegKey keyPrefs;
//	long lRet = keyPrefs.Open(HKEY_LOCAL_MACHINE, _T("Software\\KennySoft\\BeamEx"));
//	if (ERROR_SUCCESS == lRet)
//	{
//	}

#if defined(_WIN32_WCE_POCKETPC)

	bHandled = true;

	#pragma comment(lib, "aygshell.lib")

	SHMENUBARINFO mbi;

	//set up menu bar structure
	memset(&mbi, 0, sizeof(SHMENUBARINFO));
	mbi.cbSize		= sizeof(SHMENUBARINFO);
	mbi.hwndParent	= m_hWnd;
	mbi.nToolBarId	= IDM_MAIN_MENU;
	mbi.hInstRes	= g_hInst;
	mbi.cBmpImages	= 3;
	mbi.nBmpId		= IDB_MAIN_MENU;
	mbi.dwFlags		= 0;

	if (!SHCreateMenuBar(&mbi))
	{
		DWORD dw = GetLastError();
		MessageBox(_T("SHCreateMenuBar Failed"), _T("Error"), MB_OK|MB_ICONERROR);
	}

#elif defined(_WIN32_WCE)

	bHandled = true;

	// Add the application menu bar add toolbar buttons
	m_cmdbar.Create(m_hWnd, 1);

	// Add tooltips for the buttons we will add
    m_cmdbar.AddToolTips(sizeof(g_szSmallTips)/sizeof(TCHAR*), (LPTSTR) g_szSmallTips);

	m_nFirstStd = m_cmdbar.AddStdBitmap(IDB_STD_SMALL_COLOR);

# ifdef _WIN32_WCE_EMULATION
	m_nFirstLocal = m_cmdbar.AddBitmap(IDB_OPTIONS16, 1, 16, 16);
	m_cmdbar.AddBitmap(IDB_HELP16, 1, 16, 16);
# else
	m_nFirstLocal = m_cmdbar.AddBitmap(IDB_OPTIONS4, 1, 16, 16);
	m_cmdbar.AddBitmap(IDB_HELP4, 1, 16, 16);
# endif

	m_cmdbar.InsertMenubar(IDM_MAIN_MENU, 0);

    // Add buttons in tbSTDButton to Commandbar

	g_tb[0].iBitmap = 0;							// File menu
	g_tb[1].iBitmap = m_nFirstStd + STD_FILEOPEN;	// Open
	g_tb[2].iBitmap = m_nFirstStd + STD_FILESAVE;	// Save
	g_tb[3].iBitmap = m_nFirstLocal;				// Options
	g_tb[4].iBitmap = m_nFirstLocal + 1;			// About

	m_cmdbar.AddButtons(sizeof(g_tb)/sizeof(*g_tb), g_tb);
	
    // Add Close and Help buttons
	m_cmdbar.AddAdornments(CMDBAR_HELP);
#endif

	RECT rc;
	GetClientRect(&rc);
#if defined(_WIN32_WCE)
	if (m_cmdbar)
		rc.top += m_cmdbar.GetHeight();
#endif

//	UINT nIDD = 0;
//	if (GetSystemMetrics(SM_CXSCREEN) >= GetSystemMetrics(SM_CYSCREEN))
//		nIDD = IDD_INPUTPANELHPC;
//	else
//		nIDD = IDD_INPUTPANELPPC;

	// first, create the 
	CeRect rcResultsPanel;
	if (! m_panelResults.Create(IDD_RESULTS, *this, g_hInst))
	{
		// failed...
		MessageBox(_T("Dialog Creation Failed!!"), _T("Failure!"), MB_OK | MB_ICONERROR);
		return FALSE;
	}
	else
	{
		m_panelResults.GetWindowRect(rcResultsPanel);
		int nHeight = rcResultsPanel.Height();
		rcResultsPanel.top = rc.top;
		rcResultsPanel.bottom = rc.top + nHeight;
		rcResultsPanel.left = rc.left;
		rcResultsPanel.right = rc.right;

		m_panelResults.MoveWindow(&rcResultsPanel);
		m_panelResults.ShowWindow(SW_SHOW);

		rc.top += nHeight;
	}

	if (! m_panelSheet.Create(WS_VISIBLE|WS_CHILD, rc, *this, 1001, g_hInst))
	{
		// failed...
		MessageBox(_T("Dialog Creation Failed!!"), _T("Failure!"), MB_OK | MB_ICONERROR);
	}
	else
	{
		// stretch window to full client area
//		m_panelSheet.SetWindowPos(NULL, &rc, SWP_NOZORDER|SWP_SHOWWINDOW);

		m_panelSheet.AddPage(&m_pageLayout);
		m_panelSheet.AddPage(&m_pageActuals);
		m_panelSheet.AddPage(&m_pageMaterials);
	}

	OpenScenario(g_szScenarioDef);

	return TRUE;
}

void CeBeamExMain::OnDestroy(bool& bHandled)
{
	bHandled = true;
	PostQuitMessage(0);
}

void CeBeamExMain::OnClose(bool& bHandled)
{
	bHandled = true;

	SaveScenario(g_szScenarioDef);

	DestroyWindow();
}

void CeBeamExMain::OnAbout()
{
	CeAboutDlg dlg;
	dlg.DoModal(IDD_ABOUT, m_hWnd, g_hInst);
}

void CeBeamExMain::OnOptions()
{
	CeOptionsDlg dlg;
	dlg.DoModal(IDD_OPTIONS, *this, g_hInst);
}

void CeBeamExMain::OnOpen()
{
	OpenScenario(m_strScenario);
}

void CeBeamExMain::OnSave()
{
	if (m_strScenario == g_szScenarioDef)
		SaveScenario(NULL);
	else
		SaveScenario(m_strScenario);
}

void CeBeamExMain::OnSaveAs()
{
	SaveScenario(NULL);
}

void CeBeamExMain::SaveScenario(LPCTSTR lpszScenario)
{
	CeScenarioListDlg dlg(lpszScenario, true);
	if (NULL == lpszScenario || 0 == *lpszScenario)
	{
		if (IDOK != dlg.DoModal(IDD_SCENARIONAME, *this, g_hInst))
			return;

		if (dlg.m_str.IsEmpty())
			return;

		lpszScenario = dlg.m_str;
	}

	//
	// Sync the data from the controls to the data elements]
	//
	m_pageLayout.Sync(true);
	m_pageActuals.Sync(true);
	m_pageMaterials.Sync(true);

	//
	// Open the database and write the values
	//
	CeDb db;
	DWORD dwPropid = MAKELONG(CEVT_LPWSTR, BEAMSCENE_NAME);
	if (! db.Open(g_szScenarioDb, dwPropid))
	{
		if (ERROR_FILE_NOT_FOUND != GetLastError())
		{
			MessageBox(_T("Unable to open database"), _T("Database Operation Failed"));
			return;
		}

		SORTORDERSPEC sortSpec;
		sortSpec.propid = dwPropid;
		sortSpec.dwFlags = CEDB_SORT_CASEINSENSITIVE;

		if (! db.Create(g_szScenarioDb, 0, 1, &sortSpec) || ! db.Open())
		{
			MessageBox(_T("Unable to create save database"), _T("Database Operation Failed"));
			return;
		}
	}

	CeDbRecord recFind;
	recFind.AddProp(BEAMSCENE_NAME, CEVT_LPWSTR);
	recFind.SetIdVal(BEAMSCENE_NAME, lpszScenario);
	CEOID oid = db.SeekRec(recFind.m_pProps);

	// always overwrite, we've already asked when the name exists already
	CeDbRecord rec;
	rec.m_oid = oid;

	rec.AddProp(BEAMSCENE_NAME,	CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_SCENE, CEVT_I2);
	rec.AddProp(BEAMSCENE_SCENE1, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_SCENE2, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_SCENE3, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_CROSS, CEVT_I2);
	rec.AddProp(BEAMSCENE_CROSS1, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_CROSS2, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_CROSS3, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_CROSS4, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_MATERIAL, CEVT_LPWSTR);
	rec.AddProp(BEAMSCENE_ELASTICITY, CEVT_LPWSTR);

	rec.SetIdVal(BEAMSCENE_NAME, lpszScenario);
	rec.SetIdVal(BEAMSCENE_SCENE, m_pageActuals.m_nScenario);
	rec.SetIdVal(BEAMSCENE_SCENE1, (LPCTSTR) m_pageActuals.m_strParm_1);
	rec.SetIdVal(BEAMSCENE_SCENE2, (LPCTSTR) m_pageActuals.m_strParm_2);
	rec.SetIdVal(BEAMSCENE_SCENE3, (LPCTSTR) m_pageActuals.m_strParm_3);
	rec.SetIdVal(BEAMSCENE_CROSS, m_pageLayout.m_nSection);
	rec.SetIdVal(BEAMSCENE_CROSS1, (LPCTSTR) m_pageLayout.m_strParm_1);
	rec.SetIdVal(BEAMSCENE_CROSS2, (LPCTSTR) m_pageLayout.m_strParm_2);
	rec.SetIdVal(BEAMSCENE_CROSS3, (LPCTSTR) m_pageLayout.m_strParm_3);
	rec.SetIdVal(BEAMSCENE_CROSS4, (LPCTSTR) m_pageLayout.m_strParm_4);
	rec.SetIdVal(BEAMSCENE_MATERIAL, (LPCTSTR) m_pageMaterials.m_strMaterial);
	rec.SetIdVal(BEAMSCENE_ELASTICITY, (LPCTSTR) m_pageMaterials.m_strModulus);

	if (rec.m_oid)
	{
		if (! db.UpdateRec(rec))
			MessageBox(_T("Update Scenario Failed"), _T("Save Failed"));
	}
	else
	{
		if (! db.AddRec(rec))
			MessageBox(_T("Add Scenario Failed"), _T("Save Failed"));
	}

	m_strScenario = lpszScenario;
}

void CeBeamExMain::OpenScenario(LPCTSTR lpszScenario)
{
	CeScenarioListDlg dlg(lpszScenario, false);

	if (NULL == lpszScenario || m_strScenario == lpszScenario)
	{
		if (IDOK != dlg.DoModal(IDD_SCENARIONAME, *this, g_hInst))
			return;

		if (dlg.m_str.IsEmpty())
			return;

		lpszScenario = dlg.m_str;
	}

	//
	// Open the database and read the values
	//
	CeDb db;
	if (! db.Open(g_szScenarioDb))
	{
		// Doesn't exist when starting initialy
		//MessageBox(_T("Unable to open database"), _T("Database Operation Failed"));
		return;
	}

	CeDbRecord rec;
	rec.AddProp(BEAMSCENE_NAME, CEVT_LPWSTR);
	rec.SetIdVal(BEAMSCENE_NAME, lpszScenario);

	if (0 == db.SeekRec(rec.m_pProps))
		return;
	
	db.ReadRec(rec);

	//
	// parameters
	//
	rec.GetIdVal(BEAMSCENE_SCENE, m_pageActuals.m_nScenario);
	rec.GetIdVal(BEAMSCENE_SCENE1, m_pageActuals.m_strParm_1);
	rec.GetIdVal(BEAMSCENE_SCENE2, m_pageActuals.m_strParm_2);
	rec.GetIdVal(BEAMSCENE_SCENE3, m_pageActuals.m_strParm_3);

	rec.GetIdVal(BEAMSCENE_CROSS, m_pageLayout.m_nSection);
	rec.GetIdVal(BEAMSCENE_CROSS1, m_pageLayout.m_strParm_1);
	rec.GetIdVal(BEAMSCENE_CROSS2, m_pageLayout.m_strParm_2);
	rec.GetIdVal(BEAMSCENE_CROSS3, m_pageLayout.m_strParm_3);
	rec.GetIdVal(BEAMSCENE_CROSS4, m_pageLayout.m_strParm_4);

	rec.GetIdVal(BEAMSCENE_MATERIAL, m_pageMaterials.m_strMaterial);
	rec.GetIdVal(BEAMSCENE_ELASTICITY, m_pageMaterials.m_strModulus);

	//
	// Sync the data to the controls
	//
	m_pageLayout.Sync(false);
	m_pageActuals.Sync(false);
	m_pageMaterials.Sync(false);

	OnCalc();

	m_strScenario = lpszScenario;
}

void CeBeamExMain::OnCalc()
{
//	if (m_pageLayout.IsWindow() && m_pageActuals.IsWindow() && m_pageMaterials.IsWindow())
//	{
		double dblY, dblYmax;
		double dblI = m_pageLayout.CalcI();
		double dblE = m_pageMaterials.CalcE();

		CeString str( dblI , BEAMEX_PRECISION);

		if (m_pageActuals.CalcY(dblI, dblE, dblY, dblYmax))
		{
			str.SetDouble(dblY, BEAMEX_PRECISION);
			m_panelResults.SetDlgItemText(IDC_DEFLECTION, str);
			str.SetDouble(dblYmax, BEAMEX_PRECISION);
			m_panelResults.SetDlgItemText(IDC_DEFLECTION_MAX, str);

			return;
		}
//	}

	m_panelResults.SetDlgItemText(IDC_DEFLECTION, _T(""));
	m_panelResults.SetDlgItemText(IDC_DEFLECTION_MAX, _T(""));
}

void CeBeamExMain::OnFileClose()
{
	PostQuitMessage(0);
}

void CeBeamExMain::OnSize(UINT nType, int cx, int cy, bool& bHandled)
{
	RECT rc;
	GetClientRect(&rc);
#if defined(_WIN32_WCE)
	if (m_cmdbar)
		rc.top += m_cmdbar.GetHeight();
#endif

	CeRect rcResultsPanel;
	m_panelResults.GetWindowRect(rcResultsPanel);
	int nHeight = rcResultsPanel.Height();
	rcResultsPanel.top = rc.top;
	rcResultsPanel.bottom = rc.top + nHeight;
	rcResultsPanel.left = rc.left;
	rcResultsPanel.right = rc.right;

	m_panelResults.MoveWindow(&rcResultsPanel);

	rc.top += nHeight;

	m_panelSheet.SetWindowPos(NULL, &rc, SWP_NOZORDER|SWP_SHOWWINDOW);
}

void CeBeamExMain::OnSettingChange( WORD wFlags, LPCTSTR lpszSection, bool& bHandled )
{
#if defined(_WIN32_WCE_POCKETPC)

	s_sai.cbSize = sizeof s_sai;

  	SHHandleWMSettingChange(m_hWnd, wFlags, (long) lpszSection, &s_sai);
	bHandled = true;

#elif defined(_WIN32_PPC_)
	switch( wFlags)
	{
	case SPI_SETSIPINFO:
		{
			SIPINFO si;
			memset( &si, 0, sizeof( si ) );
			si.cbSize = sizeof( si );
			if( SHSipInfo( SPI_GETSIPINFO, 0, &si, 0 ) ) 
			{
				MoveWindow(
					si.rcVisibleDesktop.left,
					si.rcVisibleDesktop.top,
					si.rcVisibleDesktop.right -                                                si.rcVisibleDesktop.left,
					si.rcVisibleDesktop.bottom -
					si.rcVisibleDesktop.top,
					TRUE );
			}
		}
		break;
	default:
		break;
	}
#endif // _WIN32_PPC_
}

LRESULT CeBeamExMain::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
{
	switch (uMsg)
	{
	case WM_HELP:
		{
			PROCESS_INFORMATION pi;
			::CreateProcess(_T("peghelp.exe"), _T("file:beamex.htm#index"),
				NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi);
			CloseHandle(pi.hProcess);
			CloseHandle(pi.hThread);
		}
		break;
	}
	return 1;
}

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

Kenny G

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 5 Oct 2000
Article Copyright 2000 by Kenny G
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid