📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using JustinIO;
namespace mapinfo
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
public System.Windows.Forms.PictureBox pictureBox3;
private System.Windows.Forms.Label title;
public System.Windows.Forms.PictureBox pictureBox4;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
static JustinIO.CommPort comport;
static ulong[,] MapPointInfo; /* 地图坐标信息 */
static string g_filename;
static int g_currentmapplace = 0x00;
static int g_mapnum = 0;
static ulong currentx, currenty;
public System.Windows.Forms.PictureBox GsmModule;
private System.Windows.Forms.ImageList imageList1;
public System.Windows.Forms.PictureBox GpsStatus;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
static System_info sys_info;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.GpsStatus = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.title = new System.Windows.Forms.Label();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.GsmModule = new System.Windows.Forms.PictureBox();
this.imageList1 = new System.Windows.Forms.ImageList();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Size = new System.Drawing.Size(240, 24);
//
// GpsStatus
//
this.GpsStatus.Image = ((System.Drawing.Image)(resources.GetObject("GpsStatus.Image")));
this.GpsStatus.Location = new System.Drawing.Point(160, 0);
this.GpsStatus.Size = new System.Drawing.Size(18, 18);
this.GpsStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.GpsStatus.MouseDown += new System.Windows.Forms.MouseEventHandler(this.GpsStatus_MouseDown);
//
// pictureBox3
//
this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));
this.pictureBox3.Location = new System.Drawing.Point(6, 0);
this.pictureBox3.Size = new System.Drawing.Size(18, 18);
//
// title
//
this.title.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.title.Location = new System.Drawing.Point(40, 2);
this.title.Size = new System.Drawing.Size(56, 16);
//
// pictureBox4
//
this.pictureBox4.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox4.Image")));
this.pictureBox4.Location = new System.Drawing.Point(0, 24);
this.pictureBox4.Size = new System.Drawing.Size(240, 248);
this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox4.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Map_MouseUp);
this.pictureBox4.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Map_MouseMove);
this.pictureBox4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Map_MouseDown);
//
// openFileDialog1
//
this.openFileDialog1.InitialDirectory = "\\data";
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem1);
//
// menuItem1
//
this.menuItem1.MenuItems.Add(this.menuItem2);
this.menuItem1.MenuItems.Add(this.menuItem3);
this.menuItem1.MenuItems.Add(this.menuItem4);
this.menuItem1.Text = "操作";
//
// menuItem2
//
this.menuItem2.Text = "选择地图";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Text = "帮助";
//
// menuItem4
//
this.menuItem4.Text = "退出";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// GsmModule
//
this.GsmModule.Image = ((System.Drawing.Image)(resources.GetObject("GsmModule.Image")));
this.GsmModule.Location = new System.Drawing.Point(120, 0);
this.GsmModule.Size = new System.Drawing.Size(18, 18);
this.GsmModule.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.GsmModule.MouseDown += new System.Windows.Forms.MouseEventHandler(this.GsmModule_MouseDown);
//
// imageList1
//
this.imageList1.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
this.imageList1.Images.Add(((System.Drawing.Image)(resources.GetObject("resource1"))));
this.imageList1.Images.Add(((System.Drawing.Image)(resources.GetObject("resource2"))));
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
//
// pictureBox2
//
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(112, 160);
this.pictureBox2.Size = new System.Drawing.Size(10, 21);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
//
// label1
//
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label1.Location = new System.Drawing.Point(184, 0);
this.label1.Size = new System.Drawing.Size(50, 16);
this.label1.Text = " km/h";
//
// label2
//
this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(176, 0);
this.label2.Size = new System.Drawing.Size(56, 16);
//
// label3
//
this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Location = new System.Drawing.Point(173, 0);
this.label3.Size = new System.Drawing.Size(56, 16);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(230, 267);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.GsmModule);
this.Controls.Add(this.title);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.GpsStatus);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.pictureBox4);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Controls.Add(this.toolBar1);
this.Menu = this.mainMenu1;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.GotFocus += new System.EventHandler(this.Form1_GotFocus);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.menuItem4_Click);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
byte g_currenrMap = 0xff;
bool g_ismousedown = false;
bool g_sysisexit = false;
int x, y;
static Thread trecv;
static bool b_isloadmap = false;
static Form1 form1 = new Form1();
public struct MAPLIST
{
public byte mapindex; //地图编号
public String title; //显示在列表框中的信息
public String mappath; //地图对应的数据路径
};
public static MAPLIST[] maplist = new MAPLIST[10];
public static void Main()
{
/* 初始化 */
sys_info = new System_info();
sys_info.SysInfoInit();
trecv = new Thread(new ThreadStart(ReadThread));
/* 显示地图线程 */
MapPointInfo = new ulong[100, 4];
form1.MapPlaceInit();
form1.MainGetMapBuf(0);
g_currentmapplace = 0x0;
comport = new CommPort();
comport.Open();
trecv.Start();
try
{
Application.Run(form1);
}
catch (Exception e)
{
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
title.BackColor = System.Drawing.Color.CornflowerBlue;
title.Text = "主功能";
GsmModule.Image = imageList1.Images[1];
GpsStatus.Image = imageList1.Images[2];
}
private static void MainMapInit(string _fname)
{
int i = 2;
int j, k, n = 0;
byte[] mappoinginfo;
ulong point, d, m;
FileStream s;
mappoinginfo = new byte[1800];
FileInfo finfo = new FileInfo(_fname);
try
{
s = finfo.Open(FileMode.Open, FileAccess.Read);
}
catch
{
form1.Text = "找不到地图数据文件";
return;
}
if(s.Length > 1800)
{
j = 1800;
}
else
{
j = (int)s.Length;
}
s.Read(mappoinginfo, 0, j);
s.Close();
j = mappoinginfo[0];
k = mappoinginfo[1];
g_mapnum = j*k;
if(g_mapnum >= 100)
{
/* 地图数据错误,停止程序运行*/
form1.Text = "地图数据错误";
return;
}
for(n = 0; n< g_mapnum; n++)
{
point = (ulong)(mappoinginfo[i] & 0xf0);
d = (point >> 4) * 10 + (ulong)(mappoinginfo[i] & 0x0f);
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m = (ulong)((point >> 4) * 100000);
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)(point * 10000);
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 1000;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 100;
i++;
//NO 忽略最低位///
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 10;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point;
i++;
MapPointInfo[n,1] = d * 60 *10000 + m;
point = (ulong)(mappoinginfo[i] & 0xf0);
d = (ulong)(point >> 4) * 100 + (ulong)((mappoinginfo[i] & 0x0f) * 10);
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
d +=( point >> 4);
point = (ulong)(mappoinginfo[i] & 0x0f);
m = (ulong)point * 100000;
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point >> 4) * 10000;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 1000;
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 100;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 10;
i++;
//忽略最低位
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point >> 4);
MapPointInfo[n,0] = d * 60 *10000 + m;
/* 右上角 */
point = (ulong)(mappoinginfo[i] & 0x0f);
d = (ulong)point * 10;
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
d += (ulong)point >> 4;
point = (ulong)(mappoinginfo[i] & 0x0f);
m = (ulong)(point * 100000);
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 10000;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 1000;
i++;
//最低位
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 100;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 10;
i++;
MapPointInfo[n,3] = d * 60 *10000 + m;
point = (ulong)(mappoinginfo[i] & 0x0f);
d = point * 100;
i++;
point = (uint)(mappoinginfo[i] & 0xf0);
d +=( point >> 4) * 10;
point = (ulong)(mappoinginfo[i] & 0x0f);
d += (ulong)point;
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m = (ulong)(point >> 4) * 100000;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 10000;
i++;
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 1000;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point * 100;
i++;
//忽略最低位
point = (ulong)(mappoinginfo[i] & 0xf0);
m += (ulong)(point>>4) * 10;
point = (ulong)(mappoinginfo[i] & 0x0f);
m += (ulong)point;
i++;
MapPointInfo[n,2] = d * 60 *10000 + m;
}
}
//_x 点的经度 _y 点的纬度
static byte MainGetMapNum(ulong _x, ulong _y)
{
int i;
for(i = g_mapnum - 1; i >= 0; i--)
{
if(((_x > MapPointInfo[i, 0]) && (_x < MapPointInfo[i, 2])) &&
((_y > MapPointInfo[i, 1]) && (_y < MapPointInfo[i, 3])))
{
return (byte)(i + 1);
}
}
return 0xFF;
}
private void GsmModule_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
/* 显示当前GSM模块的状态 */
if(sys_info.SysIsGsmOk() == 0)
{
MessageBox.Show("GSM模块状态:" + "正常");
}
else
{
MessageBox.Show("GSM模块状态:" + "不正常");
}
}
private void GpsStatus_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
/* 显示当前GSM模块的状态 */
return;
if(sys_info.SysIsGpsOk()== 0)
{
MessageBox.Show("GPS模块状态:" + "正常");
}
else
{
MessageBox.Show("GPS模块状态:" + "不正常");
}
}
private void Map_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
g_ismousedown = true;
x = e.X;
y = e.Y;
}
static Bitmap b = null;
private void Map_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
g_ismousedown = false;
}
// int g_movenum = 0;
private void Map_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
/*
if(g_ismousedown == true)
{
g_movenum ++;
if(g_movenum > 10)
{
g_movenum = 0;
}
else
{
return;
}
if(pictureBox4.Left > (240 - pictureBox4.Image.Width))
{
pictureBox4.Left += (e.X - x);
x = e.X;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -