关于API中EnumChildWindows 这个的参数问题

tavor 2003-04-23 07:52:17
EnumChildWindows

VB声明
Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

lParam Long,在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的。(原文:Value that is passed to the EnumWindows event of the dwcbkd32.ocx custom control during enumeration. The meaning of this value is defined by the programmer.)

我不太懂其中lParam的调用问题,请高手指教.
...全文
991 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tavor 2003-05-14
  • 打赏
  • 举报
回复
UP
tavor 2003-05-04
  • 打赏
  • 举报
回复
完整的如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading ;
using System.Diagnostics ;
using Microsoft.Win32 ;
using System.Text ;
using System.Runtime.InteropServices ;
namespace Server1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ListBox listBox1;
private System.ComponentModel.IContainer components;
public delegate bool EnumChildWindowsProc(IntPtr hwnd, long lParam);
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 128);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(120, 16);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 88);
this.listBox1.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listBox1,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private static void StartListening()
{
Process [] f=Process.GetProcesses();
foreach (Process f2 in f)
{
if(f2.ProcessName.Equals("WSetValue")&&f2.MainWindowTitle.Equals("Form1"))
{
IntPtr hWndParent=f2.MainWindowHandle;
EnumChildWindowsProc myEnumChild = new EnumChildWindowsProc(EumWinChiPro);
try
{
EnumChildWindows(hWndParent,myEnumChild,0);
}
catch(Exception){}
}
}
}

private void button1_Click(object sender, System.EventArgs e)
{
try
{
StartListening();
//GetWindows();
}
catch(Exception){}
}

private void Form1_Load(object sender, System.EventArgs e)
{

}

private void timer1_Tick(object sender, System.EventArgs e)
{
StartListening();
}
[DllImport("user32.dll")]
public static extern long EnumChildWindows(IntPtr hWndParent, EnumChildWindowsProc lpEnumFunc,long lParam);
[DllImport("user32.dll")]
public static extern long GetClassName(IntPtr hwnd,StringBuilder lpClassName,long nMaxCount);
private static bool EumWinChiPro(IntPtr hWnd,long lParam)
{
StringBuilder s=new StringBuilder (256);
GetClassName(hWnd,s,257);
string ss=s.ToString ();
ss=ss.Trim();
MessageBox.Show(ss);
return true;
}
}
}
tavor 2003-05-04
  • 打赏
  • 举报
回复
我在获得一个应用程序的PID后,获得进程,用EnumChildWindows方法来枚举它的控件,成功!!!!


可是在枚举完它的控件后,会抛出一个异常!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading ;
using System.Diagnostics ;
using Microsoft.Win32 ;
using System.Text ;
using System.Runtime.InteropServices ;
namespace Server1
{
public class Form1 : System.Windows.Forms.Form
{
public delegate bool EnumChildWindowsProc(IntPtr hwnd, long lParam);
public Form1()
{
static void Main()
{
Application.Run(new Form1());
}
private static void StartListening()
{
Process [] f=Process.GetProcesses();
foreach (Process f2 in f)
{
if(f2.ProcessName.Equals("WSetValue")&&f2.MainWindowTitle.Equals("Form1"))
{
IntPtr hWndParent=f2.MainWindowHandle;
EnumChildWindowsProc myEnumChild = new EnumChildWindowsProc(EumWinChiPro);
try
{
EnumChildWindows(hWndParent,myEnumChild,0);
}
catch(Exception){}
}
}
}

private void button1_Click(object sender, System.EventArgs e)
{
try
{
StartListening();
}
catch(Exception){}
} [DllImport("user32.dll")]
public static extern long EnumChildWindows(IntPtr hWndParent, EnumChildWindowsProc lpEnumFunc,long lParam);
[DllImport("user32.dll")]
public static extern long GetClassName(IntPtr hwnd,StringBuilder lpClassName,long nMaxCount);
private static bool EumWinChiPro(IntPtr hWnd,long lParam)
{
StringBuilder s=new StringBuilder (256);
GetClassName(hWnd,s,257);
string ss=s.ToString ();
ss=ss.Trim();
MessageBox.Show(ss);
return true;
}
}


不太重要的地方我删掉了,大伙帮我看看吧
Knight94 2003-04-28
  • 打赏
  • 举报
回复
listBox1是用来显示的。
tavor 2003-04-27
  • 打赏
  • 举报
回复
我说的是枚举一个窗口上的控件,其中第三个参数不会用,
楼上大哥说的我也不明白,为什么要用listBox的Handle呢.讲清楚些好吗?
Knight94 2003-04-24
  • 打赏
  • 举报
回复
[DllImport("user32.Dll")]
public static extern int EnumWindows(CallBack x, int y);

public delegate bool IECallBack(int hwnd, int lParam);

调用
private void GetIE_Click(object sender, System.EventArgs e)
{
listBoxHandle = listBox1.Handle; //store a listbox handle here.
EnumWindows (new CallBack (IEInstance.EnumWindowCallBack),
(int)listBoxHandle) ;
label1.Text = "Total Instances of Internet Explorer : "+i;
}

顾君彦 2003-04-23
  • 打赏
  • 举报
回复
建议先看一下EnumWindows的调用方法,微软网站上有搜索一下。
tavor 2003-04-23
  • 打赏
  • 举报
回复
我用以下来调用,
IntPtr hWndParent=f2.MainWindowHandle;
CallBack myCallBack = new CallBack(EumWinChiPro);
EnumChildWindows(hWndParent,myCallBack,0);
可是会出现System.ExecutionEngineException异常,而且不论我把try catch加在什么地方都会这个异常,不知道是什么原因,请大哥们指点一下.
TheAres 2003-04-23
  • 打赏
  • 举报
回复
看这个例子

http://www.c-sharpcorner.com/Code/2002/Nov/winghost.asp

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧