📄 gpswin32.cpp.bak
字号:
LPCWSTR pData;
pData = Make_SmsData();
wcscat(tCmdLine,pData);
wcscat(tCmdLine, L"\"");
//wcscpy(szFormat, L"UTC Time:\nLatitude:\nLongitude:\nMSL Altitude:\nX:\nY:\n");
/*
wcscat(tCmdLine, L"gps location");
wcscat(tCmdLine, L"\"");
wcscat(tCmdLine, L"-body \"");
**/
if( !RunApp(szAppName, tCmdLine))
{
return FALSE;
}
return TRUE;
}
LPCWSTR Make_Data()
{
TCHAR szTime[MAX_LOADSTRING];
TCHAR szLatitude[MAX_LOADSTRING];
TCHAR szLongitude[MAX_LOADSTRING];
TCHAR szAltitude[MAX_LOADSTRING];
TCHAR szX[MAX_LOADSTRING];
TCHAR szY[MAX_LOADSTRING];
TCHAR szData[200];
LoadString(g_hInst, IDS_Time, szTime, MAX_LOADSTRING);
LoadString(g_hInst, IDS_Latitude, szLatitude, MAX_LOADSTRING);
LoadString(g_hInst, IDS_Longitude, szLongitude, MAX_LOADSTRING);
LoadString(g_hInst, IDS_Altitude, szAltitude, MAX_LOADSTRING);
LoadString(g_hInst, IDS_X, szX, MAX_LOADSTRING);
LoadString(g_hInst, IDS_Y, szY, MAX_LOADSTRING);
wcscpy(szData, szTime);
wcscat(szData, g_Time);
wcscat(szData, L" hhmmss.sss");
wcscat(szData, L"\n");
wcscat(szData, szLatitude);
wcscat(szData, g_Latitude);
wcscat(szData, L" ddmm.mmmm");
wcscat(szData, L"\n");
wcscat(szData, szLongitude);
wcscat(szData, g_Longitude);
wcscat(szData, L" dddmm.mmmm");
wcscat(szData, L"\n");
wcscat(szData, szAltitude);
wcscat(szData, g_Altitude);
wcscat(szData, L" m");
wcscat(szData, L"\n");
wcscat(szData, szX);
wcscat(szData, g_X);
wcscat(szData, L"\n");
wcscat(szData, szY);
wcscat(szData, g_Y);
wcscat(szData, L"\n");
return szData;
}
LPCWSTR Make_SmsData()
{
TCHAR szData[200];
wcscpy(szData, L"2#M101#军事指挥所");
wcscat(szData, g_X);
wcscat(szData, L"#");
wcscat(szData, g_Y);
wcscat(szData, L"#");
wcscat(szData, g_Altitude);
wcscat(szData, L"#300#300#");
wcscat(szData, g_Time);
//wcscat(szData, L" hhmmss.sss");
wcscat(szData, L"#上级通报#");
return szData;
}
BOOL RunApp(LPCWSTR szAppPath, LPCWSTR szCmdLine)
{
PROCESS_INFORMATION P;
LPDWORD lpExitCode=NULL;
UINT uFlag=1;
BOOL fSucess;
fSucess = CreateProcess( szAppPath,
szCmdLine,
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
NULL,
&P );
if (fSucess)
{
CloseHandle(P.hThread);
CloseHandle(P.hProcess);
return TRUE;
}
else
{
return FALSE;
}
}
#if 0
void initControl()
{
CString str;
/*
str.LoadString(IDS_TITLE_SETTINGPASSWORD);
SetWindowText(str);
**/
CRect rt, rtLabel;
CRect rtEdit;
CEdit m_Edit1;
CEdit m_Edit2;
CEdit m_Edit3;
CStatic m_Static1;
CStatic m_Static2;
CStatic m_Static3;
GetClientRect(&rt);
rtLabel.SetRect(rt.left, rt.top, rt.right, rt.bottom / 9);
HWND hwnd = m_Static1.Create(m_hWnd, &rtLabel, L"", WS_CHILD | WS_VISIBLE
| ES_AUTOHSCROLL);
str.LoadStringW(IDS_OLD_PASSWORD);
m_Static1.SetWindowTextW(str);
rtEdit.SetRect(rt.left, rtLabel.bottom, rt.right, rt.bottom*2/9);
m_Edit1.Create(m_hWnd, &rtEdit, NULL, WS_CHILD | WS_VISIBLE|WS_TABSTOP|ES_NUMBER|WS_BORDER,0,IDC_EDIT1);
m_Edit1.SetFocus();
rtLabel.SetRect(rt.left, rt.bottom*2/9, rt.right, rt.bottom /3);
hwnd = m_Static2.Create(m_hWnd, &rtLabel, L"", WS_CHILD | WS_VISIBLE
| ES_AUTOHSCROLL);
str.LoadStringW(IDS_NEW_PASSWORD);
m_Static2.SetWindowTextW(str);
rtEdit.SetRect(rt.left, rt.bottom/3,rt.right, rt.bottom*4/9);
m_Edit2.Create(m_hWnd, &rtEdit, NULL, WS_CHILD | WS_VISIBLE|ES_NUMBER|WS_TABSTOP|ES_NUMBER|WS_BORDER,0,IDC_EDIT1+1);
rtLabel.SetRect(rt.left, rt.bottom*4/9, rt.right, rt.bottom*5/9);
hwnd = m_Static3.Create(m_hWnd, &rtLabel, L"", WS_CHILD | WS_VISIBLE
| ES_AUTOHSCROLL);
str.LoadStringW(IDS_CHECK_PASSWORD);
m_Static3.SetWindowTextW(str);
rtEdit.SetRect(rt.left, rt.bottom*5/9,rt.right, rt.bottom*2/3);
m_Edit3.Create(m_hWnd, &rtEdit, NULL, WS_CHILD | WS_VISIBLE|ES_NUMBER|WS_TABSTOP|ES_NUMBER|WS_BORDER,0,IDC_EDIT1+2);
}
#endif
HRESULT ShowData()
{
HRESULT hr = E_FAIL;
BOOL bRet = FALSE;
INT dwRet = 0;
INT iRet = 0;
HWND hWnd = g_hWnd;
// HWND hWnd = NULL;
HDC hdc = NULL;
RECT rt = {0};
INT iFontSizePixel = 0;
LONG lHeightAdjust = 0;
WCHAR wszTmp[MAX_PATH] = L"";
//hWnd = FindWindow(L"MOBILEGPS", L"MobileGPS");
hdc = GetDC(hWnd);
bRet = GetClientRect(hWnd, &rt);
//SetRectEmpty(&rt);
HBRUSH hBrush; // Handle to a brush objec
hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
FillRect(hdc, &rt, hBrush);
hr = SHGetUIMetrics(SHUIM_FONTSIZE_PIXEL,
&iFontSizePixel,
sizeof(iFontSizePixel),
NULL);
if (rt.bottom < iFontSizePixel * 12)
{
iRet = DrawText(hdc, L"Not enough Space", -1, &rt, DT_CENTER);
goto Exit;
}
LPCWSTR pData;
pData = Make_Data();
rt.top += iFontSizePixel;
iRet = DrawText(hdc, pData, -1, &rt, DT_CENTER);
#if 0
// draw Time
rt.top += iFontSizePixel;
wcscpy(szFormat, szTime);
wcscat(szFormat, L": %s hhmmss.ss");
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szFormat,
g_Time);
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
// draw Latitude
rt.top += iFontSizePixel * 2;
wcscpy(szFormat, szLatitude);
wcscat(szFormat, L": %s ddmm.mmmm");
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szFormat,
g_Latitude);
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
// draw Longitude
rt.top += iFontSizePixel * 2;
wcscpy(szFormat, szLongitude);
wcscat(szFormat, L": %s ddmm.mmmm");
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szFormat,
g_Longitude);
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
// draw Altitude
rt.top += iFontSizePixel * 2;
wcscpy(szFormat, szAltitude);
wcscat(szFormat, L": %s m");
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szFormat,
g_Altitude);
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
// draw X
rt.top += iFontSizePixel * 2;
wcscpy(szFormat, szX);
wcscat(szFormat, L": %s");
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szFormat,
g_X);
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
// draw Y
rt.top += iFontSizePixel * 2;
wcscpy(szFormat, szY);
wcscat(szFormat, L": %s");
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szFormat,
g_Y);
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
#endif
hr = S_OK;
Exit:
ReleaseDC(hWnd, hdc);
return hr;
}
HRESULT Showtext()
{
HRESULT hr = E_FAIL;
BOOL bRet = FALSE;
INT dwRet = 0;
INT iRet = 0;
HWND hWnd = g_hWnd;
// HWND hWnd = NULL;
HDC hdc = NULL;
RECT rt = {0};
INT iFontSizePixel = 0;
LONG lHeightAdjust = 0;
WCHAR wszTmp[MAX_PATH] = L"";
TCHAR szGpsL[MAX_LOADSTRING];
LoadString(g_hInst, IDS_GpsL, szGpsL, MAX_LOADSTRING);
//hWnd = FindWindow(L"MOBILEGPS", L"MobileGPS");
hdc = GetDC(hWnd);
bRet = GetClientRect(hWnd, &rt);
hr = SHGetUIMetrics(SHUIM_FONTSIZE_PIXEL,
&iFontSizePixel,
sizeof(iFontSizePixel),
NULL);
if (rt.bottom < iFontSizePixel * 8)
{
iRet = DrawText(hdc, L"Not enough Space", -1, &rt, DT_CENTER);
goto Exit;
}
rt.top += iFontSizePixel*4;
StringCchPrintfEx(wszTmp,
sizeof(wszTmp)/sizeof(wszTmp[0]),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
szGpsL,
L"");
iRet = DrawText(hdc, wszTmp, -1, &rt, DT_CENTER);
hr = S_OK;
Exit:
ReleaseDC(hWnd, hdc);
return hr;
}
HRESULT UnloadThread()
{
HRESULT hr = E_FAIL;
BOOL bRet = FALSE;
DWORD dwRet = 0;
// Instruct the thread to unload
// There is not much one can do if set event failed
// Ignore the failure and continue unloading
bRet = SetEvent(s_hExitThread);
if (!bRet)
{
dwRet = GetLastError();
hr = HRESULT_FROM_WIN32(dwRet);
goto Exit;
}
dwRet = WaitForSingleObject(m_hThread, MAX_WAIT);
if(WAIT_OBJECT_0 != dwRet)
{
dwRet = GetLastError();
hr = HRESULT_FROM_WIN32(dwRet);
goto Exit;
}
hr = S_OK;
Exit:
if (s_hExitThread)
{
CloseHandle(s_hExitThread);
s_hExitThread = NULL;
}
if (m_hThread)
{
CloseHandle(m_hThread);
m_hThread = NULL;
}
return hr;
}
// **************************************************************************
// Function Name: CGPSController:LoadThread
//
// Purpose: Initialize the variables to be used by GPSThreadProc then
// create the thread
//
// Arguments:
// None
//
// Return Values:
// HRESULT: S_OK on success
// An appropriate error value on failure
//
//
// Side effects:
// It loads the GPSThreadProc
//
// Description:
// LoadThread intializes 3 events before creating GPSThreadProc.
// s_hNewLocationData : This event is set by the GPS Intermdiate
// driver whenever new location information is
// available
// s_hDeviceStateChange : This event is set by the GPS Intermediate
// driver whenever the GPS hardware state
// changes
// s_hExitThread : Used by CGPSController to instruct
// GPSThreadProc to unload
// **************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -