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

📄 myproject.cpp

📁 采用Platform Builder编写的多线程程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// Myproject.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "Myproject.h"
#include "ini.h"
#include <windows.h>
#include <commctrl.h>

#include "Shellapi.h"  //SHLoadDIBitmap()函数
#include "Mmsystem.h"

#include "winbase.h"  
#include "math.h"

#include "Mmsystem.h"

//#include <string.h>

#include <Winuser.h>
#include <stdio.h>//printf()函数
#include "stdlib.h"  //atoi()函数
#include "Winnls.h"
   DWORD t1,t2,t3,t4;//用于测试程序运行时间

//*************可能需要修改的变量**************************

   int PicType=1;//图像类型标志 1:bmp  2:jpg
   LPCTSTR BLKMapName1=TEXT("\\硬盘\\MAP\\BLK.bmp");//空海图文件
   LPCTSTR BLKMapName2=TEXT("\\硬盘\\MAP\\land.bmp");//空海图文件
   //haitu.INI文件    (注:根据INI文件的具体位置修改)
   char* haituINI = "\\硬盘\\INI\\Haitu.ini";
   LPCTSTR LPhaituINI=TEXT("\\硬盘\\INI\\Haitu.ini");

   const int picHeight = 690;// 单幅图片的高度和宽度(单位:象素点)
   const int picWidth  = 921;
   const int PicBoxWidth=650;// picbox宽 (单位:象素)
   const int PicBoxHeight=500;//picbox高
   const int xGap=200+PicBoxWidth/2;//水平方向(Center.x,Center.y)到NotLoadBox的距离   
   const int yGap=200+PicBoxHeight/2;//垂直方向(Center.x,Center.y)到NotLoadBox的距离
  
   const int Hdcnum=17;//17个设备环境变量
   
   const TCHAR PrePicName[]=TEXT("\\硬盘\\MAP\\HT100\\100");//海图文件名前缀  (注:根据海图具体存放位置修改)

//*****************固定不变的变量*******************************
 
   ////////////////////////////////////////////////////////////////////////
   ////////////////       以下为JPEG专用      ///////////////////////
    HDC         hdc;//全局设备变量
	HBITMAP		m_hbitmap=NULL;//位图句柄
    HDC	        g_hdc[Hdcnum];   //A global compatible HDC 调入图像时用
    HDC         g_hdc6,g_hdc7,g_hdc10,g_hdc11;   //A global compatible HDC 显示图像时用
    TCHAR       *StrPicName0;//海图文件名
    
	int         CenterAtPicPart;//(Center.x,Center.y)在pic的位置, 1:左上部 2:右上部  3:左下部   4:右下部
	BOOL        AllPicLoaded=false;  //是否所有的图像都导入内存
  /////////////////////////////////////////////////////////////////////
  
  //////////////////////////////////////////////////////////////   
  const TCHAR szAppName[] = TEXT ("ShipLocSystem");         // Application main window name
  const TCHAR  szClassName[] = TEXT ("Main window class");   // Main window class name
  HINSTANCE   hInst = NULL;     // Handle to the application instance
  HWND        hwndMain = NULL;       // Handle to the application main window

  /////////////////DefLocSet() 函数
  TCHAR a_tchar[]=TEXT("你好,HELLO");
  
  TCHAR*   MapName_TCHAR;
  TCHAR*   JingDu_TCHAR;
  TCHAR*   WeiDu_TCHAR;
  ////////////////////////////////////////////////////

  double LeftJingDu,BottomWeiDu;   //同一比例的未分割地图的上下左右的经纬度
  double PicJingDuGap,PicWeiDuGap; //单幅图像的经度间隔、纬度间隔
  //以上6个为经纬度值

  POINT Cross;//4幅图像拼接的点的坐标
  POINT Center={0,0};
  //从INI文件读取的初始位置。注:相对于大图的左下角(0,0)而言
  //即经纬度值转化为象素坐标后的位置  '并且该位置作为显示的中心
  //也可以是从GPS接收到的位置信息

  bool MouseDownToMovePicture=false; //是否漫游图像 开关
  int intXnumth, intYnumth; // '存放输入的位置在大图中的 行第几、列第几幅
  //  TCHAR  *yName,*xName;//   '存储图像文件的  y方向、x方向的文件名 
  
  int tag_intXnumth,tag_intYnumth; //当前4幅图中,左下角图的行列号数


  RECT pic;//定义目标图pic的 4个顶角 相对于大图的左下角(0,0)的位置(单位为:象素)
  RECT box;// 定义显示区域box的 4个顶角 相对于大图的左下角(0,0)的位置(单位为:象素)
  RECT rect;//显示图像的客户区域
  RECT NotLoadBox;//不装载图像的区域


  //---------------------------------------------------


 
  //double InputJingDu;//一开机的经纬度
  //double InputWeiDu;
  //double DefJingDu,DefWeiDu;//一开始从INI文件读取的缺省经纬度、或者一开机最先从GPS采集到的经纬度
  



//Dim strJingWeiDu  As String  '存放用户一开始输入的经纬度值



/* ////////////  5.21日   /////////////////////////////////////////

Dim strMapPath  As String
Dim intCompressRate  As Integer '图像缩放比例




  

'存放大图中,行、列下标的最大值,即00、01、02......intXnummax(有多少幅图像)
                               '或00、01、02......intYnummax
                               '用于控制文件名不会“溢出”
Const intYnummax As Integer = 10
Const intXnummax As Integer = 10

*/








//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------

// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
    WM_CREATE, DoCreateMain,
	WM_PAINT, DoPaintMain,
	WM_COMMAND, DoCommandMain,
	WM_DESTROY, DoDestroyMain,
	WM_LBUTTONDOWN, DoLButtonDownMain,

	
	
	//WM_INITMENUPOPUP, DoInitMenuPopMain, 
	//WM_SIZE, DoSizeMain,

};


// Command Message dispatch for MainWindowProc
const struct decodeCMD MainCommandItems[] = {
    ID_DlgDefLocSet, DoMainCommandDefLocSet,
    ID_EXIT, DoMainCommandExit,
    ID_MoveTest,DoMainCommandMoveTest,
	ID_MapRandom,DoMainCommandMapRandom,

};  
//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
//FUNCTION: 
//  WinMain
//PURPOSE: 
//  The WinMain function of the application. It is called by the system as
//  the initial entry point for this Windows CE-based application.

int WINAPI WinMain (
               HINSTANCE hInstance,     // Handle to the current instance
               HINSTANCE hPrevInstance, // Handle to the previous instance
               LPWSTR lpCmdLine,        // Pointer to the command line
               int nCmdShow)            // Shows the state of the window
{
    MSG msg;                             // Message structure
    int rc=0;
    HACCEL hAccel;                       // Handle of the accelerator 
                                      // table

   //创建读取GPS串口的线程
	HANDLE hThread;
	                    //LPVOID  nParameter;//=(LPVOID)5;
	LPDWORD lpThreadId=0;	 	 
	                  //创建读取GPS串口的线程
	hThread=CreateThread(NULL,0,ReadGPSSerialThread,(LPVOID)0,0,lpThreadId);CloseHandle(hThread);
		
  
   // Use this code to prevent your application from starting twice
   // assuming that your application has not changed its window text
   if (FindWindow(szClassName, szAppName))
   {
        SetForegroundWindow(FindWindow(szClassName, szAppName));
        return FALSE;
   }

   //Initialize application
    rc=InitApp(hInstance);
   if(rc) return rc;
   // Initialize this instance.
   hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);
   if (hwndMain == 0)
        return FALSE;

   //Load accelerator table
   hAccel=LoadAccelerators(hInst,MAKEINTRESOURCE(ID_ACCEL));
  
   OnInitial();
  //Application message loop
  while (GetMessage (&msg, NULL, 0, 0))
  {
    if (!TranslateAccelerator (
                    hwndMain,     // Handle to the destination window
                    hAccel,         // Handle to the accelerator table
                    &msg))          // Address of the message data
    {
      TranslateMessage (&msg);
      DispatchMessage (&msg);
    }
  }
  
  return  msg.wParam;//clean up instance  
}
 
//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
//FUNCTION: 
//  InitApplication
//PURPOSE:
//  Declare the window class structure, assign values to the window class
//  structure members, and register the window class.


int InitApp(HINSTANCE hInstance)
{
  WNDCLASS wndclass;//定义窗口类并注册

  wndclass.style =CS_HREDRAW | CS_VREDRAW;
  wndclass.lpfnWndProc = MainWndProc;
  wndclass.cbClsExtra = 0;
  wndclass.cbWndExtra = 0;
  wndclass.hIcon =NULL;
  wndclass.hInstance = hInstance;
  wndclass.hCursor =NULL;
  wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);//GRAY_BRUSH
  wndclass.lpszMenuName =NULL;
  wndclass.lpszClassName = szAppName;
  
  if( RegisterClass (&wndclass)==0) return 1;
  return 0;
}


//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow) {
    HWND hWnd;

    // Save program instance handle in global variable.
    hInst = hInstance;

    // Create main window.
    hWnd = CreateWindow (szAppName,           // Window class
                         TEXT ("船舶定位系统"),    // Window title
                         WS_VISIBLE,          // Style flags
                         CW_USEDEFAULT,       // x position
                         CW_USEDEFAULT,       // y position
                         CW_USEDEFAULT,       // Initial width
                         CW_USEDEFAULT,       // Initial height
                         NULL,                // Parent                
                         NULL,                // Menu, must be null
                         hInstance,           // Application instance
                         NULL);               // Pointer to create
                                              // parameters
    // Return fail code if window not created.
    if (!IsWindow (hWnd)) return 0;

    // Standard show and update calls
    ShowWindow (hWnd, nCmdShow); 
	UpdateWindow (hWnd);//去掉第一次刷新
    return hWnd;
}



//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
//FUNCTION: 
//  WndProc
//PURPOSE: 
//  The callback function for the main window. It processes messages that
//  are sent to the main window.


LRESULT CALLBACK MainWndProc (HWND hWnd, UINT umsg, WPARAM wParam, 
                          LPARAM lParam)
{

	int i;
	//search message list to see if we need to handle this message
	//if in list,call procedure

	for(i=0;i<dim(MainMessages);i++)
	{
		if(umsg==MainMessages[i].Code)
			return(*MainMessages[i].Fxn)(hWnd,umsg,wParam,lParam);
	}
	return DefWindowProc(hWnd,umsg,wParam,lParam);

}




//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
// DoCreateMain - Process WM_CREATE message for window.
//
LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                      LPARAM lParam) {
    
	HWND hwndCB;
    HICON hIcon;

    // Create a command bar.
    hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
    // Add the menu.
    CommandBar_InsertMenubar (hwndCB, hInst, ID_MENU, 0);
    // Add exit button to command bar. 
    CommandBar_AddAdornments (hwndCB, 0, 0);

    hIcon = (HICON) SendMessage (hWnd, WM_GETICON, 0, 0);
    if (hIcon == 0) {
         hIcon = LoadIcon (hInst, MAKEINTRESOURCE(ID_ICON));                       
        SendMessage (hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
    }

	   
	//调用初始化函数
	//OnInitial();
	/////////////////////////////////////  
    return 0;
}

//------------------------------------------------------------------------
//-------------------------------------------------------------------------
//---------------------------------------------------------------------
// fDoPaintMain - Process WM_PAINT message for window.
//            
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                     LPARAM lParam) 
{
	PAINTSTRUCT ps;
	BeginPaint (hWnd, &ps); 

⌨️ 快捷键说明

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