Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to force an overlapped or minimized window to the top Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Oct-02
Category
System
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

I cannot get my overlapped or minimized window to come to the top by hook or crook. 
I have tried the SetForegroundWindow, BringToTop and ShowWindow (show, restore) API 
calls using the form, application and the application.mainform handles. Every 
combination reacted the same. I get the visual clue of the application blinking on 
the task bar for about 5 seconds and that's it. It never comes to the top to be 
viewable. This is a Win98 SE test station.

Answer:
1   
2   function ForceForegroundWindow(hwnd: THandle): boolean;
3   const
4     SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
5     SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
6   var
7     ForegroundThreadID: DWORD;
8     ThisThreadID: DWORD;
9     timeout: DWORD;
10  begin
11    if IsIconic(hwnd) then
12      ShowWindow(hwnd, SW_RESTORE);
13    if GetForegroundWindow = hwnd then
14      Result := true
15    else
16    begin
17      {Windows 98/2000 doesn't want to foreground a window when some
18      other window has keyboard focus}
19      if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4))
20        or ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and ((Win32MajorVersion > 4)
21        or ((Win32MajorVersion = 4) and (Win32MinorVersion > 0)))) then
22      begin
23        {Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
24        Converted to Delphi by Ray Lischner
25        Published in The Delphi Magazine 55, page 16}
26        Result := false;
27        ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
28        ThisThreadID := GetWindowThreadProcessId(hwnd, nil);
29        if AttachThreadInput(ThisThreadID, ForegroundThreadID, true) then
30        begin
31          BringWindowToTop(hwnd); {IE 5.5 related hack}
32          SetForegroundWindow(hwnd);
33          AttachThreadInput(ThisThreadID, ForegroundThreadID, false);
34          Result := (GetForegroundWindow = hwnd);
35        end;
36        if not Result then
37        begin
38          {Code by Daniel P. Stasinski}
39          SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
40          SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0),
41            SPIF_SENDCHANGE);
42          BringWindowToTop(hwnd); {IE 5.5 related hack}
43          SetForegroundWindow(hWnd);
44          SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout),
45            SPIF_SENDCHANGE);
46        end;
47      end
48      else
49      begin
50        BringWindowToTop(hwnd); {IE 5.5 related hack}
51        SetForegroundWindow(hwnd);
52      end;
53      Result := (GetForegroundWindow = hwnd);
54    end;
55  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC