如何找到指定标题的窗口 隱藏窗口同樣要使用win32 API,函數為ShowWindow.具體使用請參閱MSDN. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给楼主一个查找包含有指定字符串的标题的所有窗口的代码,仅供参考,仅供参考:internal delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);internal delegate bool EnumChildrenCallback(IntPtr hwnd, IntPtr lParam);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]internal static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);[DllImport("user32.dll", ExactSpelling = true)]internal static extern bool EnumChildWindows(HandleRef hwndParent, EnumChildrenCallback lpEnumFunc, HandleRef lParam);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]internal static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);[DllImport("user32.dll", CharSet = CharSet.Auto)]internal static extern int GetWindowText(HandleRef hWnd, StringBuilder lpString, int nMaxCount);[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern int GetWindowTextLength(HandleRef hWnd);private bool EnumWindowsCallback(IntPtr handle, IntPtr extraParameter){ int capacity = GetWindowTextLength(new HandleRef(this, handle)) * 2; StringBuilder lpString = new StringBuilder(capacity); GetWindowText(new HandleRef(this, handle), lpString, lpString.Capacity); if (lpString.Length > 0 && lpString.ToString().IndexOf("工程") != -1) { Console.WriteLine(lpString.ToString()); EnumChildWindows(new HandleRef(null, handle), new EnumChildrenCallback(EnumChildWindowsCallBack), new HandleRef(null, IntPtr.Zero)); } return true;}private bool EnumChildWindowsCallBack(IntPtr handle, IntPtr lparam){ int capacity = GetWindowTextLength(new HandleRef(this, handle)) * 2; StringBuilder lpString = new StringBuilder(capacity); GetWindowText(new HandleRef(this, handle), lpString, lpString.Capacity); if (lpString.Length > 0 && lpString.ToString().IndexOf("工程") != -1) { Console.WriteLine(lpString.ToString()); EnumChildWindows(new HandleRef(null, handle), new EnumChildrenCallback(EnumChildWindowsCallBack), new HandleRef(null, IntPtr.Zero)); } return true;}private void button1_Click(object sender, EventArgs e){ EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(this.EnumWindowsCallback); EnumWindows(callback, IntPtr.Zero);} 上面的代码只是找到相应的窗口,但没有隐藏,可以使用如下API:[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]public static extern bool ShowWindow(HandleRef hWnd, int nCmdShow); 四楼正解,使用windows的一个窗口枚举器. 寻 "自动保存"及"程序异常退出重启后恢复原貌" 的最佳解决方案 WinForm 菜鸟问题:强名称和弱名称的程序集各有什么优缺点 C#里面类可以嵌套类吗? 如何去除字符串内的连续相同的字符 请问这段代码如何用C#实现? 急救!C#自定义控件编译报错! 用c#编写pc机与plc的串口通信(高分请教) VS2005水晶报表的时间格式问题,求解! 求一段打印图片的完整代码!! .NET 关于 面向对象编程 一个关于在C#中使用media player的问题 关于右键菜单(急啊)
internal delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);
internal delegate bool EnumChildrenCallback(IntPtr hwnd, IntPtr lParam);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);[DllImport("user32.dll", ExactSpelling = true)]
internal static extern bool EnumChildWindows(HandleRef hwndParent, EnumChildrenCallback lpEnumFunc, HandleRef lParam);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int GetWindowText(HandleRef hWnd, StringBuilder lpString, int nMaxCount);[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowTextLength(HandleRef hWnd);private bool EnumWindowsCallback(IntPtr handle, IntPtr extraParameter)
{
int capacity = GetWindowTextLength(new HandleRef(this, handle)) * 2;
StringBuilder lpString = new StringBuilder(capacity);
GetWindowText(new HandleRef(this, handle), lpString, lpString.Capacity);
if (lpString.Length > 0 && lpString.ToString().IndexOf("工程") != -1)
{
Console.WriteLine(lpString.ToString()); EnumChildWindows(new HandleRef(null, handle), new EnumChildrenCallback(EnumChildWindowsCallBack), new HandleRef(null, IntPtr.Zero));
}
return true;
}private bool EnumChildWindowsCallBack(IntPtr handle, IntPtr lparam)
{
int capacity = GetWindowTextLength(new HandleRef(this, handle)) * 2;
StringBuilder lpString = new StringBuilder(capacity);
GetWindowText(new HandleRef(this, handle), lpString, lpString.Capacity);
if (lpString.Length > 0 && lpString.ToString().IndexOf("工程") != -1)
{
Console.WriteLine(lpString.ToString());
EnumChildWindows(new HandleRef(null, handle), new EnumChildrenCallback(EnumChildWindowsCallBack), new HandleRef(null, IntPtr.Zero));
} return true;
}private void button1_Click(object sender, EventArgs e)
{
EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(this.EnumWindowsCallback);
EnumWindows(callback, IntPtr.Zero);
}
public static extern bool ShowWindow(HandleRef hWnd, int nCmdShow);