protected override void WndProc(ref Message m) { try { const int WM_HOTKEY = 0x0312; switch (m.Msg) { case WM_HOTKEY: switch (m.WParam.ToInt32()) { case 100: var processHandle = HotKey.GetForegroundWindow(); //非0非当前窗口 if (processHandle != 0 && processHandle != Handle.ToInt32()) { //注册过或注册的已关闭 if (registeredProcess == null || registeredProcess.HasExited) { int processId; HotKey.GetWindowThreadProcessId(new IntPtr(processHandle), out processId); Process process = Process.GetProcessById(processId); if (process != null) { HotKey.SetForegroundWindow((int)this.Handle); if (DialogResult.Yes == MessageBox.Show($"是否为{process.MainWindowTitle}设置隐藏", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { HotKey.RegisterHotKey(Handle, 100, key1, key2); this.txt_RegisteredProcess.Text = process.MainWindowTitle; if (this.cb_TopMost.Checked) { TopMostWindow.SetTopomost(process.Handle); } registeredProcess = process; } else { registeredProcess = null; } } } else { if (isVisible) { registeredHandle = registeredProcess.MainWindowHandle; HotKey.ShowWindow(registeredHandle, 0); isVisible = false; } else { HotKey.ShowWindow(registeredHandle, 5); isVisible = true; } } } break; case 101: if (registeredProcess != null && !registeredProcess.HasExited) { registeredProcess.Kill(); } break; case 105: if (HotKey.IsWindowVisible(this.Handle)) { HotKey.ShowWindow(this.Handle, 0); } else { HotKey.ShowWindow(this.Handle, 5); } break; } break; } base.WndProc(ref m); } catch (Exception e) { } }
private void Form_RunText_Load(object sender, EventArgs e) { { label_text.Font = f; label_text.ForeColor = c; //Console.WriteLine("===" + c); //this.BackColor = bc; label_text.Text = text; if (text.Equals("")) { label_text.Visible = false; //contextMenuStrip1.Enabled = false; subTextToolStripMenuItem.Enabled = false; AutotoolStripMenuItem1.Enabled = false; } timer1.Interval = Interval; Lable_Resize(); label_text.BackColor = Color.Transparent; if (tans_Flag) { this.TopMost = true; timer2.Enabled = true; } else { if (image_Flag) { string s = settingFile.ReadString("SETTING", "PictureLogo", ""); //Console.WriteLine("s ====" + s); if (!s.Equals("")) { s = s.Substring(s.Length - 4, 4); s = Application.StartupPath + @"\pic\logoshow" + s; if (this.BackgroundImage != null) { this.BackgroundImage.Dispose(); } Image im = Image.FromFile(s); this.BackgroundImage = new Bitmap(im); this.BackgroundImageLayout = ImageLayout.Stretch; } else { if (this.BackgroundImage != null) { this.BackgroundImage.Dispose(); } //this.BackgroundImage = global::WallControl.Properties.Resources.上位机_英文版_MTC_New_Logo; this.BackgroundImageLayout = ImageLayout.Stretch; } timer1.Enabled = false; //AutoAdjustShow(); label_text.TextAlign = ContentAlignment.MiddleCenter; subStopToolStripMenuItem.Checked = true; AutotoolStripMenuItem1.Enabled = true; subStartToolStripMenuItem.CheckState = CheckState.Unchecked; subStartToolStripMenuItem.Enabled = false; subColorToolStripMenuItem.Enabled = false; //int h = label_text.Size.Height; this.Height = (this.Size.Width * 9) / 16; //label_text.Location = new Point(w, (this.Size.Height - h) / 2); } } //if (tans_Flag) { if (Interval > 0 && !text.Equals("")) { /* * Thread t = new Thread(new ThreadStart(StartRunText)); * t.IsBackground = true; * t.Start(); */ if (direction) { label_text.Left = this.Width; } else { label_text.Left = -label_text.Width; } if (!image_Flag) { timer1.Enabled = true; timer1.Start(); } } else { timer1.Enabled = false; //AutoAdjustShow(); label_text.TextAlign = ContentAlignment.MiddleCenter; subStartToolStripMenuItem.CheckState = CheckState.Unchecked; subStopToolStripMenuItem.CheckState = CheckState.Checked; AutotoolStripMenuItem1.Enabled = true; subStartToolStripMenuItem.Enabled = false; //int h = label_text.Size.Height; //int w = (this.Size.Width - label_text.Size.Width) / 2; //label_text.Location = new Point(w, (this.Size.Height - h) / 2); } this.Activate(); } } Lable_Resize(); //IntPtr hDeskTop = FindWindow(null, "Form_RunText"); //SetParent(this.Handle, hDeskTop); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); TopMostWindow.SetTopomost(this.Handle); }