📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.Net;
namespace gprstest
{
//结构定义
[StructLayout(LayoutKind.Sequential)]
public struct GPRS_DATA_RECORD
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
public string m_userid;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
public string m_recv_date;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string m_data_buf;
public ushort m_data_len;
public byte m_data_type;
}
[StructLayout(LayoutKind.Sequential)]
public struct GPRS_USER_INFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
public string m_userid;
public uint m_sin_addr;
public ushort m_sin_port;
public uint m_local_addr;
public ushort m_local_port;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
public string m_logon_date;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
public string m_update_time;
public byte m_status;
}
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
//定义接口函数
[DllImport(".\\wcomm_dll.dll")]
public static extern int start_gprs_server(
IntPtr hWnd,
int wMsg,
int nServerPort,
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder mess);
[DllImport(".\\wcomm_dll.dll")]
public static extern int start_net_service(
IntPtr hWnd,
int wMsg,
int nServerPort,
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder mess);
[DllImport(".\\wcomm_dll.dll")]
public static extern int stop_gprs_server(
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder mess);
[DllImport(".\\wcomm_dll.dll")]
public static extern int stop_net_service(
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder mess);
[DllImport(".\\wcomm_dll.dll")]
public static extern int do_read_proc(
ref GPRS_DATA_RECORD recdPtr,
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder mess,
bool reply);
[DllImport(".\\wcomm_dll.dll")]
public static extern int do_send_user_data(
[MarshalAs(UnmanagedType.LPStr)]
string userid,
[MarshalAs(UnmanagedType.LPStr)]
string data,
int len,
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder mess);
[DllImport(".\\wcomm_dll.dll")]
public static extern int get_user_info(
[MarshalAs(UnmanagedType.LPStr)]
string userid,
ref GPRS_USER_INFO infoPtr);
[DllImport(".\\wcomm_dll.dll")]
public static extern int SetWorkMode(int nWorkMode);
//
//定义一些SOCKET API函数
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);
[DllImport("Ws2_32.dll")]
private static extern string inet_ntoa(uint ip);
[DllImport("Ws2_32.dll")]
private static extern uint htonl(uint ip);
[DllImport("Ws2_32.dll")]
private static extern uint ntohl(uint ip);
[DllImport("Ws2_32.dll")]
private static extern ushort htons(ushort ip);
[DllImport("Ws2_32.dll")]
private static extern ushort ntohs(ushort ip);
//
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
/// <summary>
/// 必需的设计器变量。
///
//定义窗口消息,用来响应DTU的消息
public const int WM_DTU = 0x400 + 100;
private System.Windows.Forms.TextBox tbPort;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tbSend;
private System.Windows.Forms.CheckBox checkBox1;
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.tbSend = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.tbPort = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 16);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(504, 208);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(528, 72);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 32);
this.button1.TabIndex = 1;
this.button1.Text = "开始服务";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(528, 120);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(88, 32);
this.button2.TabIndex = 2;
this.button2.Text = "停止服务";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// listView1
//
this.listView1.CheckBoxes = true;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4,
this.columnHeader5,
this.columnHeader6});
this.listView1.FullRowSelect = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.Location = new System.Drawing.Point(8, 272);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(608, 128);
this.listView1.TabIndex = 3;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "终端登录号码";
this.columnHeader1.Width = 100;
//
// columnHeader2
//
this.columnHeader2.Text = "移动网内IP地址";
this.columnHeader2.Width = 100;
//
// columnHeader3
//
this.columnHeader3.Text = "移动网内IP端口";
this.columnHeader3.Width = 100;
//
// columnHeader4
//
this.columnHeader4.Text = "登录时间";
this.columnHeader4.Width = 100;
//
// columnHeader5
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -