Board index » delphi » Need help with modeless form with WS_EX_APPWINDOW and modal dialog

Need help with modeless form with WS_EX_APPWINDOW and modal dialog

Hi all,

I need some advice.
I've got an application with some modeless forms which I want to appear on
the taskbar.
One of these forms needs to show a Modal Dialog (or 'sub'form).
Now when focus is on an other application, and user clicks on the modeless
form on the taskbar, the modal dialog 'hides' behind the first modeless
form.
When user shifts focus with Alt+Tab everything works fine.

How can I bring up the Modal Dialog when user clicks on the taskbar?

Try:

// To force Form1 to appear on the taskbar
//  Form1 is not the main Form!!
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2 := TForm2.Create(Application);
  with Form2 do
  begin
    try
    ....

      if ShowModal = mbOk then
      begin
        ...
      end;
    finally
      Free;
    end;
  end;
end;

When Form2 (the modal form) is active, and user shifts focus to other
application,
try regaining focus on Form2 by clicking on taskbar.
Alt+Tab works fine.

Any hints?

Many thanks in advance

Herman Fr?berg

 

Re:Need help with modeless form with WS_EX_APPWINDOW and modal dialog


Quote
In article <3b2223e0$1_2@dnews>, Herman Fr?berg wrote:
> I've got an application with some modeless forms which I want to appear on
> the taskbar.
> One of these forms needs to show a Modal Dialog (or 'sub'form).
> Now when focus is on an other application, and user clicks on the modeless
> form on the taskbar, the modal dialog 'hides' behind the first modeless
> form.
> When user shifts focus with Alt+Tab everything works fine.
> How can I bring up the Modal Dialog when user clicks on the taskbar?

Since the modal dialog is a form of your own, not one of the stock dialogs
from the Dialogs unit this can be solved fairly easy.

Create the form with form1 as owner:

Quote
> procedure TForm1.Button1Click(Sender: TObject);
> begin

    Form2 := TForm2.Create(self);

Override the CreateParams method of TForm2 as

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.wndParent := TWincontrol(Owner).Handle;
end;

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Need help with modeless form with WS_EX_APPWINDOW and modal dialog


Thanks a lot!

There is only one small detail left.
When user shifts focus from other application when Form2 is up by Alt+Tab
From2 has got the focus (is active), while shifting focus by clicking on
Form1 on
the taskbar, Form2 becomes topmost Form2, but isn't active.
Is there a way to achive this?

Again many thanks.

Herman Fr?berg

Re:Need help with modeless form with WS_EX_APPWINDOW and modal dialog


Quote
In article <3b247a25$1_1@dnews>, Herman Fr?berg wrote:
> There is only one small detail left.
> When user shifts focus from other application when Form2 is up by Alt+Tab
> From2 has got the focus (is active), while shifting focus by clicking on
> Form1 on
> the taskbar, Form2 becomes topmost Form2, but isn't active.
> Is there a way to achive this?

Does Form1's OnActivate event fire when it is activated this way? If so you
could move focus to form2 by calling form2.Show, form2.BringToFront or
SetForegroundWindow( form2.handle ) in the handler.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Need help with modeless form with WS_EX_APPWINDOW and modal dialog


No sorry, I had to mention I already tried that.

OnActivate doesn't get fired when a Modal Form is topmost.
Both by Alt+Tab and clicking on the Taskbar.

As far is I can see now there are no 'standard' events I can use.  It looks
like
a WM_ACTIVATEAPP message gets send to the application, but at the moment
I'm not sure I can use that one.

Much thanks again!

Herman Fr?berg

"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote in message
news:VA.00007242.0092cabc@antispam.compuserve.com...

Quote
> In article <3b247a25$1_1@dnews>, Herman Fr?berg wrote:
> > There is only one small detail left.
> > When user shifts focus from other application when Form2 is up by
Alt+Tab
> > From2 has got the focus (is active), while shifting focus by clicking on
> > Form1 on
> > the taskbar, Form2 becomes topmost Form2, but isn't active.
> > Is there a way to achive this?

> Does Form1's OnActivate event fire when it is activated this way? If so
you
> could move focus to form2 by calling form2.Show, form2.BringToFront or
> SetForegroundWindow( form2.handle ) in the handler.

Re:Need help with modeless form with WS_EX_APPWINDOW and modal dialog


Quote
In article <3b25cdba_2@dnews>, Herman Fr?berg wrote:
> No sorry, I had to mention I already tried that.
> OnActivate doesn't get fired when a Modal Form is topmost.
> Both by Alt+Tab and clicking on the Taskbar.
> As far is I can see now there are no 'standard' events I can use.  It looks
> like
> a WM_ACTIVATEAPP message gets send to the application, but at the moment
> I'm not sure I can use that one.

Try the Application.OnActivate event. Or a handler for the WM_ACTIVATE
message on form1.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Need help with modeless form with WS_EX_APPWINDOW and modal dialog


Thanks Peter,

Application.OnActivate will do the trick.

Herman Fr?berg

"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote in message
news:VA.00007255.005f49fc@antispam.compuserve.com...

Quote
> In article <3b25cdba_2@dnews>, Herman Fr?berg wrote:

> Try the Application.OnActivate event. Or a handler for the WM_ACTIVATE
> message on form1.

Other Threads