C# SendMessage show window
- User
C# SendMessage show window
- Assistant
To show a window using the SendMessage function in C#, you need to pass the WM_SHOWWINDOW message to the target window handle. Here's an example:
using System; using System.Runtime.InteropServices; public class Program { [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); private const int WM_SHOWWINDOW = 0x0018; public static void Main(string[] args) { IntPtr hWnd = FindWindow(null, "Window Title"); // Replace "Window Title" with the actual title of the window you want to show if (hWnd != IntPtr.Zero) { SendMessage(hWnd, WM_SHOWWINDOW, IntPtr.Zero, IntPtr.Zero); } else { Console.WriteLine("Window not found."); } } }In this example, the function is used to find the window handle (hWnd) of the target window using its title. Replace with the actual title of the window you want to show.
- User
C# SendMessage hide window
- Assistant
To hide a window using the SendMessage function in C#, you need to pass the WM_HIDE message to the target window handle. Here's an example:
using System; using System.Runtime.InteropServices; public class Program { [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); private const int WM_HIDE = 0x0080; public static void Main(string[] args) { IntPtr hWnd = FindWindow(null, "Window Title"); // Replace "Window Title" with the actual title of the window you want to hide if (hWnd != IntPtr.Zero) { SendMessage(hWnd, WM_HIDE, IntPtr.Zero, IntPtr.Zero); } else { Console.WriteLine("Window not found."); } } }In this example, the
FindWindowfunction is used to find the window handle (hWnd) of the target window using its title. Replace with the actual title of the window you want to hide.