设置窗口所有者 [英] Set window owner

查看:445
本文介绍了设置窗口所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何设置窗口的所有者(我的进程不拥有)。我可以通过API调用GetWindow(hWnd,GW_OWNER)获取窗口的所有者。但是我需要设置它。

只是一些背景......我正在尝试编写一个程序来隐藏任务栏中的窗口(并将它们添加到系统托盘中)。将它们添加到系统托盘很容易,但我不能让它们从任务栏中隐藏。我不想使用ShowWindow(hWnd,SW_HIDE),因为我希望窗口本身仍然可见。通过设置SetWindowLong(hWnd,GWL_EXSTYLE,!WS_EX_APPWINDOW)(不是那样 - 但我的想法是删除该标志),我相信我可以从任务栏中删除一个窗口,但前提是Window有一个所有者。这就是Visual Basic似乎如何做到的 - 一个不应该在任务栏中的顶级窗口的所有者是一个名为"WindowsFormsParkingWindow"的隐藏窗口

解决方案

< blockquote>

如果我理解你是正确的 - 你只想隐藏任务栏中的表格。没有必要为此做本机互操作。

只需将System.Windows.Forms.From 属性 ShowInTaskbar 设置为false。这将隐藏任务栏中的窗口。

在最小化时可能需要一些额外的代码来正确隐藏窗口。



private < font color ="#0000ff"> void InitializeComponent()
{
   ...
    this .ShowInTaskbar = false ;
}

private void notifyIcon1_DoubleClick( object sender,System.EventArgs e)
{
    //双击托盘图标时返回窗口
    this .Show();
     .WindowState = FormWindowState.Normal;
}

private
void MainForm_Resize( object sender,System.EventArgs e)
{
    //如果windows被删除 - >隐藏它
    if this .WindowState == FormWindowState.Minimized)
    {
       this .Hide();
  ;  }
}

 



Does anyone know how to set the owner of a window (which my process does not own). I can get the Owner of the window through the API call GetWindow(hWnd, GW_OWNER). But I need to set it.

Just some background... I am trying to write a program to hide windows from the taskbar (and add them to the system tray). Adding them to the system tray is easy, but I cannot get them to hide from the taskbar. I do not want to use ShowWindow(hWnd, SW_HIDE) because I want the window itself to still be visible. By setting SetWindowLong(hWnd, GWL_EXSTYLE, ! WS_EX_APPWINDOW) (not quite like that - but the idea is I remove that flag), I believe I can remove a Window from the Taskbar, but only if the Window has an owner. This is how Visual Basic seems to do it - the owner of a top-level window which is not supposed to be in the taskbar is some hidden window called "WindowsFormsParkingWindow"

解决方案

If I understand you correcty - you only want to hide a Form from the Taskbar. There is no need to do native interop for that.

Just set the System.Windows.Forms.From property ShowInTaskbar to false. This will hide the windows from the taskbar.

Some additional code might be required to properly hide the window when minimized.



private void InitializeComponent ()
{
   ...
   this.ShowInTaskbar = false;
}

private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
   // bring back the window when double click on tray icon
   this.Show ();
   this.WindowState = FormWindowState.Normal;
}

private
void MainForm_Resize (object sender, System.EventArgs e)
{
   // if windows got miminized -> hide it
   if (this.WindowState == FormWindowState.Minimized)
   {
      this.Hide ();
   }
}

 



Hope this solves your problem.


这篇关于设置窗口所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆