前幾天見到微博里有人提到摸魚APP,發現需要在windows store下載才可以使用,文件約157M左右的樣子,自已沒有登錄微軟Store的習慣。想想只有一個界面,沒有必要這么大,於是,自已動手寫了一個,300多K搞定,並且解決了原作者提到的多台顯示器同時使用的話,需要關閉其它顯示器,隱藏鼠標指針,文件過大等問題,花了業余時間搞了一下,發給朋友測試,直呼可以足以騙過老板,現發出來與大家分享。讓你的老板以為你的電腦正在升級,任何事情都做不了。這個時間可以理直氣壯的一邊等待電腦升級一邊喝咖啡:) 采用了習慣的到99%時一直“卡住”,這樣你可以摸一天的魚都沒有問題,也不會漏出馬腳。先放一個運行的效果圖和程序ICON,(年輕人,還是要工作第一,偶爾摸一下魚還是可以的嘛),重點在多顯示器同步顯示和多窗口的傳值及動畫和百分比的同步展示,源代碼公開,內有注解。歡迎留言交流學習。
摸魚MoFish(要想退出按鍵盤ESC)
先睹為快,體驗編譯好的EXE 下載地址:https://file6.mydrivers.com/soft/mofish.exe
效果圖如下:
代碼如下:
//入口代碼
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace MoFish { public partial class MainFrm : Form { #region 事件 public event EventHandler SendMsgEvent; public event EventHandler SendMsgEvent1; #endregion int i = 1; public MainFrm() { InitializeComponent(); //防止休眠 Helper.SleepCtr(true); //不顯示鼠標的光標 Helper.ShowCursor(false); } private void MainFrm_Load(object sender, EventArgs e) { //多個屏幕同步顯示,家里有礦的,10個顯示器可以同步摸魚:) Screen[] screen = Screen.AllScreens; for (int i = 0; i < Screen.AllScreens.Length; i++) { ShowUpdate form = new ShowUpdate(); SendMsgEvent += form.MainFormTxtChaned; //自定義事件 SendMsgEvent1 += form.MainFormTxtChaned1; form.StartPosition = FormStartPosition.CenterScreen; Screen s = Screen.AllScreens[i]; form.Location = new System.Drawing.Point(s.Bounds.X, s.Bounds.Y); form.WindowState = FormWindowState.Maximized; form.Size = new Size(s.WorkingArea.Width, s.WorkingArea.Height); form.Show(); form.BringToFront(); } //使動畫同步 SendMsgEvent1(this, new MyEventArg() { StartAnimation = true }); //更新Timer1 delay(5000); timer1_Tick(null, null); timer1.Enabled = true; } void delay(int time_ms) { DateTime last = DateTime.Now; do { Application.DoEvents(); Thread.Sleep(10); if (this.IsDisposed) { break; } } while ((DateTime.Now - last).TotalMilliseconds < time_ms); } private void timer1_Tick(object sender, EventArgs e) { if (i <= 99) {
SendMsgEvent(this, new MyEventArg() { Text = i.ToString() }); //百分比同步 i++; } else { i = 99; } } public delegate void setTextValue(string textValue); public delegate void setBeginAnimation(bool bBegin); private void MainFrm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { Application.Exit(); } } } }
//函數代碼
using Microsoft.Win32; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace MoFish { class Helper { //定義API函數 [DllImport("kernel32.dll")] static extern uint SetThreadExecutionState(uint esFlags); const uint ES_SYSTEM_REQUIRED = 0x00000001; const uint ES_DISPLAY_REQUIRED = 0x00000002; const uint ES_CONTINUOUS = 0x80000000; [DllImport("user32", EntryPoint = "ShowCursor")] public extern static bool ShowCursor(bool show); //多屏幕復制 private const uint SDC_APPLY = 0x00000080; private const uint SDC_TOPOLOGY_INTERNAL = 0x00000001; private const uint SDC_TOPOLOGY_CLONE = 0x00000002; private const uint SDC_TOPOLOGY_EXTERNAL = 0x00000008; private const uint SDC_TOPOLOGY_EXTEND = 0x00000004; [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern long SetDisplayConfig(uint numPathArrayElements, IntPtr pathArray, uint numModeArrayElements, IntPtr modeArray, uint flags); public static void SleepCtr(bool sleepOrNot) { if (sleepOrNot) { SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED); } else { SetThreadExecutionState(ES_CONTINUOUS); } } } }
//顯示界面部分的代碼
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static MoFish.MainFrm; namespace MoFish { public partial class ShowUpdate : Form { int i = 0; public ShowUpdate() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) {
//解決居中的問題 picBoxLoading.Left = (this.ClientSize.Width - picBoxLoading.Width) / 2; label1.Left = (this.ClientSize.Width - label1.Width) / 2; label2.Left = (this.ClientSize.Width - label2.Width) / 2; label3.Left = (this.ClientSize.Width - label3.Width) / 2; } public void SetText(string txt) { //this.txtMsg.Text = txt; label2.Text = $"{txt}% 已完成"; } internal void MainFormTxtChaned(object sender, EventArgs e) { //取到主窗體的傳來的文本 MyEventArg arg = e as MyEventArg; this.SetText(arg.Text); } internal void MainFormTxtChaned1(object sender, EventArgs e) { //取到主窗體的傳來的文本 MyEventArg arg = e as MyEventArg; //this.SetText(arg.Text); if (arg.StartAnimation == true) picBoxLoading.Enabled = true; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Helper.SleepCtr(false); } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape || e.KeyCode == (Keys.Control & Keys.Q)) { Application.Exit(); } } } }