EnumChildWindows

解决方案 »

  1.   

    这函数是列举当前主窗口句柄中的子窗口 的一个API函数,是一个标准化的回调函数,这样可以取到子窗口的信息。祝:身体健康!
      

  2.   

    EnumChildWindows VB声明 
    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定制控件。子窗口下属的子窗口也可由这个函数枚举
     
      

  3.   

    You can find the ans from the web www.delphi32.com
      

  4.   

    The EnumChildWindows function enumerates the child windows that belong to the specified parent window by passing the handle of each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE. BOOL EnumChildWindows(    HWND hWndParent, // handle to parent window
        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.
      

  5.   

    上面的人说的都对,但是没有说到重点:
    我举例说名:
    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;
    程序笔记!见笑了!