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

Showing form without losing focus

415 views
Skip to first unread message

Marco van Kimmenade

unread,
Aug 16, 2004, 2:42:01 AM8/16/04
to
Hi,

I have this systray-application.
From within this app I want to show a form, but this form must not get the
focus, something like the message form in MSN messenger.
The problem is that the app does take the focus away from the app I was
currently working in but this only the second time i show the form.

So, does anyone know how can i show the form without losing focus of the app
i am working in?

The form is an auto-create form. In the create and destroy I do'n do a
thing.
I have a public Init method for showing the form.
My Init method on the form is as followed

function TMessengerForm.Init(const Caption : string;
const Message : string; const MessageType : integer;
const BalloonHintTime : integer) : Boolean;
begin

Result := False;
try // statements to try
FormStyle := fsNormal;
Visible := False;
ShowWindow( handle, SW_SHOWNA );
Visible := True;
Result := True;
except
on e:Exception do
begin
ObjectModule.Logbook.Message := 'Except tijdens Init';
ObjectModule.Logbook.Message := e.Message;
end;
end; // try/except

end;


procedure TMessengerForm.CreateParams(var Params: TCreateParams);
begin

inherited;
Params.Style := (Params.Style OR WS_POPUP) AND (NOT
WS_DLGFRAME);
Params.ExStyle := WS_EX_TOOLWINDOW;
AddBiDiModeExStyle(Params.ExStyle);
Params.WindowClass.Style := CS_SAVEBITS;

end;


Ndi

unread,
Aug 18, 2004, 5:21:47 PM8/18/04
to
My guess is because you mix Visible and ShowWindow.

Setting Visible or calling Show/Hide internally calls ShowWindow, which
will bring the form forward. Use the ShowWindow API alone, don't sync
Visible and don't call Show/Hide. Actually, by doing Hide and then Show you
effectively rendered the ShowWindow call useless.

Let me know how it works out. I see no other reason for this to happen
(yet:).

--
Andrei "Ndi" Dobrin
Brainbench MVP
www.Brainbench.com


Marco van Kimmenade

unread,
Aug 19, 2004, 5:45:00 AM8/19/04
to
I pulled the form out of the application it was in and put it into a new
one.
In the new one i made 2 timers that show the form. Here everything works
great, the focus stays with the app I was working in and not the form.

I think the strange behaviour has something to do with the fact that i'm
showing the form from within a systray application.
I use the CoolTrayIcon component for this. Perhaps this is what's causing
all the trouble but I haven't found out yet what exactly is the problem
then.

Marco van Kimmenade

"Ndi" <Ndi...@Yahoo.com> wrote in message
news:4123...@newsgroups.borland.com...

Ndi

unread,
Aug 20, 2004, 12:31:55 AM8/20/04
to
It pops up and takes focus even if you use only the API with ShowWindow
and Show_NA (no visible or .show of form)? From a timer, not by clicking on
the tray icon. Clicking on the icon will bring it to front.

Because mine doesn't.

0 new messages