C# winform程序得到当前所有窗体 C# winform程序中,怎么判断当前程序已经打开的窗口 是否有指定的窗体类的 实例?如果有 就激活这个窗体类实例,没有就新建一个窗体。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static bool SearchAllForm(string FormName) { for (int i = 0; i < Application.OpenForms.Count; i++) { if (Application.OpenForms[i].Name == FormName) { return true; } } return false; } foreach (Form forms in Application.OpenForms) { }public delegate bool EnumWindowsProc(IntPtr p_Handle, int p_Param); [DllImport("user32.dll")] public static extern int EnumWindows(EnumWindowsProc ewp, int lParam); [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern int GetWindowText(IntPtr hWnd, out STRINGBUFFER text, int nMaxCount); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); [DllImport("user32.dll")] public static extern IntPtr GetWindowThreadProcessId(IntPtr hwnd, ref int lpdwProcessId); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct STRINGBUFFER { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] public string szText; } private void button1_Click(object sender, EventArgs e) { MessageWindwos(); } public void MessageWindwos() { EnumWindowsProc _EunmWindows = new EnumWindowsProc(NetEnumWindows); EnumWindows(_EunmWindows, 0); } private bool NetEnumWindows(IntPtr p_Handle, int p_Param) { if (!IsWindowVisible(p_Handle))return true; STRINGBUFFER _TitleString = new STRINGBUFFER(); GetWindowText(p_Handle, out _TitleString, 256); MessageBox.Show(_TitleString.szText); ///获取的窗体 return true; } C# Timer C#连接数据字符问题 new SqlConnection(strConn) 用socket传图片的问题 请演示一下IComparable 接口和 IComparer接口用法。不太懂。 我想问的是:C# 内存问题 一个很菜的问题 怎样用TCP异步收POP3邮件,要winform代码! 如何定义一个数据库安全类,验证超级管理员的用户名和密码 ASO.Net和Oracle9i 的问题? c#中的控件问题 哪位大牛来介绍下泛型???(附个人理解)
{
for (int i = 0; i < Application.OpenForms.Count; i++)
{
if (Application.OpenForms[i].Name == FormName)
{
return true;
}
}
return false;
}
{ }public delegate bool EnumWindowsProc(IntPtr p_Handle, int p_Param);
[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowText(IntPtr hWnd, out STRINGBUFFER text, int nMaxCount);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hwnd, ref int lpdwProcessId);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct STRINGBUFFER
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)]
public string szText;
} private void button1_Click(object sender, EventArgs e)
{
MessageWindwos();
} public void MessageWindwos()
{ EnumWindowsProc _EunmWindows = new EnumWindowsProc(NetEnumWindows);
EnumWindows(_EunmWindows, 0);
}
private bool NetEnumWindows(IntPtr p_Handle, int p_Param)
{
if (!IsWindowVisible(p_Handle))return true; STRINGBUFFER _TitleString = new STRINGBUFFER();
GetWindowText(p_Handle, out _TitleString, 256); MessageBox.Show(_TitleString.szText); ///获取的窗体
return true;
}