Board index » delphi » Application getting Focus query

Application getting Focus query

Hi,

I am having a spot of trouble trying to get an applications main
window to receive focus when requested.

I have an MDI application (see homepages GPS Utility) which runs as a
single program instance. So far, I have successfully figured out how
to detect a previously running instance of the program, to send the
second instances run parameter (a filename) to the first instance and
then to die. The first instance takes the message and makes a child
window for the filename as required.  It all works fine, but in Delphi
3, although the First instance does come to the top, it does not have
focus. In Delphi 1 this works OK - the main window of the first
instance has focus. My code segments are:  

Second instance detects application already running and then Writes
its run parameter to a file, sends message to PreviousWindow and then
makes sure First instance is on top, then it dies.
    WriteRun(paramstr(1));
    SendMessage( hWndPrev, UM_ACTIVATEFIRSTINSTANCE, 0, 0 );
    if IsIconic(hWndPrev) then ShowWindow(hWndPrev,SW_RESTORE)
    else BringWindowToTop(hWndPrev);
    ..........
    Halt;

First Instance receives the message, reads the run parameter and
generates a child window
    runparms:=ReadRun;
    GenChild(runparms);

I have tried a number of things, but I can't get the first instance to
get focus.  I am activating the second instance by double clicking in
Windows Explorer on an associated filetype.  Windows Explorer keeps
the focus even though it is not now on top.

I tried things like 'MainForm.setfocus'' and 'SetActiveWindow'  but
these do not work.

What else do I have to do to get my program the focus??

Many thanks,
Alan Murphy
To reply remove two '.null's from
murphy.n...@enterprise.net.null
http://homepages.enterprise.net/murphy/

 

Re:Application getting Focus query


Hi Alan,

You might want to try Application.BringToFront or
SetForeGroundWindow(Handle);

I hope this helps,
Earl Reddell
Res-cue (Resourceful Components for User Ease!)
Check out our web site: http://www.res-cue.com

In article <3789c51b.22963...@news.enterprise.net>,
  murphy.n...@enterprise.net.null (Alan Murphy) wrote:

Quote
> Hi,

> I am having a spot of trouble trying to get an applications main
> window to receive focus when requested.

> I have an MDI application (see homepages GPS Utility) which runs as a
> single program instance. So far, I have successfully figured out how
> to detect a previously running instance of the program, to send the
> second instances run parameter (a filename) to the first instance and
> then to die. The first instance takes the message and makes a child
> window for the filename as required.  It all works fine, but in Delphi
> 3, although the First instance does come to the top, it does not have
> focus. In Delphi 1 this works OK - the main window of the first
> instance has focus. My code segments are:

> Second instance detects application already running and then Writes
> its run parameter to a file, sends message to PreviousWindow and then
> makes sure First instance is on top, then it dies.
>     WriteRun(paramstr(1));
>     SendMessage( hWndPrev, UM_ACTIVATEFIRSTINSTANCE, 0, 0 );
>     if IsIconic(hWndPrev) then ShowWindow(hWndPrev,SW_RESTORE)
>     else BringWindowToTop(hWndPrev);
>     ..........
>     Halt;

> First Instance receives the message, reads the run parameter and
> generates a child window
>     runparms:=ReadRun;
>     GenChild(runparms);

> I have tried a number of things, but I can't get the first instance to
> get focus.  I am activating the second instance by double clicking in
> Windows Explorer on an associated filetype.  Windows Explorer keeps
> the focus even though it is not now on top.

> I tried things like 'MainForm.setfocus'' and 'SetActiveWindow'  but
> these do not work.

> What else do I have to do to get my program the focus??

> Many thanks,
> Alan Murphy
> To reply remove two '.null's from
> murphy.n...@enterprise.net.null
> http://homepages.enterprise.net/murphy/

--
Earl Reddell
Res-cue(Resourceful Components for User Ease!)
Check out our web site: http://www.res-cue.com

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Re:Application getting Focus query


Aren't Newgroups Wonderful!

Quote
On Tue, 29 Jun 1999 16:53:23 GMT, eredd...@my-deja.com wrote:
>You might want to try................
>SetForeGroundWindow(Handle);
>I hope this helps,
>Earl Reddell
>Res-cue (Resourceful Components for User Ease!)
>Check out our web site: http://www.res-cue.com

Many thanks Earl - that just did the trick - Excellent!

Alan Murphy
To reply remove two '.null's from
murphy.n...@enterprise.net.null
http://homepages.enterprise.net/murphy/

Other Threads