Hiding a window
-
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 -
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 MamtzYou 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