Solved

Bring window to Front

Posted on 2001-08-29
8
702 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
Comment Utility
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
Comment Utility
You can use SetWindowPos API function
0
 
LVL 2

Expert Comment

by:Tasomia
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:YodaMage
Comment Utility
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
Comment Utility
Thanks All.

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

Expert Comment

by:edey
Comment Utility
Glad to be of service :)

GL
Mike
0
 
LVL 1

Author Comment

by:vterekh
Comment Utility
to edey

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

17 Experts available now in Live!

Get 1:1 Help Now