且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置窗口所有者

更新时间:2023-02-21 07:53:48

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

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

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



private 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();
&nbsp ;  }
}

 




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.