Click to See Complete Forum and Search --> : ocx control on VB form
billwagnon
Jan 21st, 2002, 11:51 AM
I have made an OCX combo box control that saves file paths to the registry.
The way it *should* work is that the SaveSetting uses the current app name as the registry key.
Instead, the control only picks up its own app name. The control doesn't seem to have any awareness of the form it is called by etc.
How do I make the control aware of the app in which it is operating?
Within the OCX project, I want the code to be able to reference the name of the VB project in which it is being used as a component.
ralph
Jan 21st, 2002, 03:51 PM
Maybe there's another way, but can't you pass the app name from the parent form on Form_load into a user defined property of the ocx?
billwagnon
Jan 21st, 2002, 03:59 PM
I would like the control to do the job automatically; it's one of those deals where I think there should be A way, but it takes a while to find THE way.
Currently, I have a user defined property on the control in which I am manually entering the registry key; your way would automate that part, but it is quicker to type the key in than to code to automate it.
I've been looking for a good book on ActiveX / OCX controls, but I can't find any. Do you have any recommendations? :cool:
Edneeis
Jan 21st, 2002, 04:26 PM
Check out Joacim Andersson's reply in this old thread:
http://www.vbforums.com/showthread.php?s=&threadid=107707
That should be what you are looking for.
billwagnon
Jan 22nd, 2002, 07:36 AM
The thread deals with determining the calling program - and it works in that respect. But the value returned is for VB - not for the project in which I am using the control.
Is there a way to get the project name of the project using the OCX control? Or does that violate the rules of COM?
Thank you for your input. :)
billwagnon
Jan 22nd, 2002, 07:48 AM
Found this on Planet Source Code, and it works (almost) - it gives the name of the form on which the control is placed. Can you get from the ParentControls to the project name?
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=644&lngWId=1
'**************************************
' Name: Getting a Reference to a VB 5.0
' UserControl
' Description:Visual Basic 5.0 allows yo
' u to use UserControls to create ActiveX
' controls in your projects. The following
' code snippet does two things: It gets a
' reference to the form in which a UserCon
' trol is placed, and it gets a reference
' to that control on the form. by David Me
' ndlen
' By: Found on the World Wide Web
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:None
'
'Side Effects:None
'**************************************
Dim PControl As Object
Dim MyControl As Control
Dim AControl As Object
'Get my UserControl
For Each AControl In ParentControls
If AControl.Name = Ambient.DisplayName Then
Set MyControl = AControl
Exit For
End If
Next
'Get the Form UserControl is on
Set PControl = ParentControls.Item(1).Parent
While Not (TypeOf PControl Is Form) Set PControl = PControl.Parent
Wend
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.