关于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的调用问题,请高手指教.
...全文
957 9 打赏 收藏 转发到动态 举报
写回复
用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
API之网络函数1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同一个网络资源的连接 WNetCancelConnection 结束一个网络连接 WNetCancelConnection2 结束一个网络连接 WNetCloseEnum 结束一次枚举操作 WNetConnectionDialog 启动一个标准对话框,以便建立同网络资源的连接 WNetDisconnectDialog 启动一个标准对话框,以便断开同网络资源的连接 WNetEnumResource 枚举网络资源 WNetGetConnection 获取本地或已连接的一个资源的网络名称 WNetGetLastError 获取网络错误的扩展错误信息 WNetGetUniversalName 获取网络一个文件的远程名称以及/或者UNC(统一命名规范)名称 WNetGetUser 获取一个网络资源用以连接的名字 WNetOpenEnum 启动对网络资源进行枚举的过程 2. API之消息函数 BroadcastSystemMessage 将一条系统消息广播给系统所有的顶级窗口 GetMessagePos 取得消息队列上一条消息处理完毕时的鼠标指针屏幕位置 GetMessageTime 取得消息队列上一条消息处理完毕时的时间 PostMessage 将一条消息投递到指定窗口的消息队列 PostThreadMessage 将一条消息投递给应用程序 RegisterWindowMessage 获取分配给一个字串标识符的消息编号 ReplyMessage 答复一个消息 SendMessage 调用一个窗口的窗口函数,将一条消息发给那个窗口 SendMessageCallback 将一条消息发给窗口 SendMessageTimeout 向窗口发送一条消息 SendNotifyMessage 向窗口发送一条消息 3. API之文件处理函数 CloseHandle 关闭一个内核对象。其包括文件、文件映射、进程、线程、安全和同步对象等 CompareFileTime 对比两个文件的时间 CopyFile 复制文件 CreateDirectory 创建一个新目录 CreateFile 打开和创建文件、管道、邮槽、通信服务、设备以及控制台 CreateFileMapping 创建一个新的文件映射对象 DeleteFile 删除指定文件 DeviceIoControl 对设备执行指定的操作 DosDateTimeToFileTime 将DOS日期和时间值转换成一个 win32 FILETIME 值 FileTimeToDosDateTime 将一个 win32 FILETIME 值转换成DOS日期和时间值 FileTimeToLocalFileTime 将一个FILETIME结构转换成本地时间 FileTimeToSystemTime 根据一个FILETIME结构的内容,装载一个SYSTEMTIME结构 FindClose 关闭由FindFirstFile函数创建的一个搜索句柄 FindFirstFile 根据文件名查找文件 FindNextFile 根据调用FindFirstFile函数时指定的一个文件名查找下一个文件 FlushFileBuffers 针对指定的文件句柄,刷新内部文件缓冲区 FlushViewOfFile 将写入文件映射缓冲区的所有数据都刷新到磁盘 GetBinaryType 判断文件是否可以执行 GetCompressedFileSize 判断一个压缩文件在磁盘上实际占据的字节数 GetCurrentDirectory 在一个缓冲区装载当前目录 GetDiskFreeSpace 获取与一个磁盘的组织有关的信息,以及了解剩余空间的容量 GetDiskFreeSpaceEx 获取与一个磁盘的组织以及剩余空间容量有关的信息 GetDriveType 判断一个磁盘驱动器的类型 GetExpandedName 取得一个压缩文件的全名 GetFileAttributes 判断指定文件的属性 GetFileInformationByHandle 这个函数提供了获取文件信息的一种机制 GetFileSize 判断文件长度 GetFileTime 取得指定文件的时间信息 GetFileType 在给出文件句柄的前提下,判断文件类型 GetFileVersionInfo 从支持版本标记的一个模块里获取文件版本信息

110,537

社区成员

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

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

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