C#下基于控件的系统托盘与退出保护设计源码与贴图.doc_第1页
C#下基于控件的系统托盘与退出保护设计源码与贴图.doc_第2页
C#下基于控件的系统托盘与退出保护设计源码与贴图.doc_第3页
C#下基于控件的系统托盘与退出保护设计源码与贴图.doc_第4页
C#下基于控件的系统托盘与退出保护设计源码与贴图.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;/加动态链接库需要namespace WindowsFormsApplication2 public partial class Form1 : Form DllImport(winio.dll) public static extern bool InitializeWinIo(); DllImport(winio.dll) public static extern bool GetPortVal(IntPtr wPortAddr, out int pdwPortVal, byte bSize); DllImport(winio.dll) public static extern bool SetPortVal(uint wPortAddr, IntPtr dwPortVal, byte bSize); DllImport(winio.dll) public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize, IntPtr PhysicalMemoryHandle); DllImport(winio.dll) public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, byte pbLinAddr); DllImport(winio.dll) public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte pdwPhysVal); DllImport(winio.dll) public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte dwPhysVal); DllImport(winio.dll) public static extern void ShutdownWinIo(); DllImport(user32.dll) public static extern int MapVirtualKey(uint Ucode, uint uMapType); public bool DllLoadResult = false; public bool SystemExitFlag = false;/阻止关闭钮非法退出,只允许从托盘退出 public Form1() InitializeComponent(); private void Form1_FormClosing(object sender, FormClosingEventArgs e) /捕捉窗体Close事件,关闭窗口时提示 if (SystemExitFlag & MessageBox.Show(请您确认是否退出(Y/N), 系统提示, MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes) try ShutdownWinIo();/卸载WinIO catch (System.Exception error) /WinIO卸载失败异常 if (DllLoadResult) MessageBox.Show(error.Message, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = false;/允许退出系统 else e.Cancel = true;/阻止退出系统 this.WindowState = System.Windows.Forms.FormWindowState.Normal; this.Visible = false;/隐藏窗体转换 notifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Power.ico);/显示隐藏的托盘图标/ MessageBox.Show(请从系统托盘中退出!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); private void timer1_Tick(object sender, EventArgs e) /Timer定时到事件 toolStripStatusLabel3.Text = System.DateTime.Now.ToString(); if (toolStripProgressBar1.Value = 1; i-) (CheckBox)this.Controls.Find(checkBox + i, true)0).Checked = (pdwPortVal & (1 (8 - i) != 0; /* for (int i = 0; i 8; i+) switch (i) case 0: checkBox8.Checked = (pdwPortVal & (1 i) != 0; break; case 1: checkBox7.Checked = (pdwPortVal & (1 i) != 0; break; case 2: checkBox6.Checked = (pdwPortVal & (1 i) != 0; break; case 3: checkBox5.Checked = (pdwPortVal & (1 i) != 0; break; case 4: checkBox4.Checked = (pdwPortVal & (1 i) != 0; break; case 5: checkBox3.Checked = (pdwPortVal & (1 i) != 0; break; case 6: checkBox2.Checked = (pdwPortVal & (1 i) != 0; break; case 7: checkBox1.Checked = (pdwPortVal & (1 = 0 & ch = A & ch = (char)Keys.D0 & ch = (char)Keys.A & ch = (char)Keys.F) switch (ch) case (char)Keys.Back:/退格 case (char)Keys.Enter:/回车 break;/放过 default: e.KeyChar = x0;/放弃输入的非法字符 MessageBox.Show(请正确输入16进制数!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); break; else /合法16进制数 e.KeyChar = ch;/强制转换为大写字母 private void button3_Click(object sender, EventArgs e) /WinIO读操作 int pdwPortVal = 0; try uint wPortAddr = Convert.ToUInt32(comboBox1.Text, 16) + 1;/状态口 if (GetPortVal(IntPtr)wPortAddr, out pdwPortVal, sizeof(byte) textBox3.Text = string.Format(0:X02, (byte)pdwPortVal); else MessageBox.Show(WinIO读操作失败!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); catch (System.Exception error) /读出操作异常处理 MessageBox.Show(error.Message, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); for (int i = 9; i = 16; i+) (CheckBox)this.Controls.Find(checkBox + i, true)0).Checked = (pdwPortVal & (1 (i - 9) != 0; /* for (int i = 0; i 8; i+) switch (i) case 0: checkBox9.Checked = (pdwPortVal & (1 i) != 0; break; case 1: checkBox10.Checked = (pdwPortVal & (1 i) != 0; break; case 2: checkBox11.Checked = (pdwPortVal & (1 i) != 0; break; case 3: checkBox12.Checked = (pdwPortVal & (1 i) != 0; break; case 4: checkBox13.Checked = (pdwPortVal & (1 i) != 0; break; case 5: checkBox14.Checked = (pdwPortVal & (1 i) != 0; break; case 6: checkBox15.Checked = (pdwPortVal & (1 i) != 0; break; case 7: checkBox16.Checked = (pdwPortVal & (1 = 0 & ch = A & ch = (char)Keys.D0 & ch = (char)Keys.A & ch = (char)Keys.F) switch (ch) case (char)Keys.Back:/退格 case (char)Keys.Enter:/回车 break;/放过 default:/捕捉到的非法字符 e.KeyChar = x0;/放弃输入的非法字符 MessageBox.Show(请正确输入16进制数!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); break; else /合法16进制数 e.KeyChar = ch;/强制转换为大写字母 private void button4_Click(object sender, EventArgs e) /控制口WinIO写操作 try uint wPortAddr = Convert.ToUInt32(comboBox1.Text, 16) + 2;/控制口 int pdwPortVal = Convert.ToInt32(textBox4.Text, 16); if (!SetPortVal(wPortAddr, (IntPtr)pdwPortVal, sizeof(byte) MessageBox.Show(WinIO写入操作失败!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); catch (System.Exception error) /写入操作异常处理 MessageBox.Show(error.Message, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); private void button5_Click(object sender, EventArgs e) /控制口WinIO读操作 int pdwPortVal = 0; try uint wPortAddr = Convert.ToUInt32(comboBox1.Text, 16) + 2;/控制口 if (GetPortVal(IntPtr)wPortAddr, out pdwPortVal, sizeof(byte) textBox5.Text = string.Format(0:X02, (byte)pdwPortVal); else MessageBox.Show(WinIO读操作失败!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); catch (System.Exception error) /读出操作异常处理 MessageBox.Show(error.Message, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Error); for (int i = 17; i = 24; i+) (CheckBox)this.Controls.Find(checkBox + i, true)0).Checked = (pdwPortVal & (1 (i - 17) != 0; /* for (int i = 0; i 8; i+) switch (i) case 0: checkBox17.Checked = (pdwPortVal & (1 i) != 0; break; case 1: checkBox18.Checked = (pdwPortVal & (1 i) != 0; break; case 2: checkBox19.Checked = (pdwPortVal & (1 i) != 0; break; case 3: checkBox20.Checked = (pdwPortVal & (1 i) != 0; break; case 4: checkBox21.Checked = (pdwPortVal & (1 i) != 0; break; case 5: checkBox22.Checked = (pdwPortVal & (1 i) != 0; break; case 6: checkBox23.Checked = (pdwPortVal & (1 i) != 0; break; case 7: checkBox24.Checked = (pdwPortVal & (1 i) != 0; break; */ private void xToolStripMenuItem_Click(object sender, EventArgs e) /主菜单内退出系统 SystemExitFlag = false;/只能从托盘退出系统 Close();/警告后继续/或 Application.Exit(); private void aToolStripMenuItem_Click(object sender, EventArgs e) /主菜单的帮助 MessageBox.Show(C#学习菜鸟作nHotP, 并口调试帮助提示, MessageBoxButtons.OK); private void textBox3_KeyPress(object sender, KeyPressEventArgs e) if (e.KeyChar != (char)Keys.Back)/只允许退格建 MessageBox.Show(不能输入字符!, 系统提示, MessageBoxButtons.OK); e.KeyChar = 0;/不允许输入字符 private void textBox2_KeyPress(object sender, KeyPressEventArgs e) if (e.KeyChar != (char)Keys.Back)/只允许退格建 MessageBox.Show(不能输入字符!, 系统提示, MessageBoxButtons.OK); e.KeyChar = 0;/不允许输入字符 private void textBox5_KeyPress(object sender, KeyPressEventArgs e) if (e.KeyChar != (char)Keys.Back)/只允许退格建 MessageBox.Show(不能输入字符!, 系统提示, MessageBoxButtons.OK); e.KeyChar = 0;/不允许输入字符 private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) /鼠标右键系统托盘事件处理 contextMenuStrip1.Visible = e.Button = MouseButtons.Right;/显示菜单 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) /鼠标双击系统托盘事件处理 this.Visible = !this.Visible;/隐藏/显示窗体转换 if (this.Visible)/准备显示窗体 /防止最小化不正常显示窗体 notifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Hot.ico); this.WindowState = System.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论