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

📄 gpswin32.cpp.bak

📁 GPS 读取数据处理模块源程序
💻 BAK
📖 第 1 页 / 共 4 页
字号:
// gpswin32.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "gpswin32.h"
#include "Winbase.h"

#include"Imm.h"
#include <windows.h>
#include <commctrl.h>

#include "GpsGaussConvert.h"


#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE			g_hInst;			// current instance
HWND				g_hWndMenuBar;		// menu bar handle
HWND g_hWnd;

HANDLE s_hExitThread = NULL;
#define MAX_WAIT    5000
#define MAX_AGE     3000
#define GPS_CONTROLLER_EVENT_COUNT 1
#define GPS_COM_MASK (EV_RXCHAR | EV_RLSD | EV_ERR | EV_BREAK)
#define ueseddataSize   30
#define GPGGA_DataSize 256


// Thread Info
HANDLE m_hThread = NULL;
DWORD m_dwThreadID = 0;
int GPSNums = 0;
int GPSNum2 = 0;

TCHAR g_Time[MAX_LOADSTRING];	
TCHAR g_Day[MAX_LOADSTRING];
TCHAR g_Month[MAX_LOADSTRING];
TCHAR g_Year[MAX_LOADSTRING];
TCHAR g_Latitude[MAX_LOADSTRING];
TCHAR g_Longitude[MAX_LOADSTRING];
TCHAR g_Altitude[MAX_LOADSTRING];
TCHAR g_X[MAX_LOADSTRING];
TCHAR g_Y[MAX_LOADSTRING];

BOOL GPS_Located = 0;
int fristreadsize = 0,secondreadsize = 0,times = 0;
unsigned char  Com3Buffer[1024],ReadGPSdata[260];



// Forward declarations of functions included in this code module:
ATOM			MyRegisterClass(HINSTANCE, LPTSTR);
BOOL			InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

BOOL    SendSMS();
LPCWSTR Make_SmsData();

LPCWSTR Make_Data();

BOOL    RunApp(LPCWSTR szAppPath, LPCWSTR szCmdLine);
void initControl();
HRESULT Showtext();
HRESULT ShowData();
HRESULT LoadThread();
HRESULT UnloadThread();
DWORD WINAPI GPSThreadProc(__opt LPVOID lpParameter);

//add gps dirver.........................................................

HANDLE	g_PWR_serialCOMHandle = NULL;
typedef struct
{
	unsigned char GPSTime[20];
	unsigned char GPSLatitude[50];
	unsigned char GPSNS;
	unsigned char GPSLongitude[50];
	unsigned char GPSEW;
	unsigned char GPSFS;
	unsigned char GPSmsl[50];
	unsigned char GPSNum[2];
} GPSGGA ,*pGPSGGA;
typedef struct
{
	//unsigned char GPSTime[20];
	unsigned char GPSDay[20];
	unsigned char GPSMonth[20];
	unsigned char GPSYear[20];
	
} GPSZDA ,*pGPSZDA;

typedef struct 
{
	double Time;
	double Latitude;
	//char NS;
	double Longitude;
	//char EW;
	char FS;
	double Msl;
	double x;
	double y;
} GGA ,*pGGA;

BOOL InitportCOM3();
BOOL WriteDataSerialPort();
//DWORD RequestCom3Thread(LPVOID pParam);
DWORD ReadCom3Thread(LPVOID pParam);
BOOL WINAPI Readcom3date();
BOOL WINAPI Readcom3datezda();

double Latitude(unsigned char GPGGA_ueseddata[],int GPGGA_ueseddataSize);
BOOL WriteRequestCommand();
BOOL WriteRequestCommandzda();


//add gps dirver.........................................................
//add gps transfer......................................................
void GaussConvert(double dwLongitude, double dwLatitude, double dwHeight, double &dwX, double &dwY);
//add gps transfer......................................................




/*
void CALLBACK TimerProc(
       HWND hWnd, 
      UINT uMsg, 
      UINT idEvent, 
      DWORD dwTime  
    );
**/

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	MSG msg;
	/*
 BOOL vu;
 vu = ImmDisableIME(0);
 **/
	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}
#ifndef WIN32_PLATFORM_WFSP

	HACCEL hAccelTable;
	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_GPSWIN32));
#endif

 



	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

     UnloadThread();

	return (int) msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GPSWIN32));
	wc.hCursor       = 0;
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = szWindowClass;

	return RegisterClass(&wc);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hWnd;
    TCHAR szTitle[MAX_LOADSTRING];		// title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];	// main window class name

    g_hInst = hInstance; // Store instance handle in our global variable

    // SHInitExtraControls should be called once during your application's initialization to initialize any
    // of the device specific controls such as CAPEDIT and SIPPREF.
    SHInitExtraControls();

    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
    LoadString(hInstance, IDC_GPSWIN32, szWindowClass, MAX_LOADSTRING);

    //If it is already running, then focus on the window, and exit
    hWnd = FindWindow(szWindowClass, szTitle);	
    
    if (hWnd) 
    {
        // set focus to foremost child window
        // The "| 0x00000001" is used to bring any owned windows to the foreground and
        // activate them.
        SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
        return 0;
    } 

    if (!MyRegisterClass(hInstance, szWindowClass))
    {
    	return FALSE;
    }

    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
        return FALSE;
    }
    g_hWnd = hWnd;    // Store hwnd in our global variable
    // When the main window is created using CW_USEDEFAULT the height of the menubar (if one
    // is created is not taken into account). So we resize the window after creating it
    // if a menubar is present
    if (g_hWndMenuBar)
    {
        RECT rc;
        RECT rcMenuBar;

        GetWindowRect(hWnd, &rc);
        GetWindowRect(g_hWndMenuBar, &rcMenuBar);
        rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
		
        MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
    }

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    
    Showtext();
    HRESULT hr = E_FAIL;
    //InitportCOM3();
    //WriteDataSerialPort();
    hr = LoadThread();
    if (FAILED(hr))
    {
       goto Exit;
    }   
    return TRUE;
    Exit:
    if (FAILED(hr))
    {
        UnloadThread();
    }
    return FALSE;
   
}


/**    
     UINT nIDEvent = 1;
     UINT uElapse = 2000;
  
 
    SetTimer(
    hWnd, 
    nIDEvent, 
    uElapse, 
    TimerProc 
 ); 

 */
/*
void CALLBACK TimerProc(
       HWND hWnd, 
      UINT uMsg, 
      UINT idEvent, 
      DWORD dwTime  
    )
     {
     ShowData( hWnd);
         UpdateWindow(hWnd);
         KillTimer(
         hWnd, 
         idEvent 
         ); 

    }
**/
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    static SHACTIVATEINFO s_sai;
	
    switch (message) 
    {
        case WM_COMMAND:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            // Parse the menu selections:
            switch (wmId)
            {
                case IDM_SEND:
			              SendSMS();
                   //DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
                    break;
                case IDM_OK:
                    SendMessage (hWnd, WM_CLOSE, 0, 0);				
                    break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;
        case WM_CREATE:
            SHMENUBARINFO mbi;

            memset(&mbi, 0, sizeof(SHMENUBARINFO));
            mbi.cbSize     = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hWnd;
           mbi.nToolBarId = IDR_MENU;
            mbi.hInstRes   = g_hInst;

            if (!SHCreateMenuBar(&mbi)) 
            {
                g_hWndMenuBar = NULL;
            }
            else
            {
                g_hWndMenuBar = mbi.hwndMB;
            }
            //ShowData(hWnd);
            // Initialize the shell activate info structure
            memset(&s_sai, 0, sizeof (s_sai));
            s_sai.cbSize = sizeof (s_sai);
           
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            if(GPS_Located)
             {
             ShowData();
            }
            else
            {
            Showtext();
            }
            
            // TODO: Add any drawing code here...
            
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            CommandBar_Destroy(g_hWndMenuBar);
            PostQuitMessage(0);
            break;

        case WM_ACTIVATE:
            // Notify shell of our activate message
            SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
            break;
        case WM_SETTINGCHANGE:
            SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
            {
                // Create a Done button and size it.  
                SHINITDLGINFO shidi;
                shidi.dwMask = SHIDIM_FLAGS;
                shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
                shidi.hDlg = hDlg;
                SHInitDialog(&shidi);
            }
            return (INT_PTR)TRUE;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                EndDialog(hDlg, LOWORD(wParam));
                return TRUE;
            }
            break;

        case WM_CLOSE:
            EndDialog(hDlg, message);
            return TRUE;

    }
    return (INT_PTR)FALSE;
}

BOOL    SendSMS()
{
    
	TCHAR tCmdLine[200];
 
#if 0
char data[10] = {'E','I','G','P','Q',',','Z','D','A'};
    char sum = 0;
    int i;
	for ( i=0;i<9;i++)
	  sum ^=data[i];

	printf("%x",sum);
#endif
 

	LPCWSTR szAppName = L"tmail";
    
	wcscpy(tCmdLine, L"-service \"SMS\" -subject \"");

⌨️ 快捷键说明

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