Board index » cppbuilder » MDI Child Float

MDI Child Float


2005-12-14 09:47:22 PM
cppbuilder15
Hi
I need a way to float MDI child window as normal Form(fsNormal) and bring
it back as MDI child window(fsMDIChild) whenever required. How to do this ?
Thanx in Advance,
Saravnan A
 
 

Re:MDI Child Float

"Saravanan" < XXXX@XXXXX.COM >wrote in message
Quote
I need a way to float MDI child window as normal Form(fsNormal)
and bring it back as MDI child window(fsMDIChild) whenever
required. How to do this ?
You can change the FormStyle property dynamically at runtime, but that is
not advisable.
What EXACTLY are you trying to accomplish in the first place?
Gambit
 

Re:MDI Child Float

Hi,
Requirement : I need to implement attach/detach windows for the application.
Attach mean displaying a window as child and Dettach meaning displaying the
window as seperate application(a icon in the task bar). I should able to
toggle between attach and dettach at runtime.
Problem : When i change the formstyle from fsChild to fsNormal, Form Handle
is getting changed. I need same handle because some other child window will
be posting the messages using this handle(Please don't ask me to use
Form->handle each time..). I also have some of the third-party control
which uses postmessage that should not be affected due to this Form Style
Change.
I have seen a MFC application which does this. I don't have the source code
but i can capture the events in SPY++. Will that help.
Regards,
Saravanan A
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Saravanan" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I need a way to float MDI child window as normal Form(fsNormal)
>and bring it back as MDI child window(fsMDIChild) whenever
>required. How to do this ?

You can change the FormStyle property dynamically at runtime, but that is
not advisable.

What EXACTLY are you trying to accomplish in the first place?


Gambit


 

{smallsort}

Re:MDI Child Float

"Saravanan" < XXXX@XXXXX.COM >wrote:
Quote

When i change the formstyle from fsChild to fsNormal, Form
Handle is getting changed.
Recreated is the correct term.
Quote
I need same handle because some other child window will
be posting the messages using this handle(Please don't ask
me to use Form->handle each time..).
You don't need to because you know when it will happen so you
can reassign your private Handle variable.
Quote
I also have some of the third-party control which uses
postmessage that should not be affected due to this Form
Style Change.
A well designed component should not be effected by this.
Have you tested it to determine that it actually is?
Ultimately, I think that you could solve these issues by
using AllocateHWnd and using the resulting Handle for
everything because that will not be effected when the form's
underlying Handle is recreated. For example:
private:
HWND MyHandle;
void __fastcall MyWndProc( TMessage &Message );
public:
__fastcall ~TForm2();
//-------------------------------------------------------------
__fastcall TForm2::TForm2( TComponent *Owner ) : TForm(Owner)
{
MyHandle = AllocateHWnd( MyWndProc );
}
//-------------------------------------------------------------
__fastcall TForm2::~TForm2()
{
DeallocateHWnd( MyHandle );
}
//-------------------------------------------------------------
void __fastcall TForm2::MyWndProc( TMessage &Message )
{
switch( Message.Msg )
{
case WM_SomeThing:
....
case WM_SomethingElse:
default: Message.Result = DefWindowProc( FHandle, Message.Msg, Message.WParam, Message.LParam );
}
}
//-------------------------------------------------------------
Quote
I have seen a MFC application which does this. I don't have
the source code but i can capture the events in SPY++. Will
that help.
If we assume that you overcome all of the noted problems, my
tests show that going from fsMDIChild to fsNormal was ok but
in reverse the mdi child was recreated incorrectly in terms of
size and position and I could not prevent or fix it.
Then there is the issue of the seperate icon on the taskbar.
If you determine that you absolutely can not live with the
form's Handle being recreated, you have no choice but to use
2 seperate forms - one fsMDIChild and the other fsNormal - and
copy everything over from one to the other.
For the fsNormal form, you'll also need to override it's
CreateParams methods so that you can apply the WS_EX_APPWINDOW
flag to the form's ExStyle. For example:
protected:
virtual void __fastcall CreateParams( TCreateParams &Params );
//-------------------------------------------------------------
void __fastcall TForm2::CreateParams( TCreateParams &Params )
{
TForm::CreateParams( Params );
Params.ExStyle |= WS_EX_APPWINDOW;
}
//-------------------------------------------------------------
OTOH, if you can live dynamically changing the FormStyle at
runtime, you can use the win32 API's GetWindowLong and
SetWindowLong to add and remove WS_EX_MDICHILD and
WS_EX_APPWINDOW.
~ JD
 

Re:MDI Child Float

"saravanan" < XXXX@XXXXX.COM >wrote:
Quote

Please trim your posts.
Quote
Third-party control that we use, have problems if we change
the FormStyle dynamically.
How do these control's determine what Handle they will use?
Have you looked at using AllocateHWnd?
Quote
I don't have source code for the third-party contorls.
I *never* use 3rd party objects unless they come with source.
Quote
I have a doubt how MFC application could able to do this
without changing the handle why not with borland.
How do you know that it's not happening with MFC as well? It's
an OS thing and not unique to Borland.
Quote
I have mentioned URL for the application that i have seen
which has this attach/detaching window feature.

www.esignal.com/download/default.asp
That's 22mb and a LONG time to download with dialup just so I
can see what I think I already understand <g>.
Quote
In that software, there is an icon on the caption bar to
attach/detach windows. It is really smooth and no flickering
at all.
I could code the GUI so that it performs as you desire but
ISTM that you're looking for a special trick to create your
magic. If your components can't deal with the Handle changing
*and* they can't work with AllocateHWnd, then you have no
choice but to dynamically allocate and delete objects at
runtime.
One approach would be to allocate a copy of the components in
question, copying their properties, and then deleting the
originals.
Another approach (as noted in my other post) would be to have
2 duplicate forms with different FormStyle's and the fsNormal
form overriding it's CreateParams method (which would be my
prefered method). To accomplish this, I would create a wrapper
class that would allocate both types of the form and assign
the events which all live in the wrapper class. This would keep
all of the code centralized - preventing duplicate coding. In
addition, if the wrapper class dynamically allocated the
form's control's, the only duplicattion would be 2 blank
form's with different FormStyle's and one with an overriden
method to produce the seperate icon on the taskbar.
As for your concern about flickering, that's easily handled by
using the correct order of operation. When switching, size and
position the new form exactly over the old form *before* you
delete the old form.
~ JD
 

Re:MDI Child Float

Hi,
Third-party control that we use, have problems if we change the FormStyle
dynamically. I don't have source code for the third-party contorls.
I have a doubt how MFC application could able to do this without changing
the handle why not with borland. I have mentioned URL for the application
that i have seen which has this attach/detaching window feature.
www.esignal.com/download/default.asp
No User id or password required for that application. Please have a look at
the software. In that software, there is an icon on the caption bar to
attach/detach windows. It is really smooth and no flickering at all.
Please help me in solving this issue.
Regards,
Saravanan A
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Saravanan" < XXXX@XXXXX.COM >wrote:
>
>When i change the formstyle from fsChild to fsNormal, Form
>Handle is getting changed.

Recreated is the correct term.

>I need same handle because some other child window will
>be posting the messages using this handle(Please don't ask
>me to use Form->handle each time..).

You don't need to because you know when it will happen so you
can reassign your private Handle variable.

>I also have some of the third-party control which uses
>postmessage that should not be affected due to this Form
>Style Change.

A well designed component should not be effected by this.
Have you tested it to determine that it actually is?
Ultimately, I think that you could solve these issues by
using AllocateHWnd and using the resulting Handle for
everything because that will not be effected when the form's
underlying Handle is recreated. For example:

private:
HWND MyHandle;
void __fastcall MyWndProc( TMessage &Message );
public:
__fastcall ~TForm2();

//-------------------------------------------------------------
__fastcall TForm2::TForm2( TComponent *Owner ) : TForm(Owner)
{
MyHandle = AllocateHWnd( MyWndProc );
}
//-------------------------------------------------------------
__fastcall TForm2::~TForm2()
{
DeallocateHWnd( MyHandle );
}
//-------------------------------------------------------------
void __fastcall TForm2::MyWndProc( TMessage &Message )
{
switch( Message.Msg )
{
case WM_SomeThing:
....
case WM_SomethingElse:
default: Message.Result = DefWindowProc( FHandle, Message.Msg,
Message.WParam, Message.LParam );
}
}
//-------------------------------------------------------------


>I have seen a MFC application which does this. I don't have
>the source code but i can capture the events in SPY++. Will
>that help.

If we assume that you overcome all of the noted problems, my
tests show that going from fsMDIChild to fsNormal was ok but
in reverse the mdi child was recreated incorrectly in terms of
size and position and I could not prevent or fix it.

Then there is the issue of the seperate icon on the taskbar.
If you determine that you absolutely can not live with the
form's Handle being recreated, you have no choice but to use
2 seperate forms - one fsMDIChild and the other fsNormal - and
copy everything over from one to the other.

For the fsNormal form, you'll also need to override it's
CreateParams methods so that you can apply the WS_EX_APPWINDOW
flag to the form's ExStyle. For example:

protected:
virtual void __fastcall CreateParams( TCreateParams &Params );
//-------------------------------------------------------------
void __fastcall TForm2::CreateParams( TCreateParams &Params )
{
TForm::CreateParams( Params );
Params.ExStyle |= WS_EX_APPWINDOW;
}
//-------------------------------------------------------------

OTOH, if you can live dynamically changing the FormStyle at
runtime, you can use the win32 API's GetWindowLong and
SetWindowLong to add and remove WS_EX_MDICHILD and
WS_EX_APPWINDOW.

~ JD

 

Re:MDI Child Float

"saravanan" < XXXX@XXXXX.COM >wrote:
Quote

The only thing that I can suggest at this point is that you
post to the cppbuilder.nativeapi group or you wait for Gambit
who may know of a solution.
~ JD
 

Re:MDI Child Float

Hi,
Quote
I *never* use 3rd party objects unless they come with source.
It is too late for me to decide -:(
Quote
How do you know that it's not happening with MFC as well? It's
an OS thing and not unique to Borland.
Using SPY++, i tried to capture all the windows messages that are passed
in MFC application. In MFC, even when i detach the windows, i could able to
receive all the window messages in SPY++ posted to that window. But in our
case(Borland) on changing of FormStyle, i could not able to get any messages
in SPY++ after detaching the window.
Quote
One approach would be to allocate a copy of the components in
question, copying their properties, and then deleting the
originals.
Third Party is not a VCL component. It is ActiveX rewritten in MFC. I
have no idea how to copy it and recreate. Even on maintaining 2 copies of
the form, I have a problem in performance.
Quote
That's 22mb and a LONG time to download with dialup just so I
can see what I think I already understand <g>.
If you want me to attach the messages that i could see in SPY++, i will do
that.
Regards,
Saravanan A
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"saravanan" < XXXX@XXXXX.COM >wrote:
>

Please trim your posts.

>Third-party control that we use, have problems if we change
>the FormStyle dynamically.

How do these control's determine what Handle they will use?
Have you looked at using AllocateHWnd?

>I don't have source code for the third-party contorls.

I *never* use 3rd party objects unless they come with source.

>I have a doubt how MFC application could able to do this
>without changing the handle why not with borland.

How do you know that it's not happening with MFC as well? It's
an OS thing and not unique to Borland.

>I have mentioned URL for the application that i have seen
>which has this attach/detaching window feature.
>
>www.esignal.com/download/default.asp

That's 22mb and a LONG time to download with dialup just so I
can see what I think I already understand <g>.

>In that software, there is an icon on the caption bar to
>attach/detach windows. It is really smooth and no flickering
>at all.

I could code the GUI so that it performs as you desire but
ISTM that you're looking for a special trick to create your
magic. If your components can't deal with the Handle changing
*and* they can't work with AllocateHWnd, then you have no
choice but to dynamically allocate and delete objects at
runtime.

One approach would be to allocate a copy of the components in
question, copying their properties, and then deleting the
originals.

Another approach (as noted in my other post) would be to have
2 duplicate forms with different FormStyle's and the fsNormal
form overriding it's CreateParams method (which would be my
prefered method). To accomplish this, I would create a wrapper
class that would allocate both types of the form and assign
the events which all live in the wrapper class. This would keep
all of the code centralized - preventing duplicate coding. In
addition, if the wrapper class dynamically allocated the
form's control's, the only duplicattion would be 2 blank
form's with different FormStyle's and one with an overriden
method to produce the seperate icon on the taskbar.

As for your concern about flickering, that's easily handled by
using the correct order of operation. When switching, size and
position the new form exactly over the old form *before* you
delete the old form.

~ JD

 

Re:MDI Child Float

Hi,
Requirement : I need to implement attach/detach windows for the application.
Attach mean displaying a window as child and Dettach meaning displaying the
window as seperate application(a icon in the task bar). I should able to
toggle between attach and dettach at runtime.
Problem : When i change the formstyle from fsChild to fsNormal, Form Handle
is getting changed. I need same handle because some other child window will
be posting the messages using this handle(Please don't ask me to use
Form->handle each time..). I also have some of the third-party control
which uses postmessage that should not be affected due to this Form Style
Change.
I have seen a MFC application which does this. I don't have the source code
but i can capture the events in SPY++. Will that help.
Complete List of conversion between me and JD is available in
borland.public.cppbuilder.vcl.components.using (Subject: MDI Child Float)
Regards,
Saravanan A
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Saravanan" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I need a way to float MDI child window as normal Form(fsNormal)
>and bring it back as MDI child window(fsMDIChild) whenever
>required. How to do this ?

You can change the FormStyle property dynamically at runtime, but that is
not advisable.

What EXACTLY are you trying to accomplish in the first place?


Gambit


 

Re:MDI Child Float

Hi,
Is Gambit available...Please help me
Regards,
Saravanan A
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"saravanan" < XXXX@XXXXX.COM >wrote:
>

The only thing that I can suggest at this point is that you
post to the cppbuilder.nativeapi group or you wait for Gambit
who may know of a solution.

~ JD

 

Re:MDI Child Float

Please help me
"saravanan" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

Requirement : I need to implement attach/detach windows for the
application.
Attach mean displaying a window as child and Dettach meaning displaying
the
window as seperate application(a icon in the task bar). I should able to
toggle between attach and dettach at runtime.

Problem : When i change the formstyle from fsChild to fsNormal, Form
Handle
is getting changed. I need same handle because some other child window
will
be posting the messages using this handle(Please don't ask me to use
Form->handle each time..). I also have some of the third-party control
which uses postmessage that should not be affected due to this Form Style
Change.

I have seen a MFC application which does this. I don't have the source
code
but i can capture the events in SPY++. Will that help.

Complete List of conversion between me and JD is available in
borland.public.cppbuilder.vcl.components.using (Subject: MDI Child Float)

Regards,
Saravanan A

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>
>"Saravanan" < XXXX@XXXXX.COM >wrote in message
>news: XXXX@XXXXX.COM ...
>
>>I need a way to float MDI child window as normal Form(fsNormal)
>>and bring it back as MDI child window(fsMDIChild) whenever
>>required. How to do this ?
>
>You can change the FormStyle property dynamically at runtime, but that is
>not advisable.
>
>What EXACTLY are you trying to accomplish in the first place?
>
>
>Gambit
>
>




 

Re:MDI Child Float

"Saravanan" < XXXX@XXXXX.COM >wrote:
Quote

Is Gambit available.
Gambit has been here and I'm sure that he read this thread and
that he saw your post in the other group as well. The *only*
reason Gambit wouldn't reply would be if he didn't think that
he had anything to add.
Quote
..Please help me
If you absolutely must code the GUI as you described, then
I've given you the best that I can offer and I believe that
will get you there.
~ JD
 

Re:MDI Child Float

Quote
Problem : When i change the formstyle from fsChild to fsNormal, Form
Handle
is getting changed. I need same handle because some other child window
will
be posting the messages using this handle(Please don't ask me to use
Form->handle each time..). I also have some of the third-party control
which uses postmessage that should not be affected due to this Form Style
Change.
Form handle is changing because changing formstyle, VCL's have to recreate
the control
using or not WS_EX_MDICHILD in CreateWindowEx().
I don't think you can't find any other solution that use Form->handle.
Regards
 

Re:MDI Child Float

Quote
How do you know that it's not happening with MFC as well? It's
an OS thing and not unique to Borland.
You are right. The sample application (MFC) that i was mentioning uses 2
different instance of Form and changing the Controls parent based on visible
form.
How to retain the window position when toggling between attach and detaching
windows ? I tried using Application->MainForm->ClientToScreen ( TPoint
(Left, Top). But there is small difference in the window position when
toggling. I don't know is that because of toolbar.
Regards,
Saravanan A.
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Saravanan" < XXXX@XXXXX.COM >wrote:
>
>Is Gambit available.

Gambit has been here and I'm sure that he read this thread and
that he saw your post in the other group as well. The *only*
reason Gambit wouldn't reply would be if he didn't think that
he had anything to add.

>..Please help me

If you absolutely must code the GUI as you described, then
I've given you the best that I can offer and I believe that
will get you there.

~ JD

 

Re:MDI Child Float

"saravanan" < XXXX@XXXXX.COM >wrote:
Quote

The sample application (MFC) that i was mentioning uses 2
different instance of Form and changing the Controls parent
based on visible form.
To accomplish this, you should reconsider my suggestion about
using a wrapper class which I would modify somewhat from what
I previousely posted.
Use the IDE to design the fsNormal form with all of it's
components and events ect. and the fsNormal form will need
to have it's CreateParams overridden so that you can add the
seperate taskbar icon.
You don't *have* to design the fsNormal form to host the
components but it will be easier because you can't hide an
MDIChild, you have to destroy it. If all of the event code
is in the MDIChild and you destroy that class, everything
will stop working and you'll get AV's and Exceptions.
Then you need to modify ProjectName.cpp to remove the 2 forms
so that they are not autocreated and add the wrapper class to
the project. Click File | New | Unit and save the unit with an
appropriate name for the wrapper.
Include the wrapper's header in the main form, dynamically
allocate the wrapper in the main form's constructor and
delete the the wrapper in the main form's destructor. The
rest of your coding goes into the wrapper class.
Quote
How to retain the window position when toggling [...]
Going from fsMDIChild to fsNormal is straight forward. You
just get the form's position in screen relative terms and use
that as to assign the sfNormal Left/Top.
Going from fsNormal to fsMDIChild requires additional logic
because fsNormal could be in a position that is incompatable.
For example, if the fsNormal form is at 0,0 and the MDIParent
is at 100,100, where are you going to put the fsMDIChild? 0,0?
Quote
I tried using Application->MainForm->ClientToScreen
That is the correct method but you are calling it on the wrong
object. You need to call that on the Form2 object instead.
Quote
But there is small difference in the window position when
toggling. I don't know is that because of toolbar.
Some controls are included in the non-client area. TToolBar is
one of them (as long as the Parent is the Form).
~ JD