我每打开一个子窗口,都在主窗体的一个comboBox里面加一个条目,内容是子窗口的标题(caption),现在我想问的就是,如何根据选中的条目获得对应的子窗口的句柄?
还有,如果该子窗口最小化了,如何让他还原到最大化状态?(不是showwindow(hwnd,SW_Maximized),这个是当作顶级窗口最大化了,我要的是作为子窗口的最大化)

解决方案 »

  1.   

    mainform.MDIChildren属性存储了所有的子窗体
      with Form1 do
        for I := 0 to MDIChildCount do
          if MDIChildren[I].caption='...' then
            //do your thing
      

  2.   

    FindWindow('TForm1','FormsCaption') ;
      

  3.   

    function FindWindow(lpClassName: PChar, lpWindowName: PChar): HWND; // 如果类名不知道可以用 Nil 来指示
      

  4.   

    findwindow试过了,返回值是0,就是说没有找到
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DateUtils;type
      TMainForm = class(TForm)
        Button1: TButton;
        Button2: TButton;
        ComboBox1: TComboBox;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      MainForm: TMainForm;implementation{$R *.dfm}procedure TMainForm.Button1Click(Sender: TObject);
    begin
       ShowMessage(DateToStr(StartOfTheWeek(StrToDate('2003-3-22'))));
    end;procedure TMainForm.Button2Click(Sender: TObject);
    var
      I: Integer;
    begin
        for I := 0 to MDIChildCount - 1 do
          if MDIChildren[I].Caption = ComboBox1.Text then
          begin
            if MDIChildren[I].WindowState = wsMinimized then
              MDIChildren[I].WindowState := wsMaximized; 
            ShowMessage('句柄: $' + IntToHex(MDIChildren[I].Handle, 8));
            MDIChildren[I].BringToFront;
            break;
          end;
    end;end.
      

  6.   

    按照 NightCloud()和 xzgyb(老达摩) 的方法已经解决。谢谢大家