Handles (as in hWnd) and instances 
Author Message
 Handles (as in hWnd) and instances

I'm building an app with multiple forms having
hierarchical relationships (i.e. Form1 allows the user to
open an instance of Form2 which uses some of Form1's info
to determine the data it displays, Form2 might also allow
the user to open an instance of Form3, and so on).  I
would like to allow the user to open multiple instances
of Form1 and the so multiple instances of Form2 and so on
(only 1 Form2 per Form1 and 1 Form3 per Form2), but I
need a way to ID these instances.  I thought hWnd was the
way to go, but the VB help index admonishes me not to do
this since apparently hWnd can change.  Any suggestions?


Sat, 26 Nov 2005 22:35:01 GMT  
 Handles (as in hWnd) and instances
Hello,


Quote:
> I'm building an app with multiple forms having
> hierarchical relationships (i.e. Form1 allows the user to
> open an instance of Form2 which uses some of Form1's info
> to determine the data it displays, Form2 might also allow
> the user to open an instance of Form3, and so on).  I
> would like to allow the user to open multiple instances
> of Form1 and the so multiple instances of Form2 and so on
> (only 1 Form2 per Form1 and 1 Form3 per Form2), but I
> need a way to ID these instances.  I thought hWnd was the
> way to go, but the VB help index admonishes me not to do
> this since apparently hWnd can change.  Any suggestions?

Untested:

You can make a call to the form's GetHashCode method to create an
identifier.

Are you talking about VB Classic or VB .NET?

Regards,
Herfried K. Wagner
--
http://www.mvps.org/dotnet



Sat, 26 Nov 2005 23:20:46 GMT  
 Handles (as in hWnd) and instances
Thx for the response.  I'm using vb.NET.  I had already
thought of using the hash code.  I'm pretty new to vb
programming, but had assumed that I was trying to do a
fairly standard thing, and that there was a standard way
doing it.  
Anyway, my approach will be to create a unique ID for all
forms and to create a private variable for each form
(e.g. Dim ParentForm as String) and set the new variable
to equal the unique ID of the calling form.  Child form
events will only be able to call parent form methods when
their ParentForm value matches the ID of the parent
form.  But, as I said, it seems this should be a pretty
standard thing, so I was hoping there were already built-
in methods and/or properties to help me implement this
scheme.
Quote:
>-----Original Message-----
>Hello,


>> I'm building an app with multiple forms having
>> hierarchical relationships (i.e. Form1 allows the user
to
>> open an instance of Form2 which uses some of Form1's
info
>> to determine the data it displays, Form2 might also
allow
>> the user to open an instance of Form3, and so on).  I
>> would like to allow the user to open multiple instances
>> of Form1 and the so multiple instances of Form2 and so
on
>> (only 1 Form2 per Form1 and 1 Form3 per Form2), but I
>> need a way to ID these instances.  I thought hWnd was
the
>> way to go, but the VB help index admonishes me not to
do
>> this since apparently hWnd can change.  Any
suggestions?

>Untested:

>You can make a call to the form's GetHashCode method to
create an
>identifier.

>Are you talking about VB Classic or VB .NET?

>Regards,
>Herfried K. Wagner
>--
>http://www.mvps.org/dotnet

>.



Sun, 27 Nov 2005 00:16:25 GMT  
 Handles (as in hWnd) and instances
There are so many ways to do this it's not even funny. Perhaps the best way
for you is to create a FormManager class that would keep track of the
relationships. Rather than creating a new instance of a form, you would send
the form Type and the parent form to a method in your FormManager that would
create the new instance, record the relationship, and return the reference
to the new form. That would enable you to track relationships throughout the
application from a level higher than any particualar form. This would be a
generically reusable solution.

But there are other, simpler methods as well. For example, you could simply
set the Tag property of each form as you create it. You could add ParentForm
and ChildForms properties to your forms and populate them as needed when the
user creates new child forms. Although not generic, this method would be
fast and easy.



Quote:
> Hello,


> > I'm building an app with multiple forms having
> > hierarchical relationships (i.e. Form1 allows the user to
> > open an instance of Form2 which uses some of Form1's info
> > to determine the data it displays, Form2 might also allow
> > the user to open an instance of Form3, and so on).  I
> > would like to allow the user to open multiple instances
> > of Form1 and the so multiple instances of Form2 and so on
> > (only 1 Form2 per Form1 and 1 Form3 per Form2), but I
> > need a way to ID these instances.  I thought hWnd was the
> > way to go, but the VB help index admonishes me not to do
> > this since apparently hWnd can change.  Any suggestions?

> Untested:

> You can make a call to the form's GetHashCode method to create an
> identifier.

> Are you talking about VB Classic or VB .NET?

> Regards,
> Herfried K. Wagner
> --
> http://www.mvps.org/dotnet



Sun, 27 Nov 2005 00:26:06 GMT  
 Handles (as in hWnd) and instances
I feel like my head is going to explode.  If I understand
you correctly you are saying that I should create a class
which is a collection of "uberforms".  It would include,
say, an add method which creates an ID for and opens a
form.  The forms themselves would only be one property of
the "uberform" members of FormManager.  Another property
would be the relationship to other uberforms.

Is this what you are suggesting?

Pat

Quote:
>-----Original Message-----
>There are so many ways to do this it's not even funny.

Perhaps the best way
Quote:
>for you is to create a FormManager class that would keep
track of the
>relationships. Rather than creating a new instance of a

form, you would send
Quote:
>the form Type and the parent form to a method in your

FormManager that would
Quote:
>create the new instance, record the relationship, and

return the reference
Quote:
>to the new form. That would enable you to track

relationships throughout the
Quote:
>application from a level higher than any particualar

form. This would be a
Quote:
>generically reusable solution.

>But there are other, simpler methods as well. For

example, you could simply
Quote:
>set the Tag property of each form as you create it. You

could add ParentForm
Quote:
>and ChildForms properties to your forms and populate

them as needed when the
Quote:
>user creates new child forms. Although not generic, this
method would be
>fast and easy.




>> Hello,


>> > I'm building an app with multiple forms having
>> > hierarchical relationships (i.e. Form1 allows the
user to
>> > open an instance of Form2 which uses some of Form1's
info
>> > to determine the data it displays, Form2 might also
allow
>> > the user to open an instance of Form3, and so on).  I
>> > would like to allow the user to open multiple
instances
>> > of Form1 and the so multiple instances of Form2 and
so on
>> > (only 1 Form2 per Form1 and 1 Form3 per Form2), but I
>> > need a way to ID these instances.  I thought hWnd
was the
>> > way to go, but the VB help index admonishes me not
to do
>> > this since apparently hWnd can change.  Any
suggestions?

>> Untested:

>> You can make a call to the form's GetHashCode method
to create an
>> identifier.

>> Are you talking about VB Classic or VB .NET?

>> Regards,
>> Herfried K. Wagner
>> --
>> http://www.mvps.org/dotnet

>.



Sun, 27 Nov 2005 01:12:34 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. hWnd from Instance Handle

2. Window Handle based on Instance Handle???

3. How to Find a Window Handle Based on an Instance Handle

4. How to Find a Window Handle Based on an Instance Handle

5. Window Handle - hwnd property

6. Invoking methods of VB 4 and VB 5 - Controls using the window handle (hwnd)

7. Find Window handle (HWND) from a shelled Process ID

8. Invoking methods of VB 4 and VB 5 - Controls using the window handle (hwnd)

9. hWnd - Window Handle for hidden window

10. Windows handle (hWnd)

11. Can I convert a module handle to hWnd?

12. Checkif Handle (hWnd) is valid

 

 
Powered by phpBB® Forum Software