如题换句话说就是:主窗口出现后能不能知道工程中所有的Form有多少个请不要说类似Application.MainForm.MDIChildCount的答案

解决方案 »

  1.   

    EnumChildWindows 
    这是一个回调函数,应该可以完成你的功能.ParentHandle,设为Application.Handle
      

  2.   

    procedure addwindowInfo(hw:Hwnd);stdcall;//指定回调函数
    var
      windowname,windowclass:array[0..144] of char;
      windowInfo:TWindowInfo;
    begin
      GetWindowText(hw,windowname,144);
      GetClassName(hw,windowclass,144);
      windowInfo:=TWindowInfo.Create;
      with windowinfo do
      begin
        setlength(winname,strlen(windowname));
        setlength(winclass,strlen(windowclass));
        winname:=strpas(windowname);
        winclass:=strpas(windowclass);
      end;
      Form1.ListBox1.Items.AddObject('',windowinfo);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    var
      i:integer;
    begin
      for i:=0 to Listbox1.Items.Count-1 do
        Listbox1.Items.Objects[i].Free;
    end;procedure TForm1.windowinfoSectionResize(HeaderControl: THeaderControl;
      Section: THeaderSection);
    begin
      Listbox1.Invalidate;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ListBox1.Items.Clear;
      EnumWindows(@addwindowinfo,0);//找窗口
    end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
       Listbox1.Canvas.FillRect(Rect);
      with TWindowInfo(Listbox1.Items.Objects[index]) do
      begin
        DrawText(Listbox1.canvas.Handle,Pchar(winname),length(winname),Rect,dt_left or dt_vCenter );
        Rect.Left:=Rect.Left+windowinfo.Sections[0].Width;
        DrawText(Listbox1.Canvas.Handle,Pchar(winclass),length(winclass),Rect,dt_left or dt_wordbreak);
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin  for I :=0 to  Screen.FormCount-1  do
          ListBox1.Items.Add(Screen.Forms[I].Name);
    end;
      

  4.   

    to 回复人: madyak(无天) ( ) 信誉:120 你的不行
    因为我的窗口没有建立
      

  5.   

    不好意思,我是初学者,还是不知道怎么用,
    [Error] uMain.pas(21): Undeclared identifier: 'THeaderControl'
    [Error] uMain.pas(22): Undeclared identifier: 'THeaderSection'
    [Error] uMain.pas(41): Object or class type required
    [Error] uMain.pas(44): Undeclared identifier: 'winname'
    [Error] uMain.pas(45): Undeclared identifier: 'winclass'
    [Error] uMain.pas(49): Incompatible types: 'TObject' and 'tagWINDOWINFO'
    [Error] uMain.pas(57): ';' expected but '.' found
    [Error] uMain.pas(60): Undeclared identifier: 'Listbox1'
    [Error] uMain.pas(80): Invalid typecast
    [Error] uMain.pas(82): Undeclared identifier: 'winname'
    [Error] uMain.pas(82): Incompatible types
    [Error] uMain.pas(83): Undeclared identifier: 'windowinfo'
    [Error] uMain.pas(83): Missing operator or semicolon
    [Error] uMain.pas(83): Missing operator or semicolon
    [Error] uMain.pas(84): Undeclared identifier: 'winclass'
    [Error] uMain.pas(84): Incompatible types
    [Error] uMain.pas(91): Undeclared identifier: 'ParentHandle'
    [Hint] uMain.pas(21): Private symbol 'windowinfoSectionResize' declared but never used
    [Fatal Error] prjWsERP.dpr(8): Could not compile used unit 'pas\uMain.pas'