现在我已经取得了一个对话框的句柄,想使用EnumChildWindows遍历它的每个子窗体,取得每个子窗体的标题名称谁给个示列啊
解决方案 »
- C#.NET SQL局域网连接问题
- TABPAGE 与 Validating
- c#main函数里面的args参数到底是几维数组?还是交错数组
- 各位朋友, 我想在系统里边做一个串口通信功能,读取卡上的数据 通过RS232总线
- Process 访问权限
- 各位弟兄,帮帮忙吧,兄弟我先谢谢各位了,时间间隔问题?
- 基础问题?
- 求各位大虾,在C#下用什么类来实现是想把应用的日志记录在一个自定义的日志文件中。比如j2ee中的log4j这种日志工具
- C#初学者学完语法和面向对象基础下一步应该看点什么?进者有分。
- c#调用activex控件参数传递问题
- C# progressbar 如何实现加载图片显示进度
- C# 要获取网页由 js 或asp 产生的内容怎么办呢?
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(this.Handle);
} public void MessageWindwos(IntPtr p_MessIntPrt)
{
GetWindowThreadProcessId(p_MessIntPrt, ref m_Pid); //消息进程 EnumWindowsProc _EunmWindows = new EnumWindowsProc(NetEnumWindows);
EnumWindows(_EunmWindows, 0);
}
private int m_Pid = 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); int _PID = -1;
GetWindowThreadProcessId(p_Handle, ref _PID); //获取进程PID if (_PID == m_Pid)
{
MessageBox.Show(_TitleString.szText);
}
return true;
}
不知道是不是这个意思...根据你获取的消息获取进程ID 然后比较进程ID
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPrivate Sub Command1_Click()
Dim tWnd As Long, hWnd As Long
tWnd = FindWindow(vbNullString, "QQ2008 查找/添加好友") hWnd = FindWindowEx(tWnd, 0, vbNullString, vbNullString)
If hWnd <> 0 Then GetName hWnd
Do While hWnd <> 0
hWnd = FindWindowEx(tWnd, hWnd, vbNullString, vbNullString)
If hWnd <> 0 Then GetName hWnd
Loop
End Sub
Private Function GetName(ByVal hWnd As Long) As String
Dim lpClassName As String
Dim retval As Long
Dim mname As String
Dim i As Integer lpClassName = Space(256)
retval = GetClassName(hWnd, lpClassName, 256)
i = InStr(1, lpClassName, Chr(0))
mname = Left(lpClassName, i - 1)
Debug.Print hWnd & " " & mname
End Function