3

I am trying to bring my secondary form to the Foreground, however when I do

MyForm.Show; // It may be hidden, therefore show it first
SetForegroundWindow(MyForm.Handle);

my Main Form appears aswell. The only way I can prevent that is to do MainForm.Hide; but I got to avoid that.

The idea is to have my secondary form appear on top of another application, without my Main Form having to do so as well.

Raidri
  • 17,258
  • 9
  • 62
  • 65
Jeff
  • 12,085
  • 12
  • 82
  • 152
  • isn't this the same issue you raised a couple of months ago http://stackoverflow.com/questions/5393666/make-2-forms-able-to-overlap-each-other – David Heffernan Jun 04 '11 at 22:36
  • @David - Not really - the issue this time, is that my secondary form cant be programatically brought to the foreground, without my Main Form following. – Jeff Jun 04 '11 at 22:41
  • It's all part of the standard behaviour of windows. The secondary form is owned by the main form I presume? And I mean that in windows terms not VCL terms. – David Heffernan Jun 04 '11 at 22:46
  • @David - Yes, however I tried setting the `TCreateParams.WndParent := 0;`, which did not help either. – Jeff Jun 04 '11 at 22:50
  • [Here](https://forums.codegear.com/thread.jspa?messageID=132580&tstart=0#132580)'s a discussion of a similar problem on embarcadero newsgroups. I'm not aware of the outcome though. – Sertac Akyuz Jun 05 '11 at 01:17

2 Answers2

2

If you consider to make another application for this functionality, then you may also consider the following compromise: minimize the MainForm to the taskbar (rather than hiding it) to prevent it popping up when activating another form.

If so, then try this answer. It does add an extra icon to your taskbar for the secondary form, but I guess that'll be no problem since a different application would either. However, if the MainForm is nót minimized but obfuscated by other windows, activating the secondary form wíll also popup the MainForm, just like you are experiencing now.

And for the completeness of this answer's sake, but not by any means meant as advice: this answer describes a (somewhat experimental) construction to make fully independent windows. The little time I tested that solution, it seemed to work, but be prepared not counting any longer on the full/default functionality of the VCL.

Community
  • 1
  • 1
NGLN
  • 43,011
  • 8
  • 105
  • 200
  • I've decided to create a whole nother program for this feature. Where theres adversity theres oportunity. =) – Jeff Jun 05 '11 at 00:01
  • That's a decision made quickly! But indeed, a separate app will appeal more to your users. – NGLN Jun 05 '11 at 00:12
  • As I said, `Where theres adversity theres oportunity.`, heheh. :) – Jeff Jun 05 '11 at 00:20
0

Try settings the state of the form to fsAlwaysOnTop.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • That helps, **until** I click somewhere in the form. – Jeff Jun 04 '11 at 22:31
  • And what happens then? The main form pops up? That is because in that case your application, with all its forms, is activated. To prevent that you will indeed need to hide the mainform, or put the always on top form in a separate process/application. The latter may be more complex, because you'll need to find a way to let the two separate applications communicate. – GolezTrol Jun 04 '11 at 22:34
  • I'm afraid there's no other way. Either hide the main form, or have both forms exist in separate applications. Otherwise, they will both become on top once the application is activated. – GolezTrol Jun 04 '11 at 22:52
  • @Golez - I guess I need to do the other app then. Add that to your answer, and I will mark it, if David can't figure it out either. :) – Jeff Jun 04 '11 at 22:52
  • Well, that 'll cost me a mark then. Inter process communication is not a subject to squeeze in a short answer. There are numerious ways, amongst which are window messages, memory maps and TCP connections. The one that's the best for you depends on your actual needs. Mind that you cannot send Delphi objects, nor strings between applications, although you can send PChar buffers. – GolezTrol Jun 04 '11 at 23:04
  • 1
    I'm not convinced that this can't be done from a single process – David Heffernan Jun 04 '11 at 23:13
  • @David - Me neither, however I just dont see how. :) – Jeff Jun 04 '11 at 23:33