-
Form Container Control in VB5
Good day, all.
When changing our architecture from VB5 UserDocuments in a frameset, it was
decided that we should convert all the UserDocuments to Forms and write a
"Form Container" control to allow us to dynamically load forms (contained
in a variety of ActiveX DLL projects) onto our overall container (which can
be a UserDocument or a Form). Naturally, if we had been using VB6, we would
have used UserControls. Unfortunately it was decided that moving from VB5
to VB6 this late in the project life cycle would be too dangerous.
This "Form Container" control is an encapsulation of functionality that allows
you to position where forms will appear, and then SetParent themselves to
the UserControl. The control will handle style changes, termination gracefully,
and up to now it has worked pretty well. Unfortunately, an unforseen problem
is that these forms do not handle application focus properly. For instance,
if a control within a contained form has the focus, and you ALT-TAB to another
application, and then ALT-TAB back again, that control no longer has the
focus. Instead, the Form Container control has the focus. Or if there is
a control at the top level form, that control will have the focus. Also,
the tab order won't work as it would in a normal UserControl, i.e. VB actually
handles tabbing into the UserControl, through its constituents, and out again.
Aha - I've just had a thought. A couple of months ago, I was creating a UserControl
based on the API Edit control (with CreateWindowEx). I was having tabbing
problems there, and somebody suggested implementing the IActiveFocus (??)
interface. In the mean time, I will look into this.
Any suggestions?
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-
Re: Form Container Control in VB5
... further on ...
I have found the same that I looked at a couple of months ago. The interface
that I was thinking about was the IOleInPlaceActiveObject interface, and
the sample was on the vbAccelerator site (http://www.vbaccelerator.com),
called Tab Trap (http://vbaccelerator.com/codelib/scontrol/tabtrap.htm),
and Owner Draw Combo and List Boxes (http://vbaccelerator.com/codelib/odcbolst/article.htm).
Unfortunately, I don't think that it is that helpful in my case, since I
am not really interested in tabbing off the forms (well, not just yet). Ideally,
it would be nice to implement the UserControl type approach (i.e. whenever
you tab onto the UserControl, you automatically set focus to the first control
in the UserControl tab order, and after the final control in the tab order,
you tab to the next control on the same level as the UserControl).
One way (seen in the vbAccelerator code) was nice and simple - SetFocus to
the form when the GotFocus event of the UserControl fires. This works at
first - you manage to see the first control in the Tab order being focused.
But if you press Tab again, the focus moves to the first control of the next
UserControl, rather than the next control in the current UserControl. Very
weird.
Any further ideas?
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-
Re: Form Container Control in VB5
... further on ...
I have found the same that I looked at a couple of months ago. The interface
that I was thinking about was the IOleInPlaceActiveObject interface, and
the sample was on the vbAccelerator site (http://www.vbaccelerator.com),
called Tab Trap (http://vbaccelerator.com/codelib/scontrol/tabtrap.htm),
and Owner Draw Combo and List Boxes (http://vbaccelerator.com/codelib/odcbolst/article.htm).
Unfortunately, I don't think that it is that helpful in my case, since I
am not really interested in tabbing off the forms (well, not just yet). Ideally,
it would be nice to implement the UserControl type approach (i.e. whenever
you tab onto the UserControl, you automatically set focus to the first control
in the UserControl tab order, and after the final control in the tab order,
you tab to the next control on the same level as the UserControl).
One way (seen in the vbAccelerator code) was nice and simple - SetFocus to
the form when the GotFocus event of the UserControl fires. This works at
first - you manage to see the first control in the Tab order being focused.
But if you press Tab again, the focus moves to the first control of the next
UserControl, rather than the next control in the current UserControl. Very
weird.
Any further ideas?
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-
Re: Form Container Control in VB5
Looking at the last message, I have got too bogged down with detail. To put
it simply, I just want to be able to duplicate the functionality of focus
implemented by UserControls, but with Forms.
Thanks,
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-
Re: Form Container Control in VB5
Looking at the last message, I have got too bogged down with detail. To put
it simply, I just want to be able to duplicate the functionality of focus
implemented by UserControls, but with Forms.
Thanks,
-------------------------
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-
Re: Form Container Control in VB5
Well, after all that, I have found a reasonable solution. First of all, all
of the controls on the top level form must have TabStop set to False. However,
if you want the focus to go to controls in one particular contained form,
this should be the first added control, or TabStop should be set to True
for this particular instance.
Furthermore, the Form Container control should be subclassed for the WM_SETFOCUS
message (UserControl_GotFocus and UserControl_EnterFocus won't work). If
the control receives this message, then it should SetFocus to the form. This
will in turn set the focus to the ActiveControl on the form.
This is not a perfect generic solution, since it means that the focus will
only return to one of the contained forms, when gaining focus from another
application; however, for my particular application, this is sufficient.
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
-
Re: Form Container Control in VB5
Well, after all that, I have found a reasonable solution. First of all, all
of the controls on the top level form must have TabStop set to False. However,
if you want the focus to go to controls in one particular contained form,
this should be the first added control, or TabStop should be set to True
for this particular instance.
Furthermore, the Form Container control should be subclassed for the WM_SETFOCUS
message (UserControl_GotFocus and UserControl_EnterFocus won't work). If
the control receives this message, then it should SetFocus to the form. This
will in turn set the focus to the ActiveControl on the form.
This is not a perfect generic solution, since it means that the focus will
only return to one of the contained forms, when gaining focus from another
application; however, for my particular application, this is sufficient.
Mark Alexander Bertenshaw
Programmer/Analyst
Prime Response
Brentford
UK
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks