Click here to Skip to main content
11,495,331 members (37,390 online)
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 227.8K 795 70
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
// Setup.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

BOOL InitApplication(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
void FillInPropertyPage(PROPSHEETPAGE* pPSP, int nDlg, LPSTR pszProc, DLGPROC pfnDlgProc);
int DoWizard(HWND hwndOwner, HINSTANCE hInst);
BOOL APIENTRY PP1Proc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
BOOL APIENTRY PP2Proc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
LONG APIENTRY MainWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam);

BOOL APIENTRY WhichINIProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);

int PreInstall(HWND hList);
int Install(LPCTSTR lpszWhich);

TCHAR		g_szWhichIni[MAX_PATH];
HINSTANCE	g_hInst = NULL;

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	g_hInst = hInstance;

	int nIni = PreInstall(NULL);
	if (nIni > 1)
	{
		HWND hParent = NULL;
		if (IDOK != DialogBox(g_hInst, MAKEINTRESOURCE(IDD_WHICHINI), hParent, WhichINIProc))
			return 1;
	}
	else if (0 == nIni)
		return 1;

	DoWizard(NULL, hInstance);
	return 0;  
}


int PreInstall(HWND hList)
{
	TCHAR szError[1024];

	WIN32_FIND_DATA fd;
	HANDLE h = FindFirstFile(_T("*.ini"), &fd);
	if (INVALID_HANDLE_VALUE == h)
	{
		LoadString(g_hInst, IDS_INI_REQUIRED, szError, 1024);
		MessageBox(NULL, szError, NULL, MB_OK|MB_ICONERROR);
		return 0;
	}

	_tsplitpath(fd.cFileName, NULL, NULL, g_szWhichIni, NULL);
	if (hList != NULL)
		ListBox_AddString(hList, g_szWhichIni);

	for (int n = 1; FindNextFile(h, &fd); n++)
	{
		_tsplitpath(fd.cFileName, NULL, NULL, g_szWhichIni, NULL);
		if (hList != NULL)
			ListBox_AddString(hList, g_szWhichIni);

		wsprintf(szError, _T("%s\n"), fd.cFileName);
		OutputDebugString(szError);
	}

	FindClose(h);

	return n;
}


BOOL APIENTRY WhichINIProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
	HWND hList = GetDlgItem(hDlg, IDC_LIST1);

	switch (message)
	{
	case WM_INITDIALOG:
		PreInstall(hList);
		ListBox_SetCurSel(hList, 0);
		break;
		
	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED)
		{
			if (LOWORD(wParam) == IDOK)
			{
				ListBox_GetText(hList, ListBox_GetCurSel(hList), g_szWhichIni);
				EndDialog(hDlg, LOWORD(wParam));
			}
			else if (LOWORD(wParam) == IDCANCEL)
			{
				EndDialog(hDlg, LOWORD(wParam));
			}
		}
		break;		
		
	default:
		return FALSE;
	}

	return TRUE;   
}




int Install(LPCTSTR lpszWhich)
{
	// find the .EXE for installation
	HKEY hkSvc;
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services"), 0, KEY_READ, &hkSvc))
	{
		TCHAR szError[1024];
		LoadString(g_hInst, IDS_NOACTIVESYNC, szError, 1024);
		MessageBox(NULL, szError, NULL, MB_OK|MB_ICONERROR);
		return 1;
	}

	TCHAR szInstallDir[MAX_PATH];
	DWORD dw = MAX_PATH;
	if (RegQueryValueEx(hkSvc, _T("InstalledDir"), NULL, NULL, (LPBYTE) szInstallDir, &dw))
	{
		TCHAR szError[1024];
		LoadString(g_hInst, IDS_NOACTIVESYNC, szError, 1024);
		MessageBox(NULL, szError, NULL, MB_OK|MB_ICONERROR);
		return 1;
	}

	TCHAR szInstallCmd[MAX_PATH];
	_tcscpy(szInstallCmd, szInstallDir);
	_tcscat(szInstallCmd, _T("\\CeAppMgr.exe "));

	// Find the module
	TCHAR szFileName[MAX_PATH];
	if (! GetModuleFileName(NULL, szFileName, MAX_PATH))
	{
		//GetLastError();
		//FormatMessage();
		return 0;
	}

	LPTSTR psz = _tcsrchr(szFileName, _T('\\'));
	TCHAR szCurDir[MAX_PATH];
	_tcsncpy(szCurDir, szFileName, psz - szFileName + 1);
	szCurDir[psz - szFileName + 1] = 0;

	// save the destination .INI file name
	_tcscat(szInstallDir, _T("\\"));
	_tcscat(szInstallDir, lpszWhich);
	int n = _tcslen(szInstallDir);
	szInstallDir[++n] = 0;

	if (! CreateDirectory(szInstallDir, NULL))
	{
		DWORD dwError = GetLastError();
		if (dwError != ERROR_ALREADY_EXISTS)
		{
			//FormatMessage()
			return 1;
		}
	}

	//
	// Double null terminate destination
	//
	TCHAR szFrom[MAX_PATH];
	_tcscpy(szFrom, szCurDir);
	_tcscat(szFrom, g_szWhichIni);
	_tcscat(szFrom, _T(".*.*"));
	n = _tcslen(szFrom) + 1;

	// double null terminate
	szFrom[n] = 0;

	//
	// Copy the ftpView*.* files (ftpView.ini, ftpView_MIPS.cab, etc)
	//
	SHFILEOPSTRUCT shfo;
	shfo.hwnd = NULL;
    shfo.wFunc = FO_COPY;
    shfo.pFrom = szFrom;
    shfo.pTo = szInstallDir;
    shfo.fFlags = FOF_FILESONLY | FOF_SIMPLEPROGRESS | FOF_NOCONFIRMATION;
    shfo.fAnyOperationsAborted; 
    shfo.hNameMappings; 
    shfo.lpszProgressTitle = _T("Copying installation files..."); 

	// copy the files to an alternate location
	if (SHFileOperation(&shfo))
	{
		// this functions shows any error it encounters, just return
		return 1;
	}

	// run the installation from it's new location
	TCHAR szIni[MAX_PATH];
	_tcscpy(szIni, "\"");
	_tcscat(szIni, szInstallDir);
	_tcscat(szIni, _T("\\"));
	_tcscat(szIni, lpszWhich);
	_tcscat(szIni, _T(".ini"));
	_tcscat(szIni, "\"");

	_tcscat(szInstallCmd, szIni);

	WinExec(szInstallCmd, SW_SHOW);

	return 0;
}


//
//
//  FUNCTION: FillInPropertyPage(PROPSHEETPAGE *, int, LPSTR, LPFN) 
//
//  PURPOSE: Fills in the given PROPSHEETPAGE structure 
//
//  COMMENTS:
//
//      This function fills in a PROPSHEETPAGE structure with the
//      information the system needs to create the page.
// 
void FillInPropertyPage(PROPSHEETPAGE* pPSP, int nDlg, LPSTR pszProc, DLGPROC pfnDlgProc)
{
	pPSP->dwSize		= sizeof(PROPSHEETPAGE);
	pPSP->dwFlags		= 0;
	pPSP->hInstance		= g_hInst;
	pPSP->pszTemplate	= MAKEINTRESOURCE(nDlg);
	pPSP->pszIcon		= NULL;
	pPSP->pfnDlgProc	= pfnDlgProc;
	pPSP->pszTitle		= pszProc;
	pPSP->lParam		= 0;
}



//
//
//    FUNCTION: CreateWizard(HWND)
//
//    PURPOSE: Create the Wizard control. 
//
//   COMMENTS:
//	
//      This function creates the wizard property sheet.
//
int DoWizard(HWND hwndOwner, HINSTANCE hInst)
{
    PROPSHEETPAGE psp[2];
    PROPSHEETHEADER psh;

	FillInPropertyPage( &psp[0], IDD_PROPPAGE_START, TEXT("Welcome"), PP1Proc);
	FillInPropertyPage( &psp[1], IDD_PROPPAGE_LICENSE, TEXT("License"), PP2Proc);
    
    psh.dwSize = sizeof(PROPSHEETHEADER);
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_WIZARD | PSH_NOAPPLYNOW;
    psh.hwndParent = hwndOwner;
    psh.pszCaption = (LPSTR) TEXT("Setup Wizard");
    psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
    psh.nStartPage = 0;
    psh.ppsp = (LPCPROPSHEETPAGE) &psp;

    return (PropertySheet(&psh));
}


//
//  FUNCTION: PP1Proc(HWND, UINT, UINT, LONG)
//
//  PURPOSE:  Processes messages for "Addaptability to Change" page 
//
//  MESSAGES:
//	
//	WM_INITDIALOG - intializes the page
//	WM_NOTIFY - processes the notifications sent to the page
//	WM_COMMAND - saves the id of the choice selected
//
//
BOOL APIENTRY PP1Proc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
	HWND hRadio = GetDlgItem(hDlg, IDC_DISAGREE);

	switch (message)
	{
	case WM_INITDIALOG:
		{
			char szBuf[4096];
			char szBuf2[4096];

			SetFocus(hRadio);
			SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);

			GetWindowText( GetDlgItem(hDlg, IDC_STATIC_APP), szBuf, 4096 );
			wsprintf(szBuf2, szBuf, g_szWhichIni, g_szWhichIni);
			SetWindowText( GetDlgItem(hDlg, IDC_STATIC_APP), szBuf2 );
		}
		return FALSE;		

	case WM_COMMAND:
		break;
		
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code) 
		{
		case PSN_KILLACTIVE:	
			SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
			break;

		case PSN_RESET:
			SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
			break;

		case PSN_SETACTIVE:
			PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
			break;

		default:
			return FALSE;
		}
		break;
		
	default:
		return FALSE;
	}

	return TRUE;   
}


//
//  FUNCTION: PP2Proc(HWND, UINT, UINT, LONG)
//
//  PURPOSE:  Processes messages for "Addaptability to Change" page 
//
//  MESSAGES:
//	
//	WM_INITDIALOG - intializes the page
//	WM_NOTIFY - processes the notifications sent to the page
//	WM_COMMAND - saves the id of the choice selected
//
//
BOOL APIENTRY PP2Proc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		{
			char szLicense[MAX_PATH];
			wsprintf(szLicense, "%s.License.txt", g_szWhichIni);

			HANDLE hFile = CreateFile(szLicense, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 
				FILE_FLAG_SEQUENTIAL_SCAN, NULL);

			DWORD dwSize = GetFileSize(hFile, NULL);

			if (NULL != hFile && 0 < dwSize)
			{
				DWORD dwRead;
				BYTE* pData = (BYTE*) LocalAlloc(LPTR, dwSize);
				ReadFile(hFile, pData, dwSize, &dwRead, NULL);
				SetWindowText(GetDlgItem(hDlg, IDC_LICENSE), (char*)pData);
				LocalFree((HLOCAL) pData);
			}
			else
			{
				TCHAR sz[4096];
				LoadString((HINSTANCE)::GetWindowLong(hDlg, GWL_HINSTANCE),
					IDS_CHARITY, sz, 4096); 

				SetWindowText(GetDlgItem(hDlg, IDC_LICENSE), sz);
			}
		}
		break;
		
	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED)
		{
			if (LOWORD(wParam) == IDC_DISAGREE)
				PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
			else if (LOWORD(wParam) == IDC_AGREE)
				PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_FINISH);
		}
		break;				
		
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code) 
		{
		case PSN_KILLACTIVE:
			SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
			break;

		case PSN_RESET:
			SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
			break;

		case PSN_SETACTIVE:
			PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
			break;

		case PSN_WIZFINISH:
			Install(g_szWhichIni);
			break;

		case PSN_WIZBACK:		// nothing
		default:
			return FALSE;
		}
		break;
		
		default:
			return FALSE;
	}

	return TRUE;   
}


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
Web01 | 2.8.150520.1 | Last Updated 5 Oct 2000
Article Copyright 2000 by Kenny G
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid