.NET (C#) 窗口最小化事件

发布于 2024-08-03 21:26:57 字数 119 浏览 8 评论 0原文

嘿,我真的被我的项目困住了......我需要知道任何打开的窗口何时被最小化/恢复并在我自己的应用程序中处理事件。有什么想法吗?

编辑: Musigenesis 是对的,我确实想知道其他应用程序何时最小化/恢复

Hey, I'm really stuck with my project here... I need to know when any open window has been minimized / restored and Handle the event in my own App. Any ideas?

Edit:
Musigenesis is right, i do want to know when OTHER applications are minimized/restored

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

碍人泪离人颜 2024-08-10 21:26:57

我认为您需要使用 SetWindowsHookEx Win32 API 函数(以及其他一些函数)。基本上,您将遍历操作系统中所有打开的窗口并挂钩它们的大小调整事件。

强制性评论:您确定需要这样做吗?虽然我认为这在理论上是可能的,但这听起来是一个非常糟糕的主意,并且与 Windows 中应用程序的行为方式背道而驰。

更新:我认为 Windows 中的“显示桌面”的工作方式有点像这样,只不过它会遍历所有打开的窗口,然后使用 SendMessage 将它们最小化(如果打开的话)(完全是我的猜测)。

更新 2:这是一项艰巨的任务,我很好奇如何做到这一点(我 100% 确信这是可能的)。我会密切关注这个问题,如果没有人在接下来的一两天内给出答案,我会再次发布它并提供赏金(你可以这样做,但你需要有一些您自己的声誉点可以作为赏金提供)。

I think you would need to use the SetWindowsHookEx Win32 API function (along with a few others). Basically, you would iterate through all open windows in the OS and hook into their resizing events.

Obligatory comment: are you sure you need to do this? While I think this is theoretically possible, it sounds like a pretty bad idea, and counter to the way applications in Windows are supposed to behave.

Update: I think "Show Desktop" in Windows works kind of like this, except that it iterates through all the open windows and then uses SendMessage to minimize them if open (total guess on my part).

Update 2: this is a tough one, and I'm very curious to know how this could be done (I'm 100% sure that it is possible). I'll keep an eye on this question, and if no one comes up with an answer in the next day or two, I'll post it again and offer a bounty on it (you could do that, but you need to have some reputation points of your own to offer as a bounty).

半世晨晓 2024-08-10 21:26:57

假设您使用的是 Windows 窗体,您可以处理 OnSizeChanged 事件,并测试 WindowState

Assuming you're using Windows Forms, you can handle the OnSizeChanged event, and test the WindowState

感性不性感 2024-08-10 21:26:57
//For cases where you create the window such as:
  protected         Form           gv_AO_frmControlWindow = null;
    gv_AO_frmControlWindow = new Form();
    * * * code to add buttons and such
  // Add handler that is executed when window is minimized/maximized
  gv_AO_frmControlWindow.Resize += new EventHandler(gv_AO_frmControlWindow_Resize);
  gv_AO_frmControlWindow.ShowInTaskbar = false;
  // Show window
  gv_AO_frmControlWindow.showDiaglog.


    // ****************************************************************
    private void gv_AO_frmControlWindow_Resize(object sender, EventArgs e) {
      if ( gv_AO_frmControlWindow.WindowState == FormWindowState.Minimized ) {
        notifyIcon.Visible = true;
        }
      else {
        notifyIcon.Visible = false;
        }
      return;
      } // END OF gv_AO_frmControlWindow_Resize()
    // ****************************************************************
    private void notifyIcon_MouseClick(object sender, MouseEventArgs e) {
      gv_AO_frmControlWindow.WindowState = FormWindowState.Normal;  
      return;
      } // END OF notifyIcon_MouseClick()

//Assuming you wanted a system tray icon to maximize window:
    private System.Windows.Forms.NotifyIcon notifyIcon    = new NotifyIcon();

      notifyIcon.Icon = new Icon( "C:\\SysTray.ico");
      notifyIcon.Text = "MyWindow";
      notifyIcon.MouseClick += new MouseEventHandler(this.notifyIcon_MouseClick);

// 希望这有帮助。
// 达里尔·H·巴塞特

//For cases where you create the window such as:
  protected         Form           gv_AO_frmControlWindow = null;
    gv_AO_frmControlWindow = new Form();
    * * * code to add buttons and such
  // Add handler that is executed when window is minimized/maximized
  gv_AO_frmControlWindow.Resize += new EventHandler(gv_AO_frmControlWindow_Resize);
  gv_AO_frmControlWindow.ShowInTaskbar = false;
  // Show window
  gv_AO_frmControlWindow.showDiaglog.


    // ****************************************************************
    private void gv_AO_frmControlWindow_Resize(object sender, EventArgs e) {
      if ( gv_AO_frmControlWindow.WindowState == FormWindowState.Minimized ) {
        notifyIcon.Visible = true;
        }
      else {
        notifyIcon.Visible = false;
        }
      return;
      } // END OF gv_AO_frmControlWindow_Resize()
    // ****************************************************************
    private void notifyIcon_MouseClick(object sender, MouseEventArgs e) {
      gv_AO_frmControlWindow.WindowState = FormWindowState.Normal;  
      return;
      } // END OF notifyIcon_MouseClick()

//Assuming you wanted a system tray icon to maximize window:
    private System.Windows.Forms.NotifyIcon notifyIcon    = new NotifyIcon();

      notifyIcon.Icon = new Icon( "C:\\SysTray.ico");
      notifyIcon.Text = "MyWindow";
      notifyIcon.MouseClick += new MouseEventHandler(this.notifyIcon_MouseClick);

// Hope this helps.
// Darryl H. Bassett

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文