Board index » cppbuilder » how to set a owner of form???

how to set a owner of form???


2003-08-02 01:45:18 PM
cppbuilder56
hi,all:
In a dll, I write a form like below:
Tmyfrm* frm=new Tmyfrm(hwnd or TForm*)
frm->ShowModal() or frm->Show();
hwnd and TForm* are passed argument into dll.
this frm can be displaied, but there is a task button in windows taskbar. I
don't want to display it, how should I do to hide it from taskbar.
please help me? Thanks.
--
Regards for you.
Siney
 
 

Re:how to set a owner of form???

"Siney San" < XXXX@XXXXX.COM >wrote:
Quote
[...] how should I do to hide it from taskbar.
To not make a seperate taskbar entry, you need the owner set
correctly. When you allocate the form, you need to pass who
you want to be the owner:
Tmyfrm *frm = new Tmyfrm( the handle of the owner to be );
If you use:
Tmyfrm *frm = new Tmyfrm( this );
the form which allocates it will be the owner. This should clear up the problem.
~ JD
 

Re:how to set a owner of form???

"JD" < XXXX@XXXXX.COM >đ┤╚ŰË╩╝■ news:3f2b5d3a$ XXXX@XXXXX.COM ...
Quote

"Siney San" < XXXX@XXXXX.COM >wrote:
>[...] how should I do to hide it from taskbar.

To not make a seperate taskbar entry, you need the owner set
correctly. When you allocate the form, you need to pass who
you want to be the owner:

Tmyfrm *frm = new Tmyfrm( the handle of the owner to be );

If you use:

Tmyfrm *frm = new Tmyfrm( this );
Yes, i know. I pass this point to my export function and create my form like
yours, but the task button also be shown. eg:
extern "C" __declspec(dllexport)
int MyForm(HWND hwnd,TForm* frm)
{
Tmyfrm* frm=new Tmyfrm(frm); //new Tmyfrm(hwnd);
frm->ShowModal();
}
the frm form can be shown and embeded into the parent(owner), if i write
code like below:
Tmyfrm* frm=new Tmyfrm(NULL);
frm->ShowModal();
the frm form can be shown separetely, but there is taskbutton in the
taskbar, how should i do to hide this taskbutton in my way.
 

{smallsort}

Re:how to set a owner of form???

"Siney San" < XXXX@XXXXX.COM >wrote:
Quote
I pass this point to my export function and create my form
like yours, but the task button also be shown. eg:

extern "C" __declspec(dllexport)
int MyForm(HWND hwnd,TForm* frm)
{
Tmyfrm* frm=new Tmyfrm(frm); //new Tmyfrm(hwnd);
frm->ShowModal();

}
First, you have declared MyForm to return an int but it does
not. Second, you have defined a parameter 'frm' AND a variable
frm. In this case, I'm uncertain of how the compiler will
treat the parameter. Third, you are assigning the Owner as
it's self.
Truth be told, I have never had a need to put a form in a dll
but I would think that it should look something like this:
extern "C" __declspec(dllexport)
int MyForm( HWND hwnd )
{
Tmyfrm *A_New_My_Form = new Tmyfrm( hwnd );
return reinterpret_cast<int>( A_New_My_Form );
}
and it would be used like this:
Tmyform *frm = NULL;
frm = (Tmyform*)MyForm( this );
if( frm ) frm->ShowModal();
delete frm;
Note that you may need to cast the return differently but I
don't think so. Also, if you use frm->Show(), you can't put
the delete in there and I'm uncertain what will happen in that
case. Although the new form will be destroyed when the Owner
of the form is destroyed, I don't know what will happen to
memory if the new form is created over and over because it's
not deleted.
Quote
the frm form can be shown and embeded into the parent(owner),
if i write code like below:
The Parent and Owner are not the same thing. The Parent is the
object that is responsible for things like handling all of the
windows messaging while the Owner is responsible for freeing
it's resources apon destruction.
Quote
Tmyfrm* frm=new Tmyfrm(NULL);
This will create a form with no Owner.
Quote
taskbar, how should i do to hide this taskbutton in my way.
If the above fails, you might also try using 'Application'
instead of 'this'.
~ JD
 

Re:how to set a owner of form???

"Siney San" < XXXX@XXXXX.COM >wrote:
Quote
Could you tell me how to hide taskbutton in all case.
Set new form Owner to the application main form.
~ JD
 

Re:how to set a owner of form???

Out of curiousity, what happens if you have MainForm as the Owner of
Form1, and then Form1 creates another child form (Form2) and uses itself
as the owner? In such an instance, is a taskbutton created, or not?
If so, then doesn't this make it a bit difficult if you have a
hierarchichal tree of forms? In the above example, if I close Form1,
then Form2 will close, but if both are set to MainForm as the Owner of
each, then closing Form1 will not close Form2.
Comments appreciated.
David Erbas-White
JD wrote:
Quote
"Siney San" < XXXX@XXXXX.COM >wrote:

>Could you tell me how to hide taskbutton in all case.


Set new form Owner to the application main form.

~ JD

 

Re:how to set a owner of form???

David Erbas-White < XXXX@XXXXX.COM >wrote:
Quote
[...] if you have MainForm as the Owner of Form1, and then
Form1 creates another child form (Form2) and uses itself
as the owner? In such an instance, is a taskbutton created,
or not?
Not unless you force it to be created that way OR you have
some bug in your code that causes it to behave that way.
Quote
[...] if I close Form1, then Form2 will close, but if both
are set to MainForm as the Owner of each, then closing Form1
will not close Form2.
The Owner is responsible for destroying all objects that have
been assigned to it when it is destroyed. To be clear, while
closing a form MAY lead to code that destroys it, the simple
act of closing it does not destroy it.
~ JD
 

Re:how to set a owner of form???

JD wrote:
Quote
David Erbas-White < XXXX@XXXXX.COM >wrote:

>[...] if you have MainForm as the Owner of Form1, and then
>Form1 creates another child form (Form2) and uses itself
>as the owner? In such an instance, is a taskbutton created,
>or not?


Not unless you force it to be created that way OR you have
some bug in your code that causes it to behave that way.


>[...] if I close Form1, then Form2 will close, but if both
>are set to MainForm as the Owner of each, then closing Form1
>will not close Form2.


The Owner is responsible for destroying all objects that have
been assigned to it when it is destroyed. To be clear, while
closing a form MAY lead to code that destroys it, the simple
act of closing it does not destroy it.

~ JD

I should have been clearer (my fault, I forgot to mention critical
information). I generally have "Action=caFree" in my Close event, and
set the global form pointer to NULL in the Destroy event (I know, I
know, don't use Destroy, use the destructor, but this has been working
for me for eons, and I'm of the "if it ain't broke don't fix it" school).
Therefore, when I close a form, I am deleting it and freeing the memory.
Thus if MainForm creates Form1, and Form1 creates Form2, closing Form1
also closes (and frees) Form2.
David Erbas-White
 

Re:how to set a owner of form???

David Erbas-White < XXXX@XXXXX.COM >wrote:
Quote
[...] Therefore, when I close a form, I am deleting it and
freeing the memory. Thus if MainForm creates Form1, and
Form1 creates Form2, closing Form1 also closes (and frees)
Form2.
Just because you create the child in one form, it doesn't mean
that that form has to be the Owner.
~ JD
 

Re:how to set a owner of form???

David Erbas-White < XXXX@XXXXX.COM >wrote:
Quote
[...] It was stated that the only time that a taskbutton
is NOT created is if the MainForm owns all the other forms,
but is this really true?
You misunderstood my reply. To save you from reading the
entire thread, the OP's code had issues that he didn't seem to
want to fix. He just wanted a 'one word' answer on how to not
show the new form on the taskbar using his existing code.
To that I replied to use the Main form as the Owner. Now, that
said, I googled a bit and it's the Parent - not the Owner that
effects how it appears on the taskbar.
So ... 20 lashes with a wet noodle for me.
~ JD
 

Re:how to set a owner of form???

"JD" < XXXX@XXXXX.COM >đ┤╚ŰË╩╝■ news:3f2c2a47$ XXXX@XXXXX.COM ...
Quote

"Siney San" < XXXX@XXXXX.COM >wrote:
>Could you tell me how to hide taskbutton in all case.

Set new form Owner to the application main form.
All form in one applicationúČit must be available.But my form in the DLL, I
write code like below, but can't work fine.
in Exe
{
...
ShowMyForm(this,Handle); //this is my main form.
}
in Dll
ShowMyForm(TForm* parent,HWND hwnd)
{
Tmyfrm* frm=new Tmyfrm(parent); // or Tmyfrm* frm=new Tmyfrm(hwnd);
frm->ShowModal();
delete frm;
}
then, there is a taskbutton in the taskbar.
Anyone can tell me why?
 

Re:how to set a owner of form???

David Erbas-White wrote:
Quote
In other words, I don't
want Form1 to close without closing Form2. This can only (easily) be
accomplished by having Form1 'own' Form2, and freeing Form1 (and thus
Form2) upon closing.
Form2 will be closed and deleted too if Form1 is closed and in
Form1::OnCLose() Action is set to caFree;
Quote
Now, I can't really see the above scenario as being all that unusual.
So, coming back to my original question, if the MainForm owns Form1, but
Form1 owns Form2, is to know if a taskbutton is created for Form1,
Form2, or both (or none)?
No. For the whole application there is onlt one taskbutton.
Hans.
 

Re:how to set a owner of form???

Hans Galema < XXXX@XXXXX.COM >wrote:
Quote
[...] For the whole application there is onlt one taskbutton.
Add this to Form2 right after the Constructor - nothing gets added to the header - and see what happens.
void __fastcall TForm2::CreateParams( TCreateParams& Params )
{
TForm::CreateParams( Params );
Params.ExStyle |= WS_EX_APPWINDOW;
Params.WndParent = GetDesktopWindow();
}
~ JD
 

Re:how to set a owner of form???

Siney San wrote:
Quote
All form in one applicationúČit must be available.But my form in the DLL, I
write code like below, but can't work fine.
then, there is a taskbutton in the taskbar.
Anyone can tell me why?
Well, I had never put a TForm in a DLL before and as you did not
supply all the code I had to start from scratch.
Kent Reisdorph
Using a VCL form in a DLL
www.bridgespublishing.com/articles/issues/9809/Using_a_VCL_form_in_a_DLL.htm
or
tinyurl.com/iwbw
was a good start, and it was even easier as described there as the
myforms.lib was created by bcp3 compiling myforms.cpp.
Can only confirm what you say: there is an extra button in the
taskbar with a form from a dll.
Don't know the reason.
Then I did a google search in *cppbuilder* nesgroups for
DLL second taskbar
and found the problem reported many times.
A cause of this behaviour is described in
www.google.nl/groups&lr=&ie=UTF-8&oe=UTF-8&selm=37743655.45251718%40forums.inprise.com&rnum=4
or
tinyurl.com/iwcn
Hans.
 

Re:how to set a owner of form???

The ariticle discussed the way that is static link, but my app must use
dynamic LoadLibrary to call form.
Quote
Can only confirm what you say: there is an extra button in the
taskbar with a form from a dll.
Yes, there is a extra button that must be create by dll-form.
If can I set style of window to hide the button?
Quote
Don't know the reason.

Then I did a google search in *cppbuilder* nesgroups for
DLL second taskbar
and found the problem reported many times.

A cause of this behaviour is described in

www.google.nl/groups&lr=&ie=UTF-8&oe=UTF-8&selm=37743655.45251718%40forums.inprise.com&rnum=4
or
tinyurl.com/iwcn

Thank you for your help.