Solved

WM_ACTIVATE ???

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

11 Experts available now in Live!

Get 1:1 Help Now