Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Hiding a window

Hiding a window

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mamtz
    wrote on last edited by
    #1

    Hi I wrote a simple program that should find a specific window and hide it. Somehow the window is actually being close (Its process is killed) and the weirdest thing is that the taskbar is also hides. Here is my code: public const int SW_HIDE = 0; [DllImport("user32.dll")] public static extern int ShowWindow(IntPtr hwnd,int nCmdShow); private void button1_Click(object sender, System.EventArgs e) {    string title=textBox1.Text; //gets the window title from a testbox.    Process[] plist =Process.GetProcesses();    foreach(Process p in plist){       if(title.IndexOf(p.MainWindowTitle)>=0){          ShowWindowAsync(p.MainWindowHandle,SW_HIDE);       }    } } Can you see the problem? what is it? or how can i hide a window without closing it? Thank a lot Mamtz

    M 1 Reply Last reply
    0
    • M mamtz

      Hi I wrote a simple program that should find a specific window and hide it. Somehow the window is actually being close (Its process is killed) and the weirdest thing is that the taskbar is also hides. Here is my code: public const int SW_HIDE = 0; [DllImport("user32.dll")] public static extern int ShowWindow(IntPtr hwnd,int nCmdShow); private void button1_Click(object sender, System.EventArgs e) {    string title=textBox1.Text; //gets the window title from a testbox.    Process[] plist =Process.GetProcesses();    foreach(Process p in plist){       if(title.IndexOf(p.MainWindowTitle)>=0){          ShowWindowAsync(p.MainWindowHandle,SW_HIDE);       }    } } Can you see the problem? what is it? or how can i hide a window without closing it? Thank a lot Mamtz

      M Offline
      M Offline
      Marc 0
      wrote on last edited by
      #2

      You can try this:

      [Flags]
      public enum SWP
      {
      SWP_ASYNCWINDOWPOS = 0x4000,
      SWP_DEFERERASE = 0x2000,
      SWP_DRAWFRAME = 0x20,
      SWP_FRAMECHANGED = 0x20,
      SWP_HIDEWINDOW = 0x80,
      SWP_NOACTIVATE = 0x10,
      SWP_NOCOPYBITS = 0x100,
      SWP_NOMOVE = 2,
      SWP_NOOWNERZORDER = 0x200,
      SWP_NOREDRAW = 8,
      SWP_NOREPOSITION = 0x200,
      SWP_NOSENDCHANGING = 0x400,
      SWP_NOSIZE = 1,
      SWP_NOZORDER = 4,
      SWP_REDRAWONLY = 0x717,
      SWP_SHOWWINDOW = 0x40
      }

      [DllImport("User32.dll", CharSet=CharSet.Auto)]
      public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

      private static SWP hideFlags = SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_HIDEWINDOW

      // Put this in your code instead of ShowWindowAsync
      SetWindowPos(p.MainWindowHandle, IntPtr.Zero, 0, 0, 0, 0, hideFlags);

      More info on MSDN[^]. Hope this works! :cool:


      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups