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

📄 memorydemodlg.cpp

📁 在WinCE环境下,不同的AP可能需要共享数据,信息,该例子就是几个不同的AP来读写同一块内存的例子.
💻 CPP
字号:
// MemoryDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MemoryDemo.h"
#include "MemoryDemoDlg.h"
#include <tlhelp32.h>
#include <windows.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

int wcs2ansi (LPSTR _mbstr, const wchar_t* _wcstr, int _max_mbstr_len)

{

	int sz = wcstombs (_mbstr, _wcstr, _max_mbstr_len-1);

	_mbstr[sz] = 0;

	return sz;

};

/////////////////////////////////////////////////////////////////////////////
// CMemoryDemoDlg dialog
void lpRecvProc(LPVOID lpParam)
{
//	CEdit* pEdit=(CEdit*)lpParam;
	CListBox* pList = (CListBox*)lpParam;
	long j = 0;
//	CString str;
//	pEdit->GetWindowText(str);
//	j=_ttoi(str);
//	for(int i=0;i<100000;i++)
//	{
//		j++;
//		CString str1;
//		str1.Format(L"%d",j);
//		pEdit->SetWindowText(str1);
//	}

	HANDLE g_hProcessSnap;
	CString strValue = _T("");	

    g_hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

	if (INVALID_HANDLE_VALUE  == g_hProcessSnap) 
    {
        return;
    }

    // Take all the module snapshots - if any of them fails, exit...
    // This will make the snapshot operation as a whole seem atomic
    PROCESSENTRY32 pe32 = {0};
	pe32.dwSize = sizeof(PROCESSENTRY32);
	if (TRUE == Process32First(g_hProcessSnap, &pe32)) 
	{
	    do
		{
			strValue.Format(_T("%s"),pe32.szExeFile);
			pList->AddString(strValue);

		}while (Process32Next(g_hProcessSnap, &pe32));
	}

//	do {
//		if( j> 100000)
//		{
//			break;
//		}
//		
//		strValue.Format(_T("%d"),j);
//		pList->InsertString(j,strValue);
//		j++;
//		
//	} while(!IsRun(_T("PARK.EXE")));

}
CMemoryDemoDlg::CMemoryDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMemoryDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMemoryDemoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMemoryDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMemoryDemoDlg)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMemoryDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CMemoryDemoDlg)
	ON_BN_CLICKED(IDC_BTN_START, OnBtnStart)
	ON_BN_CLICKED(IDC_BTN_END, OnBtnEnd)
	ON_BN_CLICKED(IDC_BTN_PAUSE, OnBtnPause)
	ON_BN_CLICKED(IDC_BTN_RESTART, OnBtnRestart)
	//}}AFX_MSG_MAP
	ON_MESSAGE (WMMSG_CLOSE_GPS, OnReleaseGPS)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemoryDemoDlg message handlers

BOOL CMemoryDemoDlg::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
// 	::MoveWindow(this->m_hWnd,0,0,240,160,TRUE);
	CMemoryDemoApp* ptheApp = (CMemoryDemoApp*) AfxGetApp();
	if(ptheApp->m_bIsOpenGPS)
	{
		GetDlgItem(IDC_LABEL)->SetWindowText(_T("GPS is Opened by MemoryDemo1"));
	}
	else
	{
		GetDlgItem(IDC_LABEL)->SetWindowText(_T("MemoryDemo1: Failed to open GPS."));
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}
HRESULT CMemoryDemoDlg::OnReleaseGPS(WPARAM wParam, LPARAM lParam)
{
	CMemoryDemoApp* ptheApp = (CMemoryDemoApp*)AfxGetApp();
	if(ptheApp->ReleaseGPS())
	{
		GetDlgItem(IDC_LABEL)->SetWindowText(_T("Got it, GPS has been released by MemoryDemo1"));
	}
	else
	{
		GetDlgItem(IDC_LABEL)->SetWindowText(_T("Got it, MemoryDemo1:failed to release GPS"));
	}
	return S_OK;
}

void CMemoryDemoDlg::OnBtnStart() 
{
//	if(hThread)
//		TerminateThread(hThread,dwThreadId);
//
//	hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)lpRecvProc,&m_list,0,&dwThreadId);
//	if(hThread==NULL)
//		AfxMessageBox(L"创建线程失败!");
	double      dblHDOP ;
	HKEY		_hkey	;
	DWORD		dwType	;
	DWORD		dwSize	;
//	WCHAR		dataX[32];
//	WCHAR		dataY[32];
//@@@#ADD  2006-7-13  Xiangjun Han
	WCHAR		dataHDOP[32];
//@@@#ADD  2006-7-13  Xiangjun Han
	
	DWORD		isActive = 0;
	
	if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER,
										TEXT("MioMap\\GPS"),
										0,0,&_hkey))
	{
		//::MessageBox(NULL,L"uu1",L"uu1",MB_OK);
		return;
	}
	else
	{
		//dwType = REG_SZ;
		BOOL bSuccX = FALSE;
		BOOL bSuccY = FALSE;
//@@@#ADD  2006-7-13  Xiangjun Han
		BOOL bSuccHDOP = FALSE;
//@@@#ADD  2006-7-13  Xiangjun Han
		dwType = 0;
		dwSize = sizeof(DWORD);
		if (ERROR_SUCCESS==RegQueryValueEx(  _hkey,              // subkey handle 
			TEXT("isActive"),              // value name 
			0,                 // must be zero 
			&dwType,            // value type 
		   (LPBYTE)&isActive,        // pointer to value data 
			&dwSize))    // length of value data 
		{
			;
		}

		if(!isActive)
		{
//@@@#ADD  2006-7-13  Xiangjun Han
			dwType = 0;
			dwSize = sizeof(dataHDOP);
			if (ERROR_SUCCESS==RegQueryValueEx(  _hkey,              // subkey handle 
				TEXT("HDOP"),              // value name 
				0,                 // must be zero 
				&dwType,            // value type 
			   (LPBYTE)dataHDOP,        // pointer to value data 
				&dwSize))    // length of value data 
			{
				bSuccHDOP = TRUE;
			}

			if(bSuccHDOP)
			{
				char szTempHDOP[100];
				wcs2ansi(szTempHDOP,dataHDOP,100);
				dblHDOP = atof(szTempHDOP);
				if(atof(szTempHDOP) > 10.0f)
				{
					return;
				}
			}

//@@@#ADD  2006-7-13  Xiangjun Han

		}
		RegCloseKey(_hkey);

	}
}

void CMemoryDemoDlg::OnBtnEnd() 
{
//	if(hThread)
//		TerminateThread(hThread,dwThreadId);
		CString strValue = _T("3167.7467");
//		char _str[50];
//		_str = (LPTSTR)(LPCTSTR)strValue;
// 		strcpy(_str,(const char*)(LPCTSTR)strValue);
		wchar_t *stopscan; 

		wchar_t* _str = (LPTSTR)(LPCTSTR)strValue; 
		double dblValue = 0.0f;
// 		sprintf(_str,"%s","3167.7467");
		wchar_t *pt = wcschr(_str, '.');
		if (!pt)
		{
			dblValue = 8.0f;
		}
			
		USHORT	unDeg;
		USHORT	unMin;
		USHORT	unSec;
		USHORT	unMSec;
		int nMin = _wtol(_str);
		unDeg = nMin / 100;
		unMin = nMin - unDeg * 100;
		
		double fVal = wcstod(pt,&stopscan);
		double fSec = fVal * 60.;
		unSec = (int) fSec;
		unMSec = (int) ((fSec - (double)unSec) * 1000. + .5);
		dblValue = (double)unDeg + (double)unMin/60. + fVal/60.;
	
}

void CMemoryDemoDlg::OnBtnPause() 
{
	if(hThread)
		SuspendThread(hThread);	
}

void CMemoryDemoDlg::OnBtnRestart() 
{
	if(hThread)
		ResumeThread(hThread);
	
}

⌨️ 快捷键说明

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