EnumChildWindows
解决方案 »
- 取记录某个字段值不成功
- 请问大家如何执行一段SQL脚本?
- (未解决..在线等待...) 小弟正在试做一个MP3播放器,想用TRACKBAR跟踪播放的进度,可是用TrackBar1.max:=MedliaPlayer1.length传递给Trac
- 怎样取一字符串的一个子串,应该用什么函数?在线等待
- 程序员没有GF,编程还有动力吗?
- 请问:M/D 关系的数据怎么打印?具体看内容!
- 各位高手,请指教,我只有一天的时间了。在线等待
- 你一定得进来看看(有关日期运算)
- 高手请进:关于存大字段问题(Blob形)
- Socket问题??
- ADO批量提交問題?
- 编程一定要有MSDN呢?是不是一定要弄懂win的消息机制呢?
Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
说明
为指定的父窗口枚举子窗口
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
hWndParent Long,欲枚举子窗口的父窗口的句柄
lpEnumFunc Long,为每个子窗口调用的函数的指针。用AddressOf运算符获得函数在一个标准模块中的地址
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.)
注解
在vb4下要求dwcbkd32.ocx定制控件。子窗口下属的子窗口也可由这个函数枚举
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);
ParametershWndParentIdentifies the parent window whose child windows are to be enumerated. lpEnumFuncPoints to an application-defined callback function. For more information about the callback function, see the EnumChildProc callback function. lParamSpecifies a 32-bit, application-defined value to be passed to the callback function. Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. ResThe EnumChildWindows function does not enumerate top-level windows owned by the specified window, nor does it enumerate any other owned windows.
If a child window has created child windows of its own, this function enumerates those windows as well.
A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated. The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process. This function is more reliable than calling the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.
我举例说名:
type
PFindWindowStruct=^TFindWindowStruct;
TFindWindowStruct=Record
ClassName:String;
WindowHandle:THandle;
定义一个指向记录类型的指针
**************************(1):
Procedure WriteToMK_YG(rBIL_NO,rBIL_ID:String);
Var
TheWindowHandle:THandle;
begin
TheWindowHandle:=FindAWindow('TMrpEG4Form');调用函数FindAWindow
是为了不用FindWindow(要Caption)
。
END
***********************************(2):
function FindAWindow(ClassName:String):THandle;
Var
WindowInfo:TFindWindowStruct;
begin
WindowInfo.ClassName:=UpperCase(ClassName);//记录的数值
WindowInfo.WindowHandle:=0;
EnumChildWindows//api(Application.MainForm.handle,@EnumChildWindowsProc,LongInt(@WindowInfo));
FindAWindow:=WindowInfo.WindowHandle;
end;
//第一个Application.MainForm.handle是主窗体的句柄
//@EnumChildWindowsProc 指向一个回掉函数的地址。
//取记录类型的地址
****************************************************(3)
function EnumChildWindowsProc(hWindow:hWnd;lParam:LongInt):Bool
{$IFDEF Win32}stdcall;{$ELSE};export;{$ENDIF}
//注意回掉函数的参数和掉用这个函数EnumChildWindows参数的数量和类型,hWnd就是EnumChildWindows中的Application.MainForm.handle,
lParam就是EnumChildWindows中的LongInt(@WindowInfo),回掉函数循环的找
var
lpBuffer:PChar;
ClassNameFound:bool;
begin
GetMem(lpBuffer,255);//给变量分配大小
Result:=True;
ClassNameFound:=False;
try
if GetClassName(hWindow,lpBuffer,255)>0 then//放到lpBuffer中
if Pos(PFindWindowStruct(lParam).ClassName,UpperCase(StrPas(lpBuffer)))>0 then//找到了!
// PFindWindowStruct(lParam).ClassName就是结构体长用的写发 ClassNameFound:=True;
if ClassNameFound then
begin
PFindWindowStruct(lParam).WindowHandle:=hWindow;//保存句柄
Result:=False;
end;
finally
FreeMem(lpBuffer,sizeof(lpBuffer^));
end;
end;
程序笔记!见笑了!