Solved

Bring window to Front

Posted on 2001-08-29
8
706 Views
Last Modified: 2010-05-18
hi
what kind of message and parameters should i send to window using SendMessage API to bring it to front or send it to back?
0
Comment
Question by:vterekh
8 Comments
 
LVL 6

Accepted Solution

by:
edey earned 30 total points
ID: 6437175
I wouldn't think you'd use a message - use setFocus instead.

//Bring the current form to the front
setFocus;

//Bring some other form to the front
windows.setFocus(some_windows_handle);

GL
Mike
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6437199
You can use SetWindowPos API function
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6438399
I use this function:

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 <dannys@karemor.com>

        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; { ForceForegroundWindow }
0
 
LVL 3

Expert Comment

by:VSF
ID: 6438499
If you are talking about bringing MDI Child forms to Front you should try:

MyForm.bringtofront;

Hope this helps!

VSF
www.victory.hpg.com.br
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:YodaMage
ID: 6438651
ActiveControl := TForm; (I hate set focus...too many problems in the past trying to set focus before changing visible or enabled properties)

TForm.Show; should also work.
0
 
LVL 1

Author Comment

by:vterekh
ID: 6439345
Thanks All.

edey's answer is more appropriated for my purposes.
0
 
LVL 6

Expert Comment

by:edey
ID: 6440538
Glad to be of service :)

GL
Mike
0
 
LVL 1

Author Comment

by:vterekh
ID: 6440573
to edey

Mike
By the way I've found that BringWindowToTop function exists declared in windows unit too :))
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now