将窗体显示在最前面。我在form1窗体放了三个button1.button2,button3
分别用来显示form2和form3的。button1.onclick;内容如下。form2:=Tform2.create(application);
form2.parent:=form1;
form2.showl;button2.onclickform3:=Tform3.create(application);
FORM3.parent:=form1.
form3.show;
点击button3的时候怎样让button1显示在最前面, 知道窗体的句柄。
如果没有FORM3.parent:=form1.和form2.parent:=form1;是非常好实现。
有没有人遇到过我要求的这种问题.

解决方案 »

  1.   

    用setactivewindow试试
      SetActiveWindow(form1.Handle);
      

  2.   

    用以下函数
    function ForceForegroundWindow(hwnd: THandle): boolean;
    const
      SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
      SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
    var
      ForegroundThreadID: DWORD;
      ThisThreadID      : DWORD;
      timeout           : DWORD;
    begin
      if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE);  if GetForegroundWindow = hwnd then Result := true
      else begin    // Windows 98/2000 doesn't want to foreground a window
        //when some other
        // window has keyboard focus    if ((Win32Platform = VER_PLATFORM_WIN32_NT) and
    (Win32MajorVersion > 4)) or
          ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
          ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
    (Win32MinorVersion > 0)))) then
          begin      // Code from Karl E. Peterson,www.mvps.org/vb/sample.htm
          // Converted to Delphi by Ray Lischner
          // Published in The Delphi Magazine 55, page 16      Result := false;
          ForegroundThreadID := GetWindowThreadProcessID
    (GetForegroundWindow,nil);
          ThisThreadID := GetWindowThreadPRocessId(hwnd,nil);
          if AttachThreadInput(ThisThreadID, ForegroundThreadID,
    true) then
          begin
            BringWindowToTop(hwnd); // IE 5.5 related hack
            SetForegroundWindow(hwnd);
            AttachThreadInput(ThisThreadID, ForegroundThreadID,
    false);
            Result := (GetForegroundWindow = hwnd);
          end;
          if not Result then begin        // Code by Daniel P. Stasinski        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
    @timeout, 0);
            SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
    TObject(0), SPIF_SENDCHANGE);
            BringWindowToTop(hwnd); // IE 5.5 related hack
            SetForegroundWindow(hWnd);
            SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
    TObject(timeout), SPIF_SENDCHANGE);
          end;
        end
        else begin
          BringWindowToTop(hwnd); // IE 5.5 related hack
          SetForegroundWindow(hwnd);
        end;    Result := (GetForegroundWindow = hwnd);
      end;
    end;
      

  3.   

    sorry,没看清楚问题使用Button的BringToTop可以暂时性置前,
    上面的函数也可以让他暂时置前,想总置前还需要研究!
    呵呵,我也懒得研究,等人吧!
      

  4.   

    楼上的,你的方法可以解决我的问题,是你自己搞出来的吗?你有改过这段源程序。 原本好向是delphi自身带的对不。谢谢你了。我还以为没人会呀。 你知道吗? 这个问题问过很多的人。没人会。只有你现在的办法可以达到要求。
      

  5.   

    此函数不是我写的,出处也想不起来了!sorry!:)
      

  6.   

    让Button1首先执行请用发消息的方法,或者直接调用Button1的Click事件;
    获得窗口的句柄可用如下方法:
    procedure TForm1.Button3Click(Sender: TObject);
    var
      hCurrentWindow: HWnd;
      szText: array[0..254] of char;
    begin
      hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
      while hCurrentWindow <> 0 do
      begin
        if GetWindowText(hCurrentWindow, @szText, 255) > 0 then
        Memo1.Lines.Add(StrPas(@szText));
        hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
      end;
    end;
      

  7.   

    =======================================
    这里找不到答案吗?来这里试试看!
    这里有问必答
    http://systemer.51.net/cgi-bin/leoboard.cgi
    希望你能在这里找到你满意的答案
    =========================================
      

  8.   

    我指的是fenglic(风中之城),不过你的热情助人的精神值和我佩服。我发现
    csdn比大富翁气氛活多了。