⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtdtest.cpp

📁 windows ce开发技巧与实例光盘代码
💻 CPP
字号:
// DTDTest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <commdlg.h>
#include "resource.h"
#include "AdoFiltr.h"


/////////////////////////////////////////////////////////////////////////////
// Globals

HINSTANCE g_hInst=NULL;



/////////////////////////////////////////////////////////////////////////////
// Local function prototypes

BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
void DoTransfer(HWND hwnd, BOOL bDesktopToDevice);



/////////////////////////////////////////////////////////////////////////////
//
// WinMain - Main application entry point
//
/////////////////////////////////////////////////////////////////////////////
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
	// Save the instance handle
	g_hInst=hInst;

	// Launch the main dialog
	DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);

	return 0;
}


/////////////////////////////////////////////////////////////////////////////
//
// DlgProc - Main dialog box procedure
//
/////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	switch(msg)
	{
	case WM_INITDIALOG:
		{
			// Set upper limits on text length so we know how big a buffer we
			// need later on...
			SendDlgItemMessage(hwnd, IDC_DSKTP_LOC, EM_LIMITTEXT, MAX_PATH, 0);
			SendDlgItemMessage(hwnd, IDC_DVC_LOC, EM_LIMITTEXT, MAX_PATH, 0);
			SendDlgItemMessage(hwnd, IDC_TABLE_LIST, EM_LIMITTEXT, MAX_PATH, 0);
		}
		return TRUE;

	case WM_COMMAND:
		switch(LOWORD(wp))
		{
		case IDCANCEL:
			{
				// Prompt user for confirmation before quitting
				if(IDYES==MessageBox(hwnd, "Are you sure you want to quit?",
					"Confirm:", MB_YESNO|MB_DEFBUTTON2))
				{
					EndDialog(hwnd, IDCANCEL);
				}
			}
			return TRUE;

		case IDC_BROWSE:
			{
				// Browse for the database file on the desktop
				TCHAR szFilename[MAX_PATH]={0};
				OPENFILENAME ofn={sizeof(OPENFILENAME)};

				ofn.hwndOwner=hwnd;
				ofn.hInstance=g_hInst;
				ofn.lpstrFilter="Database Files (*.mdb)\0*.mdb\0All Files(*.*)\0*.*\0";
				ofn.lpstrFile=szFilename;
				ofn.nMaxFile=MAX_PATH;
				ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
				ofn.lpstrDefExt="mdb";

				if(GetOpenFileName(&ofn))
					SetDlgItemText(hwnd, IDC_DSKTP_LOC, szFilename);
			}
			return TRUE;

		case IDC_DESKTOPTODEVICE:
		case IDC_DEVICETODESKTOP:
			{
				// Begin the transfer!
				DoTransfer( hwnd, (IDC_DESKTOPTODEVICE==LOWORD(wp)) );
			}
			return TRUE;
		}
		break;
	}

	return FALSE;
}


/////////////////////////////////////////////////////////////////////////////
//
// DoTransfer - Read the values from the dialog box controls and calls either
// DESKTOPTODEVICE or DEVICETODESKTOP to transfer the tables
//
/////////////////////////////////////////////////////////////////////////////
void DoTransfer(HWND hwnd, BOOL bDesktopToDevice)
{
	char szDesktopLocn[MAX_PATH]={0};
	char szDeviceLocn[MAX_PATH]={0};
	char szTableList[MAX_PATH]={0};

	// Get the text from the edit boxes
	GetDlgItemText(hwnd, IDC_DSKTP_LOC, szDesktopLocn, MAX_PATH);
	GetDlgItemText(hwnd, IDC_DVC_LOC, szDeviceLocn, MAX_PATH);
	GetDlgItemText(hwnd, IDC_TABLE_LIST, szTableList, MAX_PATH);

	// Get the transfer options
	BOOL bSync=( SendDlgItemMessage(hwnd, IDC_SYNC, BM_GETCHECK, 0, 0)
		==BST_CHECKED );

	BOOL bOverwrite=( SendDlgItemMessage(hwnd, IDC_OVERWRITE, BM_GETCHECK, 0,
		0)==BST_CHECKED );

	// Transfer the tables
	HRESULT hResult=NO_ERROR;

	SetCursor(LoadCursor(NULL, IDC_WAIT));

	if(bDesktopToDevice)
	{
		hResult=DESKTOPTODEVICE(szDesktopLocn, szTableList, bSync,
			bOverwrite, szDeviceLocn);
	}
	else
	{
		hResult=DEVICETODESKTOP(szDesktopLocn, szTableList, bSync,
			bOverwrite, szDeviceLocn);
	}

	SetCursor(LoadCursor(NULL, IDC_ARROW));

	// Report results
	if(SUCCEEDED(hResult))
		MessageBox(hwnd, "Transfer Succeeded!", "Result:", MB_OK);
	else
	{
		LPTSTR lpBuff=NULL;
		DWORD dwChars=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
			FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
			hResult, 0, (LPTSTR)&lpBuff, 0, NULL);

		if(dwChars && lpBuff)
		{
			MessageBox(hwnd, lpBuff, NULL, MB_OK);
			LocalFree(lpBuff);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -