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

📄 app_sync728.cpp

📁 SyncML 协议的同步实现的数据备份,是基于wince平台,,也可很容易移植到其它平台
💻 CPP
字号:
// App_Sync728.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "App_Sync728.h"

#include "MainFrm.h"

#include "App_Sync728Doc.h"
#include "App_Sync728View.h"
//#include <osinterfacedll.h>
#include <Pw.h>
#include "progressdlg.h"

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

#ifndef MAX_PATH_LEN
#define MAX_PATH_LEN 256
#endif

extern BOOL bAutoRemind;
extern BOOL bReplace;
extern BOOL bPassword;
extern wchar_t wszLastZip[MAX_PATH_LEN];
extern wchar_t wszLastXDB[MAX_PATH_LEN];

#define  WM_DSHOWEVENT WM_APP+1

enum{
	RING_INITIAL=0   ,
	RING_START       ,
	RING_RESTART     ,
	RING_PAUSE       ,
	RING_STOP        ,
	RING_IS_PLAYING  ,
	RING_SET_CHANNEL ,
	RING_RELEASE     ,
	RING_SET_FILE    ,
	RING_EVENT_WINDOW,
	RING_HANDLE_EVENT,
	RING_PLAY_STRING ,
};

typedef int (*pAudioPlay)(int nWhichFun,void * param1=NULL,void * param2=NULL);

DWORD PlayMusic(void *p);

/////////////////////////////////////////////////////////////////////////////
// CApp_Sync728App

BEGIN_MESSAGE_MAP(CApp_Sync728App, CWinApp)
	//{{AFX_MSG_MAP(CApp_Sync728App)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CApp_Sync728App construction

CApp_Sync728App::CApp_Sync728App()
	: CWinApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CApp_Sync728App object

CApp_Sync728App theApp;

/////////////////////////////////////////////////////////////////////////////
// CApp_Sync728App initialization

BOOL CApp_Sync728App::InitInstance()
{
    // 用应用程序名创建信号量
	HANDLE hSem = CreateSemaphore(NULL, 1, 1, m_pszExeName);

    // 信号量已存在?
	// 信号量存在,则程序已有一个实例运行
    if (GetLastError() == ERROR_ALREADY_EXISTS)
	{
		// 关闭信号量句柄
        CloseHandle(hSem);
		
		// 寻找先前实例的主窗口
		HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), 
			GW_CHILD);
        while (::IsWindow(hWndPrevious))
		{
			wchar_t txt[128];
			memset(&txt, 0, sizeof (txt));
			
			::GetWindowText(hWndPrevious, txt, 127); 

			TCHAR SZ[80];
	        LoadString(AfxGetInstanceHandle(), MESSAGE_MAIN_NAME, SZ, sizeof(SZ)/sizeof(TCHAR));
			if (wcscmp(txt, CString(SZ)) == 0)
			{
				::SetForegroundWindow(hWndPrevious);
				// 退出本实例
                return TRUE;
			}
			// 继续寻找下一个窗口
			hWndPrevious = ::GetWindow(hWndPrevious,GW_HWNDNEXT);
        }
		
		// 前一实例已存在,但找不到其主窗
		// 可能出错了
		// 退出本实例
		return FALSE;
    }
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

	// Change the registry key under which our settings are stored.
	// You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CApp_Sync728Doc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CApp_Sync728View));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	bAutoRemind = TRUE;
	bReplace = TRUE;
	bPassword = TRUE;
	memset(&wszLastZip, 0, sizeof (wszLastZip));
	memset(&wszLastXDB, 0, sizeof (wszLastZip));

	CFile file;
	if (file.Open(TEXT("\\DbData\\SYSCONFIG\\SDSync.cfg"), CFile::modeRead))
	{
		file.Read(&bAutoRemind, sizeof (bAutoRemind));
		file.Read(&bReplace, sizeof (bReplace));
		file.Read(&bPassword, sizeof (bPassword));
		file.Read(&wszLastZip, MAX_PATH_LEN);
		file.Read(&wszLastXDB, MAX_PATH_LEN);
		file.Close();
	}
	else
	{
		bAutoRemind = TRUE;
		bReplace = TRUE;
		file.Open(TEXT("\\DbData\\SYSCONFIG\\SDSync.cfg"), CFile::modeCreate | CFile::modeWrite);
		file.Write(&bAutoRemind, sizeof (bAutoRemind));
		file.Write(&bReplace, sizeof (bReplace));
		file.Write(&bPassword, sizeof (bPassword));
		file.Write(&wszLastZip, MAX_PATH_LEN);
		file.Write(&wszLastXDB, MAX_PATH_LEN);
		file.Close();
	}

	if (cmdInfo.m_strFileName == TEXT("X"))
	{
		if (bAutoRemind)
		{	
			HANDLE hThread = ::CreateThread(NULL, NULL, PlayMusic, this, NULL, NULL);
			
	        TCHAR SZ1[160];
            TCHAR SZ2[160];
			LoadString(AfxGetInstanceHandle(), MESSAGE_MAIN_HINT, SZ1, sizeof(SZ1)/sizeof(TCHAR));
		    LoadString(AfxGetInstanceHandle(), MESSAGE_MAIN_HINT_TITLE, SZ2, sizeof(SZ2)/sizeof(TCHAR));
			if (MessageBox(NULL, CString(SZ1), CString(SZ2), MB_YESNO) != IDYES)
			{
				return FALSE;	
			}
		}
		cmdInfo.m_strFileName = TEXT("");
		memset(&cmdInfo.m_nShellCommand, 0, sizeof (int));
	}

	if (bPassword)
	{
		CProgressDlg dlg;
		dlg.DoModal();

		if (!dlg.m_bOK)
		{
			return FALSE;
		}
	}
	
	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	SetForegroundWindow(m_pMainWnd->m_hWnd); 
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// 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)
	virtual BOOL OnInitDialog();		// Added for WCE apps
	//}}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()

// App command to run the dialog
void CApp_Sync728App::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CApp_Sync728App commands
// Added for WCE apps

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CenterWindow();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

DWORD PlayMusic(void *p)
{
	HINSTANCE  hIns;
	pAudioPlay playEntry;
	hIns=::LoadLibrary(L"\\SystemData\\dll\\RingPlay.dll");   //////具体路径视具体情况而定
	if (hIns != NULL)
	{
		playEntry=(pAudioPlay)::GetProcAddress(hIns,L"XRingPlayEntry");
		if (playEntry != NULL)
		{
			playEntry(RING_RELEASE);
	
			playEntry(RING_INITIAL);
			playEntry(RING_SET_FILE);

			CString strAutoPath = TEXT("\\windows\\default.wav");
			WIN32_FIND_DATA fileData;
			HANDLE hFindFile = FindFirstFile((LPCTSTR)strAutoPath, &fileData);
			if (hFindFile == INVALID_HANDLE_VALUE)
			{
				//播放系统提示音乐
			}
			else
			{
				playEntry(RING_START,(void*)(LPCTSTR)strAutoPath);
				while (playEntry(RING_IS_PLAYING))
				{
					Sleep(3000);
					playEntry(RING_STOP);
				}	
			}
			FindClose(hFindFile);
			playEntry(RING_RELEASE);
		}	
		FreeLibrary(hIns);
	}
	return 0;
}

⌨️ 快捷键说明

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