Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2006 Sep : A TForm on different desktop showing a modal MessageBox

www.cryer.info
Managed Newsgroup Archive

A TForm on different desktop showing a modal MessageBox

Subject:A TForm on different desktop showing a modal MessageBox
Posted by:"Aleksander Oven" (aleksander.ov..@email.si)
Date:Fri, 22 Sep 2006 17:48:00

I wrote a Delphi form that can be shown on an isloated, separate desktop
to avoid tampering by other programs.

To accomplish this, I created a thread that pumps its own messages.
This thread creates a new desktop (CreateDesktop, SetThreadDesktop) and
a form (any TForm descendant, really), then switches to the new desktop
(SwitchDesktop) and shows the form there.

Now, I know all too well that VCL wasn't built with this kind of use
in mind, but it all works surprisingly well! I'm having no problems
with UI message processing from TApplication in main thread.
Granted, I had to write my own Action updating as part of the message
pump, but that wasn't too complicated and is now working like a charm.

I'm able to put various components on the form (i.e. TButton, TPanel,
TLabel, TVirtualStringTree, TPNGImageList, TActionList and more) and
nothing ever crashes. I don't know about hints yet, but I'll get to that
when need arises.

So what's the problem then, you ask? The problem I'm having is not so
much a problem, but rather an interesting observation that makes me
think something is not yet quite in place regarding the window parents.

For example, if I call a MessageBox API from this "secure" form, and
provide form's Handle as the hWnd parameter, the MessageBox displays
fine and is also modal to the form, as expected.
The interesting part is that it doesn't flash or beep when I click on
the disabled form in the background, as it normally would in main
thread.

Originally, I've set the form's WndParent in CreateParams to
GetDesktopWindow, so I though this might be the problem. Instead, I
tried creating an invisible window (similar to the one that TApplication
creates in main thread) and settings the form's WndParent to that
window's Handle, but nothing changed.

This bothers me, because it indicates I missed something. It could be
some internal VCL snag or simply a lost message that I'd need to handle.

Can anyone help me with this?

Regards,
Aleksander Oven

Replies:

www.cryer.info
Managed Newsgroup Archive