刚刚才学的D7,想做个遍列窗口的小程序,可这enmuwindow就是不听话,怎么写都不行
哪位老师有空,帮写个带注的例子参考学习下。谢谢。

解决方案 »

  1.   

    参考
    http://topic.csdn.net/t/20011006/19/313689.html
    http://delphi.ktop.com.tw/board.php?cid=31&fid=79&tid=49824
      

  2.   

    是你的遍历写的不对。enmuwindow很听话的。例如:procedure TForm1.Button1Click(Sender: TObject);
    var
    Child:THandle;
    h:HWND;
    begin
    WinExec('calc',1);
    Sleep(1000);
    h:=FindWindow(0,'计算器');
    if h=0 then exit;Child:=findwindowex(h,0,pchar('Button'),nil);
    enablewindow(Child,false);
    while Child<>0 do
    begin
    Child:=findwindowex(h,Child,pchar('Button'),nil);
    enablewindow(Child,false);
    end;
    Child:=findwindowex(h,0,pchar('Edit'),nil);
    enablewindow(Child,false);
    while Child<>0 do
    begin
    Child:=findwindowex(h,Child,pchar('Edit'),nil);
    enablewindow(Child,false);
    end;end;
      

  3.   

    二楼的不乖了,你说enmuwindows听话?却给我搜寻子窗体代码?呵呵是帖错了吧?
      

  4.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}function GetWindows(
        handle: HWND; // handle to parent window
        WinList: TList  // application-defined value
       ): Boolean; stdcall;
    begin   {}
      Result := True;
      WinList.Add(Pointer(handle));
    end;function GetWindowNames(WinNames: TStrings): HWnd;
    var
      i: integer;
      Dest: array [0..80] of char;
      WindowList: TList;
    begin
      Result := 0;
      WindowList := TList.Create();
      EnumWindows(@GetWindows, integer(WindowList));
      for i := 0 to WindowList.Count - 1 do
      begin
       if GetWindowText(Hwnd(WindowList[i]), Dest, Sizeof(Dest) - 1) > 0 then
         if ISwindowVisible(Hwnd(WindowList[i])) then // 过滤隐藏的窗口
           WinNames.Add(Dest);
      end;
      WindowList.Free();
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      GetWindowNames(ListBox1.Items);
    end;end.
      

  5.   


    我的代码没有贴错,对于计算器,这样是可以的。如果想写成万能的,就用EnumWindows函数吧。