社区
C#
帖子详情
public string extern int MessageBox (int hWnd,String text,
zhengjianping
2003-08-24 02:10:27
public string extern int MessageBox (int hWnd,String text,
String caption, uint type);
该句提示出错:
成员修饰符“extern”必须位于成员类型和名称之前
可我不知道正确的应该这么写,谁知道帮忙一下,我还刚学。
...全文
26
2
打赏
收藏
public string extern int MessageBox (int hWnd,String text,
public string extern int MessageBox (int hWnd,String text, String caption, uint type); 该句提示出错: 成员修饰符“extern”必须位于成员类型和名称之前 可我不知道正确的应该这么写,谁知道帮忙一下,我还刚学。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhengjianping
2003-08-24
打赏
举报
回复
谢,刚才抄错了,大意了。分是你的了。
cnhgj
2003-08-24
打赏
举报
回复
public static extern int MessageBox (int hWnd,String text,
String caption, uint type);
如何在容器中显示.exe文件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.
Text
; using System.Windows.Forms; using System.Diagnostics; using System.Runtime.
Int
eropServices; namespace exe_test {
public
partial class Form1 : Form {
public
Form1() { InitializeComponent(); } Process process = null;
Int
Ptr appWin; private
string
exeName = ""; [DllImport("user32.dll", EntryPo
int
= "GetWindowThreadProcessId", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] private static
extern
long GetWindowThreadProcessId(long
hWnd
, long lpdwProcessId); [DllImport("user32.dll", SetLastError = true)] private static
extern
Int
Ptr FindWindow(
string
lpClassName,
string
lpWindowName); [DllImport("user32.dll", SetLastError = true)] private static
extern
long SetParent(
Int
Ptr
hWnd
Child,
Int
Ptr
hWnd
NewParent); [DllImport("user32.dll", EntryPo
int
= "GetWindowLongA", SetLastError = true)] private static
extern
long GetWindowLong(
Int
Ptr
hwnd
,
int
nIndex); [DllImport("user32.dll", EntryPo
int
= "SetWindowLongA", SetLastError = true)] private static
extern
long SetWindowLong(
Int
Ptr
hwnd
,
int
nIndex, long dwNewLong); //private static
extern
int
SetWindowLong(
Int
Ptr
hWnd
,
int
nIndex,
Int
Ptr dwNewLong); [DllImport("user32.dll", SetLastError = true)] private static
extern
long SetWindowPos(
Int
Ptr
hwnd
, long
hWnd
InsertAfter, long x, long y, long cx, long cy, long wFlags); [DllImport("user32.dll", SetLastError = true)] private static
extern
bool MoveWindow(
Int
Ptr
hwnd
,
int
x,
int
y,
int
cx,
int
cy, bool repa
int
); [DllImport("user32.dll", EntryPo
int
= "PostMessageA", SetLastError = true)] private static
extern
bool PostMessage(
Int
Ptr
hwnd
, u
int
Msg, long wParam, long lParam); private const
int
SWP_NOOWNERZORDER = 0x200; private const
int
SWP_NOREDRAW = 0x8; private const
int
SWP_NOZORDER = 0x4; private const
int
SWP_SHOWWINDOW = 0x0040; private const
int
WS_EX_MDICHILD = 0x40; private const
int
SWP_FRAMECHANGED = 0x20; private const
int
SWP_NOACTIVATE = 0x10; private const
int
SWP_ASYNCWINDOWPOS = 0x4000; private const
int
SWP_NOMOVE = 0x2; private const
int
SWP_NOSIZE = 0x1; private const
int
GWL_STYLE = (-16); private const
int
WS_VISIBLE = 0x10000000; private const
int
WM_CLOSE = 0x10; private const
int
WS_CHILD = 0x40000000;
public
string
ExeName { get { return exeName; } set { exeName = value; } } private void button1_Click(object sender, EventArgs e) { this.exeName = @"calc.exe"; try { process = System.Diagnostics.Process.Start(this.exeName); process.WaitForInputIdle(); System.Threading.Thread.Sleep(150); appWin = process.MainWindowHandle; } catch (Exception ex) {
MessageBox
.Show(this, ex.Message, "Error"); } SetParent(appWin, this.splitContainer1.Panel2.Handle); MoveWindow(appWin, 0, 0, this.Width, this.Height, true); } } }
C# 自定义窗体的最大化、最小化和关闭按钮
自定义窗体的最大化、最小化和关闭按钮, C#移动无标题栏窗体的三种代码: C#移动无标题栏窗体的三种代码:第一种采用,需注意窗体上的控件是否把窗体覆盖了。。。MouseDown、MouseMove、MouseUp事件应该是鼠标所处位置最顶层的控件的事件 在窗体的类中声明两个变量 private Po
int
mouseOffset; //记录鼠标指针的坐标 private bool isMouseDown = false; //记录鼠标按键是否按下 创建该窗体 MouseDown、MouseMove、MouseUp事件的相应处理程序 private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
int
xOffset;
int
yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X ; yOffset = -e.Y ; mouseOffset = new Po
int
(xOffset, yOffset); isMouseDown = true; } } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (isMouseDown) { Po
int
mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { // 修改鼠标状态isMouseDown的值 // 确保只有鼠标左键按下并移动时,才移动窗体 if (e.Button == MouseButtons.Left) { isMouseDown = false; } } 第二种调用API 未验证 using System.Runtime.
Int
eropServices; [DllImport("user32.dll")]
public
static
extern
bool ReleaseCapture(); [DllImport("user32.dll")]
public
static
extern
bool SendMessage(
Int
Ptr
hwnd
,
int
wMsg,
int
wParam,
int
lParam);
public
const
int
WM_SYSCOMMAND = 0x0112;
public
const
int
SC_MOVE = 0xF010;
public
const
int
HTCAPTION = 0x0002; private void Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } 第三种未验证 private bool isMouseDown = false; private Po
int
FormLocation; //form的location private Po
int
mouseOffset; //鼠标的按下位置 [DllImport("user32.dll")]
public
static
extern
bool ReleaseCapture(); [DllImport("user32.dll")]
public
static
extern
bool SendMessage(
Int
Ptr
hwnd
,
int
wMsg,
int
wParam,
int
lParam); private const
int
WM_SYSCOMMAND = 0x0112;//点击窗口左上角那个图标时的系统信息 private const
int
SC_MOVE = 0xF010;//移动信息 private const
int
HTCAPTION = 0x0002;//表示鼠标在窗口标题栏时的系统信息 private const
int
WM_NCHITTEST = 0x84;//鼠标在窗体客户区(除了标题栏和边框以外的部分)时发送的消息 private const
int
HTCLIENT = 0x1;//表示鼠标在窗口客户区的系统消息 private const
int
SC_MAXIMIZE = 0xF030;//最大化信息 private const
int
SC_MINIMIZE = 0xF020;//最小化信息 protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SYSCOMMAND: if (m.WParam == (
Int
Ptr)SC_MAXIMIZE) { m.WParam = (
Int
Ptr)SC_MINIMIZE; } break; case WM_NCHITTEST: //如果鼠标移动或单击 base.WndProc(ref m);//调用基类的窗口过程——WndProc方法处理这个消息 if (m.Result == (
Int
Ptr)HTCLIENT)//如果返回的是HTCLIENT { m.Result = (
Int
Ptr)HTCAPTION;//把它改为HTCAPTION return;//直接返回退出方法 } break; } base.WndProc(ref m);//如果不是鼠标移动或单击消息就调用基类的窗口过程进行处理 } private void Form1_Load(object sender, EventArgs e) { } ------------------------------- 如何在窗体标题栏左边的控制菜单加入自己的菜单啊? 我们一般在窗口标题栏点右键 或 按Alt+空格 可以弹出那个菜单。 ------解决方案-------------------- using System.Runtime.
Int
eropServices; [DllImport( "user32.dll ")]
public
static
extern
Int
Ptr GetSystemMenu(
Int
Ptr
hWnd
, bool bRevert); [DllImport( "user32.dll ")]
public
static
extern
bool InsertMenu(
Int
Ptr hMenu, u
int
uPosition, u
int
uFlags, u
int
uIDNewItem,
string
lpNewItem);
public
const
int
MF_BYCOMMAND = 0;
public
const
int
MF_
STRING
= 0;
public
const
int
MF_BYPOSITION = 0x400;
public
const
int
MF_SEPARATOR = 0x800; private const u
int
SC_ABOUT = 0x0001;
public
const
int
WM_SYSCOMMAND = 0x0112; private void Form1_Load(object sender, EventArgs e) {
Int
Ptr vMenuHandle = GetSystemMenu(Handle, false); InsertMenu(vMenuHandle, 255, MF_
STRING
, SC_ABOUT, "About... "); } protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SYSCOMMAND: if ((u
int
)m.WParam == SC_ABOUT) {
MessageBox
.Show( "Zswang 路过! "); } break; } base.WndProc(ref m); }
wpf写一个秒表计时器程序
WPF 秒表 计时器 定时关机 到计时关机
public
const u
int
WM_SYSCOMMAND = 0x0112;
public
const u
int
SC_MONITORPOWER = 0xF170; [DllImport("user32")]
public
static
extern
Int
Ptr SendMessage(
Int
Ptr
hWnd
, u
int
wMsg, u
int
wParam,
int
lParam); /// /// 关闭显示器 ///
public
void CloseScreen() {
Int
Ptr windowHandle = Process.GetCurrentProcess().MainWindowHandle; SendMessage(windowHandle, WM_SYSCOMMAND, SC_MONITORPOWER, 2); // 2 为关闭显示器, -1则打开显示器 } using System; using System.Collections.Generic; using System.Linq; using System.
Text
; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using IniFiles; namespace StopWatch { /// /// shutdonwCtrl.xaml 的交互逻辑 ///
public
partial class shutdonwCtrl : UserControl { DispatcherTimer timer1; DispatcherTimer timer2;
public
shutdonwCtrl() { InitializeComponent(); timer1 = new DispatcherTimer(); timer1.Tick += new EventHandler(OnTimer1); timer1.
Int
erval = new TimeSpan(0, 0, 1); timer2 = new DispatcherTimer(); timer2.Tick += new EventHandler(OnTimer2); timer2.
Int
erval = new TimeSpan(0, 0, 1); btn_cancel.IsEnabled = false; cancel1.IsEnabled = false; } IniFile INI = new IniFile(IniFile.AppIniName);
public
void LoadIni() { cbo_hour.
Text
= INI.Read
String
("定时关机", "时", "0"); cbo_Minute.
Text
= INI.Read
String
("定时关机", "分", "0"); cbo_Second.
Text
= INI.Read
String
("定时关机", "秒", "0"); cbo1.
Text
= INI.Read
String
("到计时关机", "分", "0"); //combobox1.
Text
= INI.Read
String
("到计时", "时", "0"); //combobox2.
Text
= INI.Read
String
("到计时", "分", "0"); //combobox3.
Text
= INI.Read
String
("到计时", "秒", "0"); }
public
void SaveIni() { INI.Write
String
("定时关机", "时", cbo_hour.
Text
); INI.Write
String
("定时关机", "分", cbo_Minute.
Text
); INI.Write
String
("定时关机", "秒", cbo_Second.
Text
); INI.Write
String
("到计时关机", "分", cbo1.
Text
); } private void ShutDown() { System.Diagnostics.Process.Start("shutdown.exe", "-s -t 1"); } private void OnTimer1(object sender,EventArgs e) { if (second > 0) second--; label1.Content =
string
.Format("Windows将在 {0} 关机", TimerClass.GetTime
String
1(second)); if (second <= 0 && !cbo1.IsEnabled) { ShutDown(); } }
int
second = 0; private void Button_Click(object sender, RoutedEventArgs e) { second = Convert.To
Int
32(cbo1.
Text
) * 60; if (second <= 0) {
MessageBox
.Show("数值必须大于0!"); return; } timer1.Start(); cbo1.IsEnabled = false; cancel1.IsEnabled = true; start1.IsEnabled = false; } private void Button_Click_1(object sender, RoutedEventArgs e) { label1.Content = " "; timer1.Stop(); second = 0; cbo1.IsEnabled = true; cancel1.IsEnabled = false; start1.IsEnabled = true; } private void OnTimer2(object sender, EventArgs e) { if ( DateTime.Now.Hour == Convert.To
Int
32(cbo_hour.
Text
) && DateTime.Now.Minute == Convert.To
Int
32(cbo_Minute.
Text
) && DateTime.Now.Second == Convert.To
Int
32(cbo_Second.
Text
) ) { ShutDown(); } } private void Button_Click_2(object sender, RoutedEventArgs e) {
int
s = Convert.To
Int
32(cbo_hour.
Text
) * 3600 + Convert.To
Int
32(cbo_Minute.
Text
) * 60 + Convert.To
Int
32(cbo_Second.
Text
); timer2.Start(); label2.Content =
string
.Format("Windows将在 {0} 关机", TimerClass.GetTime
String
1(s)); btn_start.IsEnabled = false; btn_cancel.IsEnabled = true; cbo_hour.IsEnabled = false; cbo_Minute.IsEnabled = false; cbo_Second.IsEnabled = false; } private void btn_cancel_Click(object sender, RoutedEventArgs e) { label2.Content = ""; timer2.Stop(); btn_start.IsEnabled = true; btn_cancel.IsEnabled = false; cbo_hour.IsEnabled = true; cbo_Minute.IsEnabled = true; cbo_Second.IsEnabled = true; } } } using System; using System.Collections.Generic; using System.Linq; using System.
Text
; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Threading.Tasks; using System.Runtime.
Int
eropServices; using System.Windows.Threading; using IniFiles; namespace StopWatch { /// /// TimerCtrl.xaml 的交互逻辑 ///
public
partial class TimerCtrl : UserControl { private DispatcherTimer timer1 = null; private DispatcherTimer timer2 = null;
int
SND_SYNC = 0x0000; /* play asynchronously */ //异步
int
SND_ASYNC = 0x0001;
int
SND_LOOP = 8; [DllImport("winmm")]
public
static
extern
bool PlaySound(
string
szSound,
Int
Ptr hMod,
int
flags); private void playSound3() { Task tsk = new Task(new Action(proc)); tsk.Start(); } private void proc() { PlaySound(@"Sound\2.wav",
Int
Ptr.Zero, SND_SYNC); PlaySound(@"Sound\2.wav",
Int
Ptr.Zero, SND_SYNC); PlaySound(@"Sound\2.wav",
Int
Ptr.Zero, SND_SYNC); }
public
TimerCtrl() { InitializeComponent(); timer1 = new DispatcherTimer(); timer1.Tick += new EventHandler(OnTimer1); timer1.
Int
erval = new TimeSpan(0, 0, 1); timer2 = new DispatcherTimer(); timer2.Tick += new EventHandler(OnTimer2); timer2.
Int
erval = new TimeSpan(0, 0, 1); btn_reset1.IsEnabled = false; btn_pause1.IsEnabled = false; }
int
h = 0;
int
m = 0;
int
s = 0;
int
seconds = 0; private void OnTimer1(object sender, EventArgs e) { if (seconds < 1) { PlaySound(@"Sound\2.wav",
Int
Ptr.Zero, SND_ASYNC); btn_start.IsEnabled = false; btn_reset1.IsEnabled = true; btn_pause1.IsEnabled = false; combobox1.IsEnabled = true; combobox2.IsEnabled = true; combobox3.IsEnabled = true; return; } seconds--; label1.Content = TimerClass.GetTime
String
1(seconds); } private void btn_start_Click(object sender, RoutedEventArgs e) { h = Convert.To
Int
32(combobox1.
Text
); m = Convert.To
Int
32(combobox2.
Text
); s = Convert.To
Int
32(combobox3.
Text
); seconds = h * 3600 + m * 60 + s; label1.Content = TimerClass.GetTime
String
1(seconds); timer1.Start(); btn_start.IsEnabled = false; btn_reset1.IsEnabled = true; btn_pause1.IsEnabled = true; combobox1.IsEnabled = false; combobox2.IsEnabled = false; combobox3.IsEnabled = false; } private void btn_reset_Click(object sender, RoutedEventArgs e) { seconds = 0; label1.Content = TimerClass.GetTime
String
1(seconds); timer1.Stop(); btn_start.IsEnabled = true; btn_reset1.IsEnabled = false; btn_pause1.IsEnabled = false; combobox1.IsEnabled = true; combobox2.IsEnabled = true; combobox3.IsEnabled = true; } private void pause1_Click(object sender, RoutedEventArgs e) { if (btn_pause1.Content.To
String
() == "暂停") { timer1.Stop(); btn_pause1.Content = "继续"; } else { timer1.Start(); btn_pause1.Content = "暂停"; } }
int
SEC = 0; private void OnTimer2(object sender, EventArgs e) { if (SEC < 1) { timer2.Stop(); playSound3(); btn_quick.IsEnabled = true; btn_cancel2.IsEnabled = false; combobox4.IsEnabled = true; return; } SEC--; label4.Content = TimerClass.GetTime
String
1(SEC); } private void Button_Click(object sender, RoutedEventArgs e) { SEC = Convert.To
Int
32(combobox4.
Text
) * 60; timer2.Start(); combobox4.IsEnabled = false; btn_quick.IsEnabled = false; btn_cancel2.IsEnabled = true; } private void Button_Click_1(object sender, RoutedEventArgs e) { SEC = 2; label4.Content = "00:00:00"; timer2.Stop(); combobox4.IsEnabled = true; btn_quick.IsEnabled = true; } IniFile INI = new IniFile(IniFile.AppIniName);
public
void LoadIni() { combobox1.
Text
= INI.Read
String
("到计时", "时", "0"); combobox2.
Text
= INI.Read
String
("到计时", "分", "0"); combobox4.
Text
= INI.Read
String
("快速计时", "分", "0"); }
public
void SaveIni() { INI.Write
String
("到计时", "时", combobox1.
Text
); INI.Write
String
("到计时", "分", combobox2.
Text
); INI.Write
String
("到计时", "秒", combobox3.
Text
); INI.Write
String
("快速计时", "分", combobox4.
Text
); } } } using System; using System.Collections.Generic; using System.Linq; using System.
Text
; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Threading; using System.Windows.Threading; namespace StopWatch { /// /// WatchCtrl.xaml 的交互逻辑 ///
public
partial class WatchCtrl : UserControl {
public
WatchCtrl() { InitializeComponent(); timer1 = new DispatcherTimer(); timer1.Tick += new EventHandler(OnTimer1); timer1.
Int
erval = new TimeSpan(0, 0, 1); timer1_1 = new DispatcherTimer(); timer1_1.Tick += new EventHandler(OnTimer1_1); timer1_1.
Int
erval = new TimeSpan(0, 0, 0, 100); timer2 = new DispatcherTimer(); timer2.Tick += new EventHandler(OnTimer2); timer2.
Int
erval = new TimeSpan(0, 0, 1); } private DispatcherTimer timer1 = null; private DispatcherTimer timer1_1 = null; private DispatcherTimer timer2 = null; private void OnTimer1(object sender, EventArgs e) { second++; label1.Content = TimerClass.GetTime
String
1(second) ;//DateTime.Now.To
String
("h:mm:ss"); }
public
int
second = 0; private
int
second1 = 0;
public
int
count = 0; private void OnTimer1_1(object sender, EventArgs e) { //label1.Content = TimerClass.GetTime
String
1(second) + "." + count.To
String
();//DateTime.Now.To
String
("h:mm:ss"); //count++; //if (count > 9) // count = 0; } private void OnTimer2(object sender, EventArgs e) { second1++; label2.Content = TimerClass.GetTime
String
1(second1) ;//.To
String
("h:mm:ss"); } private void btn_start_Click(object sender, RoutedEventArgs e) { timer1.Start(); timer2.Start(); if (btn_start.Content.To
String
() == "停止") { btn_start.Content = "开始"; btn_reset.Content = "复位"; timer1.Stop(); timer2.Stop(); } else { btn_start.Content = "停止"; btn_reset.Content = "计次"; } } private
int
counter = 0; private void btn_reset_Click(object sender, RoutedEventArgs e) { if (btn_reset.Content.To
String
() == "复位") { second = 0; second1 = 0; label1.Content = "00:00:00"; label2.Content = "00:00:00"; timer1.Stop(); timer2.Stop(); } else { if (second1 > 0) { counter++; listbox1.Items.Add(
string
.Format(" {0}\t{1}", counter, label2.Content)); } second1 = 0; label2.Content = "00:00:00"; } if (btn_reset.Content.To
String
() == "复位" && btn_start.Content.To
String
()=="开始") { listbox1.Items.Clear(); } } } }
C#写gps中心服务处理程序
要改协议,,高手帮下忙。。在线等。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Messaging;
using System.Net.Sockets;
using System.
Text
;
using System.Runtime.
Int
eropServices;
using System.IO;
using System.Threading ;
using System.Net;
namespace GprsServer
{
///
/// Form1 的摘要说明。
///
public
class GprsServer : System.Windows.Forms.Form
{
///
/// 必需的设计器变量。
///
[DllImport("User32.dll",EntryPo
int
="SendMessage")]
private static
extern
int
SendMessage(
int
hWnd
, // handle to destination window
int
Msg, // message
int
wParam, // first message parameter
string
lParam // second message parameter
);
[DllImport("User32.dll",EntryPo
int
="FindWindow")]
private static
extern
int
FindWindow(
string
lpClassName,
string
lpWindowName);
[DllImport("kernel32.dll")]
public
static
extern
int
GetPrivateProfile
String
(
string
section ,
string
key ,
string
def ,
String
Builder retVal ,
int
size ,
string
filePath ) ;
[DllImport("kernel32")]
public
static
extern
long WritePrivateProfile
String
(
string
section,
string
key,
string
val,
string
filePath ) ;
private System.ComponentModel.IContainer components;
public
static
int
LocaPort;//本地端口
public
static
string
RemoteIp;
public
static
int
RemotePort;//远程端口
public
static
string
sCompanyName;//公司名称
private Icon m_Icon1;
private Icon m_Icon2;
private Icon m_Icon3;
private NotifyIcon notifyIcon;
MenuItem menuItem1;
MenuItem menuItem2;
private Hashtable CarID_RemoteIP_Hash;
private Thread thGprs ;
private Thread thTcpMsg ;
private Socket socket;
private Socket TcpSocket;
private System.Windows.Forms.Timer TimerIcon;
private System.Windows.Forms.Label lblInfo;
private System.Windows.Forms.Timer TimerConn;
private byte[] TempBuff;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ImageList imgList;// = new byte[1024];
private byte[] TcpBuff;
private System.Windows.Forms.ListView lvwMsg;
private System.Windows.Forms.ColumnHeader sId;
private System.Windows.Forms.ColumnHeader sNote;
private System.Windows.Forms.Button cmdExit;
private System.Windows.Forms.Button cmdSet;// = new byte[2048];
private bool bTsFlag=false;
public
GprsServer()
{
InitializeComponent();
//检测配置文件目录是否存在
GetSysPra();
TempBuff= new byte[1];
TcpBuff=new byte[1];
m_Icon1 = new Icon("SysFile\\Icon1.ico");
m_Icon2 = new Icon("SysFile\\Icon2.ico");
m_Icon3 = new Icon("SysFile\\Icon3.ico");
notifyIcon = new NotifyIcon();
notifyIcon.Icon = m_Icon1;
notifyIcon.
Text
= sCompanyName;
notifyIcon.Visible = true;
menuItem1=new MenuItem("设置");
menuItem2=new MenuItem("退出");
menuItem1.Click+=new EventHandler(this.menuItem1_Click);
menuItem2.Click+=new EventHandler(this.menuItem2_Click);
notifyIcon.Con
text
Menu=new Con
text
Menu(new MenuItem[]{menuItem1,menuItem2});
notifyIcon.DoubleClick+=new System.EventHandler(this.notifyIcon_DBClick);
CarID_RemoteIP_Hash=new Hashtable();
thGprs = new Thread(new ThreadStart(ReadUdp)) ;
//启动线程
thGprs.IsBackground =true;//将线程作为后台线程处理,用途,当主线程关闭,子线程随着关闭
thGprs.Start( );
try
{
IPHostEntry IPHost = Dns.Resolve(RemoteIp);
string
[]aliases = IPHost.Aliases;
IPAddress []addr = IPHost.AddressList;
EndPo
int
ep = new IPEndPo
int
(addr[0],RemotePort);
TcpSocket = new Socket(AddressFamily.
Int
erNetwork,SocketType.Stream,ProtocolType.Tcp);
TcpSocket.Connect(ep);
thTcpMsg = new Thread (new ThreadStart(ReadTcpMsg)) ;
//启动线程
thTcpMsg.IsBackground =true;
thTcpMsg.Start( ) ;
lblInfo.
Text
="系统运行正常,正在中转GPRS数据...";
}
catch
{}
}
private void GetSysPra()
{
String
Builder temp = new
String
Builder(255);
if (Directory.Exists("SysIni"))
{
if (File.Exists("SysIni\\SysIni.ini"))
{
int
i;
i= GetPrivateProfile
String
("PortIni","UdpPort","",temp,255,"SysIni\\SysIni.ini");
if (i==0)
{
LocaPort=8888;
WritePrivateProfile
String
("PortIni","UdpPort","8888","SysIni\\SysIni.ini");
}
else
{
LocaPort=
int
.Parse(temp.To
String
( ));
}
i = GetPrivateProfile
String
("Company","Name","",temp,255,"SysIni\\SysIni.ini");
if (i==0)
{
sCompanyName="龙翰科技";
WritePrivateProfile
String
("Company","Name","龙翰科技","SysIni\\SysIni.ini");
}
else
{
sCompanyName=temp.To
String
( );
}
i = GetPrivateProfile
String
("PortIni","TcpAddress","",temp,255,"SysIni\\SysIni.ini");
if (i==0)
{
RemoteIp="127.0.0.1";
WritePrivateProfile
String
("PortIni","TcpAddress","127.0.0.1","SysIni\\SysIni.ini");
}
else
{
RemoteIp=temp.To
String
( );
}
i = GetPrivateProfile
String
("PortIni","TcpPort","",temp,255,"SysIni\\SysIni.ini");
if (i==0)
{
RemotePort=6666;
WritePrivateProfile
String
("PortIni","TcpPort","6666","SysIni\\SysIni.ini");
}
else
{
RemotePort=
int
.Parse(temp.To
String
( ));
}
}
else
{
//File.Create("SysIni\\SysIni.ini",255);
LocaPort=8888;
WritePrivateProfile
String
("PortIni","UdpPort","8888","SysIni\\SysIni.ini");
sCompanyName="龙翰科技";
WritePrivateProfile
String
("Company","Name","龙翰科技","SysIni\\SysIni.ini");
RemoteIp="127.0.0.1";
WritePrivateProfile
String
("PortIni","TcpAddress","127.0.0.1","SysIni\\SysIni.ini");
RemotePort=6666;
WritePrivateProfile
String
("PortIni","TcpPort","6666","SysIni\\SysIni.ini");
}
}
else
{
Directory.CreateDirectory("SysIni");
//File.Create("SysIni\\SysIni.ini",255);
LocaPort=8888;
WritePrivateProfile
String
("PortIni","UdpPort","8888","SysIni\\SysIni.ini");
sCompanyName="龙翰科技";
WritePrivateProfile
String
("Company","Name","龙翰科技","SysIni\\SysIni.ini");
RemoteIp="127.0.0.1";
WritePrivateProfile
String
("PortIni","TcpAddress","127.0.0.1","SysIni\\SysIni.ini");
RemotePort=6666;
WritePrivateProfile
String
("PortIni","TcpPort","6666","SysIni\\SysIni.ini");
}
}
///
/// 清理所有正在使用的资源。
///
private void menuItem1_Click(object sender,System.EventArgs e)
{
//
}
private void menuItem2_Click(object sender,System.EventArgs e)
{
this.Close();
Application.Exit();
}
private void notifyIcon_DBClick(object sender, System.EventArgs e)
{
//
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
notifyIcon.Visible =false;;
notifyIcon.Icon=null;
notifyIcon.Dispose();
m_Icon1.Dispose();
m_Icon2.Dispose();
m_Icon3.Dispose();
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GprsServer));
this.TimerIcon = new System.Windows.Forms.Timer(this.components);
this.lblInfo = new System.Windows.Forms.Label();
this.TimerConn = new System.Windows.Forms.Timer(this.components);
this.lvwMsg = new System.Windows.Forms.ListView();
this.sId = new System.Windows.Forms.ColumnHeader();
this.sNote = new System.Windows.Forms.ColumnHeader();
this.imgList = new System.Windows.Forms.ImageList(this.components);
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.cmdExit = new System.Windows.Forms.Button();
this.cmdSet = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// TimerIcon
//
this.TimerIcon.Enabled = true;
this.TimerIcon.
Int
erval = 1000;
this.TimerIcon.Tick += new System.EventHandler(this.TimerIcon_Tick);
//
// lblInfo
//
this.lblInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblInfo.Location = new System.Drawing.Po
int
(4, 298);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(310, 23);
this.lblInfo.TabIndex = 0;
this.lblInfo.
Text
Align = System.Drawing.ContentAlignment.MiddleCenter;
//
// TimerConn
//
this.TimerConn.Enabled = true;
this.TimerConn.
Int
erval = 6000;
this.TimerConn.Tick += new System.EventHandler(this.TimerConn_Tick);
//
// lvwMsg
//
this.lvwMsg.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.sId,
this.sNote});
this.lvwMsg.FullRowSelect = true;
this.lvwMsg.Location = new System.Drawing.Po
int
(2, 2);
this.lvwMsg.Name = "lvwMsg";
this.lvwMsg.Size = new System.Drawing.Size(564, 292);
this.lvwMsg.SmallImageList = this.imgList;
this.lvwMsg.TabIndex = 1;
this.lvwMsg.View = System.Windows.Forms.View.Details;
//
// sId
//
this.sId.
Text
= "";
this.sId.Width = 21;
//
// sNote
//
this.sNote.
Text
= "消息内容";
this.sNote.Width = 522;
//
// imgList
//
this.imgList.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
this.imgList.ImageSize = new System.Drawing.Size(16, 16);
this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
this.imgList.TransparentColor = System.Drawing.Color.Transparent;
//
// checkBox1
//
this.checkBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.checkBox1.Location = new System.Drawing.Po
int
(332, 300);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(104, 19);
this.checkBox1.TabIndex = 2;
this.checkBox1.
Text
= "显示调试数据";
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// cmdExit
//
this.cmdExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.cmdExit.Location = new System.Drawing.Po
int
(504, 298);
this.cmdExit.Name = "cmdExit";
this.cmdExit.Size = new System.Drawing.Size(60, 22);
this.cmdExit.TabIndex = 3;
this.cmdExit.
Text
= "退出(&E)";
this.cmdExit.Click += new System.EventHandler(this.cmdExit_Click);
//
// cmdSet
//
this.cmdSet.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.cmdSet.Location = new System.Drawing.Po
int
(432, 298);
this.cmdSet.Name = "cmdSet";
this.cmdSet.Size = new System.Drawing.Size(60, 22);
this.cmdSet.TabIndex = 4;
this.cmdSet.
Text
= "设置(&S)";
this.cmdSet.Click += new System.EventHandler(this.cmdSet_Click);
//
// GprsServer
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(566, 323);
this.Controls.Add(this.cmdSet);
this.Controls.Add(this.cmdExit);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.lvwMsg);
this.Controls.Add(this.lblInfo);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "GprsServer";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.
Text
= "中继服务器";
this.Load += new System.EventHandler(this.GprsServer_Load);
this.ResumeLayout(false);
}
#endregion
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new GprsServer());
}
private byte Get_CheckXor(ref byte[] temp,
int
len)
{
byte A=0;
for(
int
i=0;i
{
A^=temp[i];
}
return A;
}
private void ReadTcpMsg() //读取用户发送的指令数据
{
byte[] buff= new byte[2048];
string
CartIpAddress="";//车辆的IP地址
EndPo
int
TempRemote = null;
int
recv = 0;
byte[] Tbuff;
byte[] AllBuff;
int
iLenght=0;
int
iIndex=0;
int
iLen=0;
int
iXorValue=0;
while(true)
{
try
{
recv=TcpSocket.Receive(buff,0,TcpSocket.Available,SocketFlags.None);//读取数据内容
if (recv==0)
{
recv=TcpSocket.Receive(buff,0,TcpSocket.Available,SocketFlags.None);//读取数据内容
if (recv==0)
{
TcpSocket.Close();
break;
}
}
}
catch
{
break;
}
AllBuff=new byte[recv +TcpBuff.Length];
for (iIndex = 1; iIndex <=TcpBuff.Length; iIndex++)
{
AllBuff[iIndex-1]=TcpBuff[iIndex-1];
}
for (iIndex = 1; iIndex <=recv; iIndex++)
{
AllBuff[TcpBuff.Length+iIndex-1]=buff[iIndex-1];
}
for (iIndex = 1; iIndex <=AllBuff.Length; iIndex++)
{
iLenght=AllBuff.Length-iIndex+1;
if (iLenght<6)//检测数据包长度
{
//不完整,则将指令保存
if (iLenght>0)
{
TcpBuff=new byte[iLenght];
for (iLen = 1; iLen <=iLenght; iLen++)
{
TcpBuff[iLen-1]=AllBuff[iLen+iIndex-2];
}
}
break;
}
else
{
//检测当前指令是否是完整的指令,查找数据包头
if (AllBuff[iIndex-1]==0x29 & AllBuff[iIndex]==0x29)
{
if ((AllBuff.Length -iIndex)>=(AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+4))
{
//检测当前指令是否是完整的指令
if ((AllBuff[AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+iIndex+3])==0x0D)
{
//在接收的数据中获取单条完整的指令数据
Tbuff=new byte[AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+5];
for (iLen = 1; iLen <=Tbuff.Length; iLen++)
{
Tbuff[iLen-1]=AllBuff[iLen+iIndex-2];
}
iXorValue=Get_CheckXor(ref Tbuff,Tbuff.Length-2);
if(iXorValue!=Tbuff[Tbuff.Length-2])
{
//校验不合格,继续查找合法指令数据
continue;
}
else
{
if (bTsFlag)
{
string
BuffToStr="";
for(
int
i=0;i
{
BuffToStr+=Tbuff[i].To
String
("X2")+" ";
}
ShowSysMsg(BuffToStr,2);
}
//获取车载终端手机号
CartIpAddress=Tbuff[5]+"." +Tbuff[6] +"."+Tbuff[7] +"."+Tbuff[8];
TempRemote=(EndPo
int
)CarID_RemoteIP_Hash[CartIpAddress];
if( TempRemote==null)
{
if (bTsFlag)
{
ShowSysMsg("无法查找到接收数据的远程终节点!",3);
}
}
else
{
try
{
socket.SendTo(Tbuff,TempRemote);
if (bTsFlag)
{
ShowSysMsg("数据成功转发到车载终端!",1);
}
}
catch
{
if (bTsFlag)
{
ShowSysMsg("数据转发到车载终端失败!",3);
}
}
}
iIndex=iIndex+Tbuff.Length-1;
TcpBuff=new byte[1];
}
}
else
{
continue;
}
}
else
{
if ((AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+4)>1024)
{
continue;
}
else
{
//不完整,则将指令保存
if (iLenght>0)
{
TcpBuff=new byte[iLenght];
for (iLen = 1; iLen <=iLenght; iLen++)
{
TcpBuff[iLen-1]=AllBuff[iLen+iIndex-2];
}
break;
}
else
{
TcpBuff=new byte[1];
break;
}
}
}
}
else
{
continue;
}
}//检测数据包长度
}
}
}
public
void ShowSysMsg(
string
sNote,
int
iIcon)
{
//显示系统消息
try
{
lvwMsg.BeginUpdate();
if (lvwMsg.Items.Count >100)
lvwMsg.Items.Clear();
ListViewItem li = new ListViewItem();
//li.SubItems[0].
Text
=sNote ;
li.SubItems.Add (sNote);
li.ImageIndex=iIcon;
lvwMsg.Items.Add(li);
lvwMsg.EndUpdate();
}
catch
{}
}
private void ReadUdp() //从UDP数据端口读取GPRS数据
{
byte[] buff = new byte[1024];
int
recv = 0;
byte[] Tbuff;
byte[] AllBuff;
int
iLenght=0;
int
iIndex=0;
int
iLen=0;
int
iXorValue=0;
string
CarIpAddress="";
byte[] RecvAffirmBuff=new byte[]{0x29,0x29,0x21,0x00,0x05,0,0,0,0,0x0D};//回应终端数组
IPEndPo
int
ipep = new IPEndPo
int
(IPAddress.Any ,LocaPort);
//socket = new Socket(AddressFamily.
Int
erNetwork, SocketType.Dgram, ProtocolType.Udp);
socket = new Socket(AddressFamily.
Int
erNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
socket.Bind(ipep);
ShowSysMsg("系统成功在"+LocaPort + "端口侦听!",6);
}
catch
{
ShowSysMsg("端口"+LocaPort+"已被占用,系统侦听失败!",5);
return;
}
IPEndPo
int
sender = new IPEndPo
int
(IPAddress.Any , 0);//指远程终端(终节点)Ip地址对象 IPAddress.Any表示任何地址 0 表示任何端口
EndPo
int
remote = (EndPo
int
)(sender); //指远程终端(终节点)
while(true)
{
try
{
recv = socket.ReceiveFrom(buff , ref remote);
}
catch
{
ShowSysMsg("接收车载终端数据错误!",3);
}
//---------------------you2004-12-31 begin------------------------------//
AllBuff=new byte[recv +TempBuff.Length];
for (iIndex = 1; iIndex <=TempBuff.Length; iIndex++)
{
AllBuff[iIndex-1]=TempBuff[iIndex-1];
}
for (iIndex = 1; iIndex <=recv; iIndex++)
{
AllBuff[TempBuff.Length+iIndex-1]=buff[iIndex-1];
}
for (iIndex = 1; iIndex <=AllBuff.Length; iIndex++)
{
iLenght=AllBuff.Length-iIndex+1;
if (iLenght<6)//检测数据包长度
{
//不完整,则将指令保存
if (iLenght>0)
{
TempBuff=new byte[iLenght];
for (iLen = 1; iLen <=iLenght; iLen++)
{
TempBuff[iLen-1]=AllBuff[iLen+iIndex-2];
}
}
break;
}
else
{
//检测当前指令是否是完整的指令,查找数据包头
if (AllBuff[iIndex-1]==0x29 & AllBuff[iIndex]==0x29)
{
if ((AllBuff.Length -iIndex)>=(AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+4))
{
//检测当前指令是否是完整的指令
if ((AllBuff[AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+iIndex+3])==0x0D)
{
//在接收的数据中获取单条完整的指令数据
Tbuff=new byte[AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+5];
for (iLen = 1; iLen <=Tbuff.Length; iLen++)
{
Tbuff[iLen-1]=AllBuff[iLen+iIndex-2];
}
iXorValue=Get_CheckXor(ref Tbuff,Tbuff.Length-2);
if(iXorValue!=Tbuff[Tbuff.Length-2])
{
//校验不合格,继续查找合法指令数据
continue;
}
else
{
if (bTsFlag)
{
string
BuffToStr="";
for(
int
i=0;i
{
BuffToStr+=Tbuff[i].To
String
("X2")+" ";
}
ShowSysMsg(BuffToStr,0);
}
//获取车载终端手机号
CarIpAddress=Tbuff[5]+"." +Tbuff[6] +"."+Tbuff[7] +"."+Tbuff[8];
//-----------------检测系统哈希表是否包含此终端数据---------------------\\
if(CarID_RemoteIP_Hash.ContainsKey(CarIpAddress))
{
CarID_RemoteIP_Hash[CarIpAddress]=remote;//有更新
}
else
{
CarID_RemoteIP_Hash.Add(CarIpAddress,remote);//没有添加
}
//--------------------将数据转发到中心处理程序-----------------\\
if (TcpSocket.Connected)
{
try
{
TcpSocket.Send(Tbuff,0,Tbuff.Length,SocketFlags.None);
if (bTsFlag)
{
ShowSysMsg("数据成功转发到网络中心处理程序!",1);
}
}
catch
{
if (bTsFlag)
{
ShowSysMsg("数据转发到网络中心处理程序失败!",3);
}
}
}
//-------------------向终端发出0x21的接收确认-------------------\\
RecvAffirmBuff[5]=Tbuff[Tbuff.Length-2];
RecvAffirmBuff[6]=Tbuff[2];
RecvAffirmBuff[7]=Tbuff[9];
RecvAffirmBuff[8]=Get_CheckXor(ref RecvAffirmBuff,8);
socket.SendTo(RecvAffirmBuff,remote);
iIndex=iIndex+Tbuff.Length-1;
TempBuff=new byte[1];
}
}
else
{
continue;
}
}
else
{
if ((AllBuff[iIndex+2]*256+ AllBuff[iIndex+3]+4)>1024)
{
continue;
}
else
{
//不完整,则将指令保存
if (iLenght>0)
{
TempBuff=new byte[iLenght];
for (iLen = 1; iLen <=iLenght; iLen++)
{
TempBuff[iLen-1]=AllBuff[iLen+iIndex-2];
}
break;
}
else
{
TempBuff=new byte[1];
break;
}
}
}
}
else
{
continue;
}
}//检测数据包长度
}
//---------------------you2004-12-31 end------------------------------//
}
}
private void GprsServer_Load(object sender, System.EventArgs e)
{
//
}
int
I=0;
private void TimerIcon_Tick(object sender, System.EventArgs e)
{
if(thGprs!=null)
{
if(thGprs.IsAlive)
notifyIcon.Icon=notifyIcon.Icon==m_Icon1?m_Icon2:m_Icon1;
else
notifyIcon.Icon=notifyIcon.Icon==m_Icon1?m_Icon3:m_Icon1;
}
I++;
if(I>5)
{
I=FindWindow(null,@sCompanyName);
if( I!= 0)
{
SendMessage(I,0x501,1002,"");
}
I=0;
}
}
private void TimerConn_Tick(object sender, System.EventArgs e)
{
if (!TcpSocket.Connected)
{
try
{
lblInfo.
Text
="与中心数据处理程序断开,正在进行二次连接...";
IPHostEntry IPHost = Dns.Resolve(RemoteIp);
string
[]aliases = IPHost.Aliases;
IPAddress []addr = IPHost.AddressList;
EndPo
int
ep = new IPEndPo
int
(addr[0],RemotePort);
TcpSocket = new Socket(AddressFamily.
Int
erNetwork,SocketType.Stream,ProtocolType.Tcp);
TcpSocket.Connect(ep);
thTcpMsg = new Thread ( new ThreadStart(ReadTcpMsg)) ;
//启动线程
thTcpMsg.IsBackground =true;
thTcpMsg.Start( ) ;
lblInfo.
Text
="系统运行正常,正在中转GPRS数据...";
}
catch
{
return;
}
}
}
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
bTsFlag=checkBox1.Checked;
}
private void cmdExit_Click(object sender, System.EventArgs e)
{
if(
MessageBox
.Show("确定关闭中继服务器?", "提示",
MessageBox
Buttons.YesNo,
MessageBox
Icon.Information) == DialogResult.Yes)
{
Application.Exit ();
}
}
private void cmdSet_Click(object sender, System.EventArgs e)
{
frmUdpSet frmudpset=new frmUdpSet();
frmudpset.Show();
}
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel =true;
this.WindowState =FormWindowState.Minimized;
}
}
}
API精灵源码(C#编)
/* API精灵 FOR C# 开始设计日期 2004.03.06 设计目的:简单快速对C#中使用的API函数进行查询,并给出调用代码 设计进度: 2004.03.09 完成对的查询功能,包括 代码调用,中文注释,所需的DLL库,与C#中函数对应关系 2004.03.10 0:48:52 完成了用
String
Builder数组对原ComboBox的替换,可以使程序不用从新读取数据库就可以刷新修改后的信息! 2004.03.10 18:00:00 完成了用ArrayList对
String
Builder数组的替换节省2M内存 2004.03.11 21:10:15 完成滚动字幕的设置,启用了一个TIMER控件,然后设置时间,删除字符串的第一个字母已达到滚动效果! 2004.03.11 22:02:00 改正更新时出现空值出错问题,新填函数isnull 2004.03.12 13:22:08 完成关键字高亮显示 高亮显示函数 mykeywords 2004.03.12 22:08:20 加强了高亮显示函数 mykeywords的功能,使其能识别不同的关键字并显示不同的颜色 2004.03.14 01:40:00 完成对CONST的查询,并且增加了 mykeywords1函数,使其关键字显示性能提高 2004.03.14 13:12:00 添加了提示信息,提示信息设置在函数 mytips() 中 2004.03.15 21:51:20 更改数据库和WINAPI.TXT路径为程序运行路径 2004.03.15 22:31:50 添加了鼠标右键信息 2004.03.15 23.23:30 添加了数据库密码 2004.03.16 23:24:30 添加了版权信息以及相应提示 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using System.Runtime.
Int
eropServices; using System.IO; namespace API精灵 { /// /// Form1 的摘要说明。 /// 这个版本没有使用oleDbDataAdapter+DataSet对数据进行存取,而是使用的OleDbCommand +OleDbDataReader 的形式。 /// 主要是想试验一下不用oleDbDataAdapter+DataSet的数据存取速度。 ///
public
class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Button button4; private System.Windows.Forms.
Text
Box mysearch; private System.Windows.Forms.ListBox tiplist; private System.Windows.Forms.ComboBox select_type; private System.Windows.Forms.
Text
Box dll
text
; /// /// 必需的设计器变量。 /// //自定义变量 private ArrayList fundll = new ArrayList();//保存读取出来的DLL内容 private ArrayList funtips = new ArrayList();//保存读取出来的中文提示信息 private ArrayList funcode = new ArrayList();//保存读取出来的C#调用代码 private ArrayList funmat = new ArrayList();//保存读取出来的C#对应函数 private ArrayList funwin9x = new ArrayList();//保存读取出来的WIN9X private ArrayList funwin2k = new ArrayList();//保存读取出来的WIN2K private
int
nowselect = 0; private
string
oldscoll_
text
; private
int
nowtypeselect = 0; private
string
nowpath = @System.Environment.CurrentDirectory+@"\"; private
string
dbpassword = "ling_feng_work";
public
string
myConnstr;
public
OleDbConnection myconn ;//创建一个新连接 private
string
mysql ;//查询语句 private
string
sql_update; private System.Windows.Forms.Rich
Text
Box tipsmemo; private System.Windows.Forms.
Text
Box mat_
text
; private OleDbCommand mycommand = new OleDbCommand(); private System.Windows.Forms.Rich
Text
Box codememo; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.CheckBox win9x; private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.CheckBox win2k; private System.Windows.Forms.CheckBox e_add; private System.Windows.Forms.CheckBox e_modify; private System.Windows.Forms.Button b_modify; private System.Windows.Forms.Button b_add; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.Con
text
Menu mypop; private System.Windows.Forms.MenuItem menuItem1; private System.ComponentModel.IContainer components;
public
Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.button1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tiplist = new System.Windows.Forms.ListBox(); this.select_type = new System.Windows.Forms.ComboBox(); this.mat_
text
= new System.Windows.Forms.
Text
Box(); this.mysearch = new System.Windows.Forms.
Text
Box(); this.dll
text
= new System.Windows.Forms.
Text
Box(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.tipsmemo = new System.Windows.Forms.Rich
Text
Box(); this.mypop = new System.Windows.Forms.Con
text
Menu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.codememo = new System.Windows.Forms.Rich
Text
Box(); this.b_modify = new System.Windows.Forms.Button(); this.b_add = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.win2k = new System.Windows.Forms.CheckBox(); this.win9x = new System.Windows.Forms.CheckBox(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.e_add = new System.Windows.Forms.CheckBox(); this.e_modify = new System.Windows.Forms.CheckBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Po
int
(224, 395); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 24); this.button1.TabIndex = 10; this.button1.
Text
= "关 于"; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox1 // this.groupBox1.Controls.Add(this.tiplist); this.groupBox1.Controls.Add(this.select_type); this.groupBox1.Controls.Add(this.mat_
text
); this.groupBox1.Controls.Add(this.mysearch); this.groupBox1.Controls.Add(this.dll
text
); this.groupBox1.Location = new System.Drawing.Po
int
(8, 8); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(200, 168); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.
Text
= "API查询"; // // tiplist // this.tiplist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tiplist.ItemHeight = 12; this.tiplist.Location = new System.Drawing.Po
int
(8, 43); this.tiplist.Name = "tiplist"; this.tiplist.Size = new System.Drawing.Size(184, 110); this.tiplist.TabIndex = 1; this.tiplist.Visible = false; this.tiplist.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tiplist_KeyDown); this.tiplist.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tiplist_KeyPress); this.tiplist.DoubleClick += new System.EventHandler(this.tiplist_DoubleClick); this.tiplist.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tiplist_MouseUp); this.tiplist.MouseLeave += new System.EventHandler(this.tiplist_MouseLeave); this.tiplist.SelectedIndexChanged += new System.EventHandler(this.tiplist_SelectedIndexChanged); // // select_type // this.select_type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.select_type.Items.AddRange(new object[] { "API函数查询", "常量定义查询"}); this.select_type.Location = new System.Drawing.Po
int
(8, 61); this.select_type.Name = "select_type"; this.select_type.Size = new System.Drawing.Size(184, 20); this.select_type.TabIndex = 2; this.select_type.SelectedIndexChanged += new System.EventHandler(this.select_type_SelectedIndexChanged); // // mat_
text
// this.mat_
text
.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mat_
text
.Location = new System.Drawing.Po
int
(8, 134); this.mat_
text
.Name = "mat_
text
"; this.mat_
text
.Size = new System.Drawing.Size(184, 21); this.mat_
text
.TabIndex = 4; this.mat_
text
.
Text
= "C#对应函数:"; this.mat_
text
.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mat_
text
_MouseDown); // // mysearch // this.mysearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mysearch.Location = new System.Drawing.Po
int
(8, 24); this.mysearch.Name = "mysearch"; this.mysearch.Size = new System.Drawing.Size(184, 21); this.mysearch.TabIndex = 0; this.mysearch.
Text
= ""; this.mysearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mysearch_KeyDown); this.mysearch.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mysearch_MouseDown); this.mysearch.
Text
Changed += new System.EventHandler(this.mysearch_
Text
Changed); // // dll
text
// this.dll
text
.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dll
text
.Location = new System.Drawing.Po
int
(8, 97); this.dll
text
.Name = "dll
text
"; this.dll
text
.Size = new System.Drawing.Size(184, 21); this.dll
text
.TabIndex = 3; this.dll
text
.
Text
= ""; this.dll
text
.
Text
Changed += new System.EventHandler(this.dll
text
_
Text
Changed); // // groupBox2 // this.groupBox2.Controls.Add(this.tipsmemo); this.groupBox2.Location = new System.Drawing.Po
int
(216, 8); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(200, 168); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.
Text
= "函数注释"; // // tipsmemo // this.tipsmemo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tipsmemo.Con
text
Menu = this.mypop; this.tipsmemo.Location = new System.Drawing.Po
int
(8, 16); this.tipsmemo.Name = "tipsmemo"; this.tipsmemo.Size = new System.Drawing.Size(184, 144); this.tipsmemo.TabIndex = 0; this.tipsmemo.
Text
= ""; this.tipsmemo.MouseEnter += new System.EventHandler(this.rich
Text
Box1_MouseEnter); // // mypop // this.mypop.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.
Text
= "复制信息"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.codememo); this.groupBox3.Location = new System.Drawing.Po
int
(8, 221); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(408, 168); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.
Text
= "代码调用"; // // codememo // this.codememo.Con
text
Menu = this.mypop; this.codememo.Location = new System.Drawing.Po
int
(8, 16); this.codememo.Name = "codememo"; this.codememo.Size = new System.Drawing.Size(392, 144); this.codememo.TabIndex = 0; this.codememo.
Text
= ""; this.codememo.
Text
Changed += new System.EventHandler(this.codememo_
Text
Changed); // // b_modify // this.b_modify.Enabled = false; this.b_modify.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_modify.Location = new System.Drawing.Po
int
(120, 395); this.b_modify.Name = "b_modify"; this.b_modify.Size = new System.Drawing.Size(75, 24); this.b_modify.TabIndex = 4; this.b_modify.
Text
= "修改信息"; this.b_modify.Click += new System.EventHandler(this.button2_Click); // // b_add // this.b_add.Enabled = false; this.b_add.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_add.Location = new System.Drawing.Po
int
(16, 395); this.b_add.Name = "b_add"; this.b_add.Size = new System.Drawing.Size(75, 24); this.b_add.TabIndex = 5; this.b_add.
Text
= "添加新项"; // // button4 // this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button4.Location = new System.Drawing.Po
int
(328, 395); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 24); this.button4.TabIndex = 6; this.button4.
Text
= "退 出"; this.button4.Click += new System.EventHandler(this.button4_Click); // // groupBox4 // this.groupBox4.Controls.Add(this.win2k); this.groupBox4.Controls.Add(this.win9x); this.groupBox4.Location = new System.Drawing.Po
int
(8, 176); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(200, 40); this.groupBox4.TabIndex = 11; this.groupBox4.TabStop = false; // // win2k // this.win2k.Location = new System.Drawing.Po
int
(104, 11); this.win2k.Name = "win2k"; this.win2k.Size = new System.Drawing.Size(80, 24); this.win2k.TabIndex = 1; this.win2k.
Text
= "支持win2k"; // // win9x // this.win9x.Location = new System.Drawing.Po
int
(16, 11); this.win9x.Name = "win9x"; this.win9x.TabIndex = 0; this.win9x.
Text
= "支持win9x"; // // groupBox5 // this.groupBox5.Controls.Add(this.e_add); this.groupBox5.Controls.Add(this.e_modify); this.groupBox5.Location = new System.Drawing.Po
int
(216, 176); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(200, 40); this.groupBox5.TabIndex = 12; this.groupBox5.TabStop = false; // // e_add // this.e_add.Location = new System.Drawing.Po
int
(112, 10); this.e_add.Name = "e_add"; this.e_add.Size = new System.Drawing.Size(80, 24); this.e_add.TabIndex = 5; this.e_add.
Text
= "允许添加"; this.e_add.CheckedChanged += new System.EventHandler(this.e_add_CheckedChanged); // // e_modify // this.e_modify.Location = new System.Drawing.Po
int
(16, 10); this.e_modify.Name = "e_modify"; this.e_modify.Size = new System.Drawing.Size(76, 24); this.e_modify.TabIndex = 4; this.e_modify.
Text
= "允许修改"; this.e_modify.CheckedChanged += new System.EventHandler(this.e_modify_CheckedChanged); // // timer1 // this.timer1.
Int
erval = 500; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(424, 429); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.button4); this.Controls.Add(this.b_add); this.Controls.Add(this.b_modify); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); this.Controls.Add(this.button1); this.Controls.Add(this.groupBox2); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.
Text
= "API精灵FOR C#"; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.Run(new Form1()); } [DllImport("user32.dll", EntryPo
int
="ShowWindow")]
public
static
extern
int
ShowWindow (
int
hwnd
,
int
nCmdShow ); private void button1_Click(object sender, System.EventArgs e) { AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } /// /// 填写mysearch中的内容。 /// private void search_comp() { if (tiplist.SelectedIndex>-1) mysearch.
Text
= tiplist.SelectedItem.To
String
(); tiplist.Visible = false ; mysearch.Select(); } /// /// 自动填写提示内容。 /// private void autocomp() { if (tiplist.SelectedIndex>-1) try { if (this.nowtypeselect==0) //================查询函数 { this.nowselect = tiplist.SelectedIndex; dll
text
.
Text
= fundll[tiplist.SelectedIndex].To
String
();//else tipsmemo.
Text
= funtips[tiplist.SelectedIndex].To
String
(); codememo.
Text
= funcode[tiplist.SelectedIndex].To
String
(); mat_
text
.
Text
= funmat[tiplist.SelectedIndex].To
String
(); this.oldscoll_
text
= mat_
text
.
Text
; if (funwin9x[tiplist.SelectedIndex].To
String
()==("Yes")) win9x.Checked=true; else win9x.Checked=false; if (funwin2k[tiplist.SelectedIndex].To
String
()==("Yes")) win2k.Checked=true; else win2k.Checked=false; //滚动文字 if (mat_
text
.
Text
Length>30) timer1.Enabled = true; else timer1.Enabled = false; } else { dll
text
.
Text
= ""; tipsmemo.
Text
= ""; codememo.
Text
= ""; win9x.Checked = false; win2k.Checked = false; } //******************** if (this.nowtypeselect==1) { this.nowselect = tiplist.SelectedIndex; codememo.
Text
= funcode[tiplist.SelectedIndex].To
String
(); } //******************** //================= } catch { dll
text
.
Text
= "没有找到相应连接库"; tipsmemo.
Text
= "没有找到相应提示"; codememo.
Text
= "没有找到相应调用代码"; mat_
text
.
Text
= "没有找到相应C#函数"; } } // /// /// 手动释放一些内存。 /// private void mydisp() { tipsmemo.Clear(); codememo.Clear(); tiplist.Items.Clear(); // ===== fundll.Clear();//保存读取出来的DLL内容 funtips.Clear();//保存读取出来的中文提示信息 funcode.Clear();//保存读取出来的C#调用代码 funmat.Clear();//保存读取出来的C#对应函数 funwin9x.Clear();//保存读取出来的WIN9X funwin2k.Clear();//保存读取出来的WIN2K } private void mysearch_
Text
Changed(object sender, System.EventArgs e) { tiplist.Visible = true ; //自动完成功能。 tiplist.SelectedIndex = (tiplist.Find
String
(mysearch.
Text
,-1)) ;//加上这句,保证TIPLIST跟着自动变化 nowselect = tiplist.SelectedIndex; autocomp(); //设置提示信息 mytips(); } private void mysearch_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up)) tiplist.Focus(); if (e.KeyCode == Keys.Enter) { search_comp(); if (this.nowtypeselect==0) mykeyword(); if (this.nowtypeselect==1) mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_MouseLeave(object sender, System.EventArgs e) { } private void tiplist_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { } private void tiplist_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_DoubleClick(object sender, System.EventArgs e) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } private void Form1_Load(object sender, System.EventArgs e) { //初始化数据库 initdatabase(); //
MessageBox
.Show(this,"欢迎使用 共享版\n 本版对使用功能上略有限制\n 且不提供数据库更新!\n 如想获得更多信息请与我联系。\n dong_teng@tom.com","提示",
MessageBox
Buttons.OK,
MessageBox
Icon.Information); select_type.SelectedIndex = 0; AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } // private void mytips() { //设置提示信息 if ((this.nowselect>-1)&(this.nowtypeselect==0)) { toolTip1.SetToolTip(this.dll
text
,"所在动态连接库: "+this.fundll[this.nowselect].To
String
()); toolTip1.SetToolTip(this.mat_
text
,"在C#中对应的函数: "+this.funmat[this.nowselect].To
String
()); toolTip1.SetToolTip(this.codememo,"函数 "+this.tiplist.SelectedItem.To
String
()+" 在C#中的调用代码,可以手动修改"); toolTip1.SetToolTip(this.tipsmemo,"函数 "+this.tiplist.SelectedItem.To
String
()+" 的注释信息,可以手动修改"); } else if ((this.nowselect>-1)&(this.nowtypeselect==1)) { toolTip1.SetToolTip(this.codememo,"常量 "+this.tiplist.SelectedItem.To
String
()+" 在C#中的调用代码"); toolTip1.SetToolTip(this.dll
text
,"没有相关信息"); toolTip1.SetToolTip(this.mat_
text
,"没有相关信息"); toolTip1.SetToolTip(this.tipsmemo,"没有相关信息"); } } // private void initdatabase() {
string
dbpath = @nowpath+"winapi.mdb"; tiplist.Items.Clear(); //@"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Password="+this.dbpassword ; //"Provider=Microsoft.Jet.OleDB.4.0;Data Source=your mdb filename;Jet OLEDB:Database Password='pass'" ; this.myConnstr = @"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Jet OLEDB:Database Password="+this.dbpassword ; this.myconn= new OleDbConnection(myConnstr); mysql= @"select Fun_name,Fun_dll,Fun_tips,Fun_code,Fun_com,win9x,win2k from winapi"; using(myconn) { myconn.Open(); // if (myconn.State.To
String
() == "Open")
MessageBox
.Show("打开成功!"); //数据处理 // OleDbCommand mycommand = new OleDbCommand(mysql,myconn); mycommand.Command
Text
= mysql; mycommand.Connection = myconn; OleDbDataReader myreader = mycommand.ExecuteReader();
int
i=0; while (myreader.Read()) { tiplist.Items.Add(myreader["Fun_name"]); fundll.Add(myreader["fun_dll"].To
String
()); funtips.Add(myreader["fun_tips"].To
String
()); funcode.Add(myreader["fun_code"].To
String
()); funmat.Add(myreader["fun_com"].To
String
()); funwin9x.Add(myreader["win9x"].To
String
()); funwin2k.Add(myreader["win2k"].To
String
()); i++; } myconn.Close(); myreader.Close(); } } //更新缓存 private void memo_update() { fundll[nowselect] = dll
text
.
Text
; funtips[nowselect] = this.tipsmemo.
Text
; funcode[nowselect] = this.codememo.
Text
; funmat[nowselect] = this.mat_
text
.
Text
; if (win9x.Checked) funwin9x[nowselect]="Yes" ;else funwin9x[nowselect]="No"; if (win2k.Checked) funwin2k[nowselect]="Yes" ;else funwin2k[nowselect]="No"; } // private void oleDbConnection1_InfoMessage(object sender, System.Data.OleDb.OleDbInfoMessageEventArgs e) { } //==============从WINAPI.TXT读取CONST并拆分 private void mysplip() { //
string
dbpath = @System.Environment.CurrentDirectory+@"\winapi.mdb";
string
filename =@nowpath +"winapi.txt";
string
nextline; tiplist.Items.Clear(); StreamReader sr = new StreamReader(filename); while ((nextline = sr.ReadLine())!=null) { if (nextline.StartsWith("
public
const")) {
string
[] ss = nextline.Split('='); tiplist.Items.Add(ss[0].Sub
string
(16).Trim()); funcode.Add(nextline); } } sr.Close(); } //============================== private void select_type_SelectedIndexChanged(object sender, System.EventArgs e) { if (select_type.SelectedIndex != this.nowtypeselect) { this.mydisp(); switch (select_type.SelectedIndex) { case 0:initdatabase();this.nowtypeselect=select_type.SelectedIndex;break; case 1:mysplip();this.nowtypeselect=select_type.SelectedIndex;this.dll
text
.Clear();this.mat_
text
.Clear();break; } isenable(this.nowtypeselect); } } private void dll
text
_
Text
Changed(object sender, System.EventArgs e) { } private void rich
Text
Box1_MouseEnter(object sender, System.EventArgs e) { tiplist.Visible = false ; } private void mysearch_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { tiplist.Visible = false ; mysearch.Focus(); } private void tiplist_SelectedIndexChanged(object sender, System.EventArgs e) { autocomp(); } /// /// 修改内容。 /// private void fun_update() { using(myconn) { myconn.Connection
String
= myConnstr; myconn.Open(); try { //if (myconn.State.To
String
() == "Open")
MessageBox
.Show("打开成功!"); isnull();//判断是否有无效值
string
str_win9x,str_win2k; if (win9x.Checked) str_win9x = "Yes" ; else str_win9x = "No"; if (win2k.Checked) str_win2k = "Yes" ; else str_win2k = "No"; sql_update = "update winapi set Fun_dll = '"+dll
text
.
Text
+"'"+" , Fun_tips = '"+tipsmemo.
Text
+"'"+" , Fun_code = '"+codememo.
Text
+"'"+" , Fun_com ='"+mat_
text
.
Text
+"' "; sql_update +=" , win9x = '" + str_win9x +"' " + ", win2k = '" + str_win2k+"' "; sql_update +=" where Fun_name ='"+ mysearch.
Text
+"'"; mycommand.Connection = myconn; mycommand.Command
Text
= sql_update; mycommand.ExecuteNonQuery(); myconn.Close(); memo_update();
MessageBox
.Show(this,"恭喜!更新成功!","提示",
MessageBox
Buttons.OK,
MessageBox
Icon.Information); } catch { // tipsmemo.
Text
= sql_update;
MessageBox
.Show("没有找到相应记录,更新失败!"); } } } //判断是更新的部分是否有效(不能为空) private void isnull() { if (this.mat_
text
.
Text
=="") this.mat_
text
.
Text
="没有相关信息"; if (this.codememo.
Text
=="") this.codememo.
Text
="没有相关信息"; if (this.tipsmemo.
Text
=="") this.tipsmemo.
Text
="没有相关信息"; if (this.dll
text
.
Text
=="") this.dll
text
.
Text
="没有相关信息"; } //关键字高亮显示 private void mykeyword() {
string
[] keywords = new
string
[5]; keywords[0]=mysearch.
Text
; keywords[1]="
string
"; keywords[2]="ref"; keywords[3]="
int
"; keywords[4]="static
extern
"; for(
int
i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Green;break; case 2: codememo.SelectionColor = Color.Brown;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } } } } // //CONST中关键字高亮显示 private void mykeyword1() {
string
[] keywords = new
string
[5]; keywords[0]=mysearch.
Text
; keywords[1]="="; keywords[2]="0"; keywords[3]="
int
"; keywords[4]="const"; for(
int
i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Blue;break; case 2: codememo.SelectionColor = Color.Green;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } if (index>codememo.
Text
Length) break; } } } // private void button2_Click(object sender, System.EventArgs e) { this.fun_update(); } private void isenable(
int
i_temp) { if (i_temp==0) { win9x.Enabled=true; win2k.Enabled=true; e_modify.Enabled=true; e_add.Enabled=true; b_modify.Enabled=true; b_add.Enabled=true; } else { win9x.Enabled=false; win2k.Enabled=false; e_modify.Enabled=false; e_add.Enabled=false; b_modify.Enabled=false; b_add.Enabled=false; } } private void button4_Click(object sender, System.EventArgs e) { Application.Exit(); } private void e_modify_CheckedChanged(object sender, System.EventArgs e) { if (e_modify.Checked) b_modify.Enabled = true; else b_modify.Enabled = false; } private void e_add_CheckedChanged(object sender, System.EventArgs e) { if (e_add.Checked) b_add.Enabled = true; else b_add.Enabled = false; } private void timer1_Tick(object sender, System.EventArgs e) { if (this.mat_
text
.
Text
Length>0) mat_
text
.
Text
= mat_
text
.
Text
.Remove(0,1); else mat_
text
.
Text
= oldscoll_
text
; } private void mat_
text
_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { timer1.Enabled = false ; mat_
text
.
Text
= oldscoll_
text
; } private void codememo_
Text
Changed(object sender, System.EventArgs e) { } private void tiplist_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { } private void menuItem1_Click(object sender, System.EventArgs e) { Control ct = this.ActiveControl;
string
temp = ct.
Text
; Clipboard.SetDataObject(temp); } private void menuItem2_Click(object sender, System.EventArgs e) { } } }
C#
110,568
社区成员
642,567
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章