Delphi: Balloon Form with fsStayOnTop not working in Win7

2.2k views Asked by At

I have an application that uses my own balloon form. This is a non-bordered, fsStayOnTop kind form.

I show it with this code:

ShowWindow(Handle, SW_SHOWNOACTIVATE);
Visible := True;

Today I realized that if I activate another application then the balloon is not appearing! So it is loosing it's stay on top style.

Environment: Win7/x64 Delphi 6 Professional

What I can do with it?

Thanks: dd

2

There are 2 answers

1
Heinrich Ulbricht On BEST ANSWER

What worked for me in the past when struggling with stay-on-top forms:

Form := TMyForm.Create(Self);
Application.NormalizeTopMosts;
SetWindowPos(Form.Handle, HWND_TOPMOST, 0, 0, 0, 0,
             SWP_NOACTIVATE + SWP_NOMOVE + SWP_NOSIZE);
Form.Show;

Try this instead of your ShowWindow call. This stays on top of all windows (do you really want this?). Also it feelds kind of hacky because it omits the RestoreTopMosts call which the documentation says we should call (so other stay-on-top windows in your application will be affected). So there might be a better solution.

0
Mad Martian On

I tried the above solution and it did not work on a secondary form. I believe it will work on a main form, but not on a secondary form. However, I did find a solution that works for a secondary form, which sounds like what the original poster wanted, as a "balloon form" is typically a pop-up.

Put this in the "Form B" OnCreate event:

FormStyle:= fsStayOnTop;

but that alone isn't enough...

Drag a TApplicationEvents onto your "Form B"

In the OnDeactivate event for ApplicationEvents1, add the following:

SetForegroundWindow(Handle);

I keep an eye on a small status window while my main form is crunching data out of site. Works beautifully!