Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting back focus on my app after shellexecute

923 views
Skip to first unread message

Patrick

unread,
Oct 18, 1998, 3:00:00 AM10/18/98
to
Hi all,

With my application i execute an internet-link in the default browser.
After the browser is started and the link is passed to it i want to
receive the focus back to my application. I tried much things with the
setfocus but that didn't seem to work.
Any1 knows how to make this work ?

cu,

Patrick

--
---
P. van Zweden
pvzw...@no-spam.caiw.nl

*** It's our policy to always blame the computer

Nic Roche

unread,
Oct 19, 1998, 3:00:00 AM10/19/98
to

>receive the focus back to my application.

If you know the text in the title of the browser:

var

npHWnd : hWnd;

<snip>

npHWnd := 0;

while npHWnd = 0 do

npHWnd := HWndGet( <partialtitle here>);


while GetForeGroundWindow <> npHWnd do

SetForeGroundWindow( npHWnd );

</snip>


function TForm1.HWndGet( partialTitle: string ): hWnd;
var
hWndTemp, iLenText: hWnd;
cTitletemp: array [0..MAX_PATH-1] of Char;
sTitleTemp: string;
begin

//'find first window and loop through all subsequent windows in the master
window list

hWndTemp := FindWindow(nil, nil);

while hWndTemp <> 0 do
begin

// 'retrieve caption text from current window

iLenText := GetWindowText(hWndTemp, cTitletemp, MAX_PATH);

sTitleTemp := cTitletemp;

// 'clean up the return string, preparing for case insensitive
comparison

sTitleTemp := UpperCase(copy( sTitleTemp, 1, iLenText));

// ShowMessage( sTitleTemp );

// 'use appropriate method to determine if the current window's
caption either
// 'starts with or contans passed string

partialTitle := UpperCase( partialTitle );

if pos( partialTitle, sTitleTemp ) <> 0 then

break;

// 'get next window in master window list and continue

hWndTemp := GetWindow(hWndTemp, GW_HWNDNEXT);

end;

result := hWndTemp;

end;


Patrick

unread,
Oct 20, 1998, 3:00:00 AM10/20/98
to
Thanx for the answer, i brought back the code you sent to 1 line because i
know the handle of the window that's calling the web-browser. Below my piece
of code :
----- code ----
procedure Taboutform.internetlinkClick(Sender: TObject);
var handle : HWND;
operation,
command,
parameters,
directory : Pchar;
begin
//this piece of code opens the default internet-browser with the link
//specified by command.
handle := findwindow(nil,'aboutform');
command := 'http://some.web.page';
operation := 'open';
parameters := nil;
directory := nil;
ShellExecute(handle,operation,command,parameters,directory,sw_maximize);
While GetForegroundWindow <> handle do
begin
// beep;
If SetForegroundWindow(handle) = false then
beep;
end;
end;
----- end code-----
Unfortunatly this doesn't work, is this because my cutting in your code or am
i doing something different wrong ? Or is this just strange ?

Nic Roche wrote:

> >receive the focus back to my application.
>
> If you know the text in the title of the browser:
>
> var
>
> npHWnd : hWnd;
>
> <snip>
>
> npHWnd := 0;
>
> while npHWnd = 0 do
>
> npHWnd := HWndGet( <partialtitle here>);
>
> while GetForeGroundWindow <> npHWnd do
>
> SetForeGroundWindow( npHWnd );
>
> </snip>
>

--

Neil J. McLeish

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
Hi Patrick.

Intersting one that.

I did a similar thing, whilst calling the Desktop Display Properties
control panel.
All I did was to set the formstyle to fsStayOnTop. This however, may not
be what you want, as the
form will stay on top of your browser whilst the link is being passed to
it.
All the best

Neil J.McLeish

Patrick wrote:

> Hi all,
>
> With my application i execute an internet-link in the default browser.
> After the browser is started and the link is passed to it i want to
> receive the focus back to my application. I tried much things with the
> setfocus but that didn't seem to work.
> Any1 knows how to make this work ?
>
> cu,
>
> Patrick
>

Patrick

unread,
Oct 27, 1998, 3:00:00 AM10/27/98
to
Hmm.... i could try this one too, because i think you can change that
property while your program is running.
At the moment the link is passed from a aboutbox that is shown with
showmodal and i have tried many solutions i got from people but none of
them works for me. It's pretty strange.
But thanks for your suggestion

"Neil J. McLeish" wrote:
>
> Hi Patrick.
>
> Intersting one that.
>
> I did a similar thing, whilst calling the Desktop Display Properties
> control panel.
> All I did was to set the formstyle to fsStayOnTop. This however, may not
> be what you want, as the
> form will stay on top of your browser whilst the link is being passed to
> it.
> All the best
>
> Neil J.McLeish
>

Marco Roberto Gonçalves Junior

unread,
Oct 29, 1998, 3:00:00 AM10/29/98
to
Try Application.BringToFront after shellexecute command.

Best Regards,

Marco Roberto

Patrick <pvzw...@no-spam.caiw.nl> wrote in article
<3635E458...@no-spam.caiw.nl>...

Patrick

unread,
Oct 30, 1998, 3:00:00 AM10/30/98
to
Unfortunatly this doesn't work either, i'm almost thinking it is because
the link is showed from a window that is shown modal.

"Marco Roberto Gonçalves Junior" wrote:
>
> Try Application.BringToFront after shellexecute command.
>
> Best Regards,
>
> Marco Roberto

0 new messages