Solved

WM_ACTIVATE ???

Posted on 2002-04-28
5
4,465 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

732 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