Solved

WM_ACTIVATE ???

Posted on 2002-04-28
5
4,483 Views
Last Modified: 2011-10-03
Hi,

I want to use this code to always set my windows activate, but it doesn't work???


...
Private
  Procedure ToujoursActif(var Msg :TMessage);
   message WM_ACTIVATE;

...
Procedure TMainForm.ToujoursActif(var Msg :TMessage);
begin
if Msg.WParam = WA_INACTIVE then SendMessage(handle, WM_ACTIVATE, WA_ACTIVE,0);
end;



logicaly, this code work, cause if i put SendMessage(handle, WM_ACTIVATE, WA_ACTIVE,0); in a button, it's ok
0
Comment
Question by:DelphiCool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6975097
hi,
use TWMActivate mesage instead,declare it like this:

private
    { Private declarations }
    procedure WMActivate( Var msg: TWMActivate );
      message WM_ACTIVATE;
 public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMActivate( Var msg: TWMActivate );
begin
  If msg.Active = WA_INACTIVE Then
PostMessage(handle, WM_ACTIVATE, WA_ACTIVE,0);
  inherited;
end;


the above will only make the window active and not nessesarily at the top though,so maybe you may want to add setforegroundwindow etc as well.
0
 

Author Comment

by:DelphiCool
ID: 6975124
It doesn't work inthe

The form isn't bringged to top

I try your code and add
    setforegroundwindow(handle);
    BringWindowToTop(handle);

but no way

Why did you prefer  procedure WMActivate( Var msg: TWMActivate );
instead of Procedure ToujoursActif(var Msg :TMessage);

to work only with WM_activate message ??
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6975200
>>Why did you prefer  procedure WMActivate( Var msg: TWMActivate );
>>instead of Procedure ToujoursActif(var Msg :TMessage);
>>to work only with WM_activate message ??

exactly..

ok the following is getting silly but im guesssing your using 2k or something else setforegroundwindow would be working.
its not small but is nessesary ,it came form the borland newsgroups with parts from different sources.
http://groups.google.com/groups?q=forceforegroundwindow+delphi+ray&hl=en&selm=3A62F81B.7790A088%40ia.comweb.nl&rnum=1


private
    { Private declarations }
    procedure WMActivate( Var msg: TWMActivate );
      message WM_ACTIVATE;
 public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function ForceForeground(AppHandle:HWND): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID      : DWORD;
timeout           : DWORD;
OSVersionInfo     : TOSVersionInfo;
Win32Platform     : Integer;
begin
if IsIconic(AppHandle) then ShowWindow(AppHandle, SW_RESTORE);
if (GetForegroundWindow = AppHandle) then Result := true else
begin
  Win32Platform := 0;
  OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
  if GetVersionEx(OSVersionInfo) then Win32Platform := OSVersionInfo.dwPlatformId;

  { Windows 98/2000 doesn't want to foreground a window when some other window has keyboard focus}

  if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (OSVersionInfo.dwMajorVersion > 4)) or
     ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and ((OSVersionInfo.dwMajorVersion > 4) or
     ((OSVersionInfo.dwMajorVersion = 4) and (OSVersionInfo.dwMinorVersion > 0)))) then
  begin
    Result := false;
    ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow,nil);
    ThisThreadID := GetWindowThreadPRocessId(AppHandle,nil);
    if AttachThreadInput(ThisThreadID, ForegroundThreadID, true) then
    begin
      BringWindowToTop(AppHandle);
      SetForegroundWindow(AppHandle);
      AttachThreadInput(ThisThreadID, ForegroundThreadID, false);
      Result := (GetForegroundWindow = AppHandle);
    end;
    if not Result then
    begin
      SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
      SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE);
      BringWindowToTop(AppHandle);
      SetForegroundWindow(AppHandle);
      SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
      Result := (GetForegroundWindow = AppHandle);
      if not Result then
        begin
        ShowWindow(AppHandle,SW_HIDE);
        ShowWindow(AppHandle,SW_SHOWMINIMIZED);
        ShowWindow(AppHandle,SW_SHOWNORMAL);
        BringWindowToTop(AppHandle);
        SetForegroundWindow(AppHandle);
        end;
    end;
  end else
  begin
    BringWindowToTop(AppHandle);
    SetForegroundWindow(AppHandle);
  end;
  Result := (GetForegroundWindow = AppHandle);
end;
end;



procedure TForm1.WMActivate( Var msg: TWMActivate );
begin
  If msg.Active = WA_INACTIVE Then
ForceForeground(handle);
 inherited;
  end;


see here for details of a new win2k api allowsetforegroundwindow:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_5fw7.asp
0
 

Author Comment

by:DelphiCool
ID: 6975223
thanks inthe

you get the points

It's bizare, when I click on another window, my programme is bring to top, but if i click another time on the other window, my prog doesn't came on top


PS I'm using windows ME

Thanks
0
 
LVL 17

Expert Comment

by:inthe
ID: 6975236
yeh i noticed that also.
there are other ways around this but they can get long and messy.i guess thats why they made this new api AllowSetFor..() , the way ms made all the windows versions with a different mechanism for putting a window to top is not good (IMHO :-)

also maybe using modal forms etc and different formstyles (ie FsStayOnTop) can improve what your trying to do.

good luck
Barry
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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