error in calling ActiveX Property from html code
Hello all,
I have created One activeX control and create One BackColor Property. when i use this ActiveX in any vb project it shows me the above property and if i change the backcolor it shows the chages. but when i run the application with the control the changes lost.
Same way When i use the ActiveX control in Html page, it chages doesnot works.. the html code i use is as follows:
<HTML>
<HEAD>
<TITLE>prjTest.CAB</TITLE>
</HEAD>
<BODY>
<!-- If any of the controls on this page require licensing, you must
create a license package file. Run LPK_TOOL.EXE to create the
required LPK file. LPK_TOOL.EXE can be found on the ActiveX SDK,
http://www.microsoft.com/intdev/sdk/sdk.htm. If you have the Visual
Basic 6.0 CD, it can also be found in the \Tools\LPK_TOOL directory.
The following is an example of the Object tag:
<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
<PARAM NAME="LPKPath" VALUE="LPKfilename.LPK">
</OBJECT>
-->
<OBJECT ID="ucTest"
CLASSID="CLSID:6771C92A-1766-449D-917A-55DE0F7779F4"
CODEBASE="prjTest.CAB#version=1,0,0,24" height="500" width="1000">
<PARAM NAME="ucBackColor" VALUE="#CCFFFF">
</OBJECT>
</BODY>
</HTML>
If anybody know plz reply...
# 1 Re: error in calling ActiveX Property from html code
Show us the code of ActiveX Control.
And please refrain from posting the same question in multiple threads.
# 2 Re: error in calling ActiveX Property from html code
ActiveX controls can save the properties using a property bag. Have you included code within the control for this?
# 3 Re: error in calling ActiveX Property from html code
I use following code for ACtiveX control's Property..
Dim m_backColor As String
Const m_init_backColor = "#FFFF1F"
Public Property Get ucBackColor() As String
ucBackColor = m_backColor
End Property
Public Property Let ucBackColor(ByVal vNewValue As String)
m_backColor = vNewValue
PropertyChanged "ucBackColor"
picture1.BackColor = HEXCOL2RGB(m_backColor)
End Property
Private Sub UserControl_InitProperties()
m_backColor = m_init_backColor
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_backColor = PropBag.ReadProperty("ucBackColor", m_init_backColor)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("ucBackColor", m_backColor, m_init_backColor)
End Sub
# 4 Re: error in calling ActiveX Property from html code
First, color values are Longs, not strings. Also, using OLE_COLOR will enable the property browser to show the color dialog. Using Option Explicit is highly recommended, as it will help you make certain you haven't mistyped the name of a variable, or forgot to declare it. The problem I see with the code as you posted it, is that the BackColor of the picturebox isn't being set until the property is called. So at startup, no change to the property is made. In the code example below, I added a SetProperties sub, in which you can put all the code which makes the changes to properties at startup. Then, the other addition I made is to call the SetProperties sub from within the Resize Event for the control, which insures that properties are set upon startup. Although you could call the SetProperties sub from all public properties, that might end up being somewhat inefficient if it updates many properties when only one has been changed. There are of course many ways to approach this, and the method you choose should take into consideration the requirements of the control.
Option Explicit
Dim m_backColor As Long
Const m_init_backColor = &HFFFF1F
Public Property Get ucBackColor() As OLE_COLOR
ucBackColor = m_backColor
End Property
Public Property Let ucBackColor(ByVal vNewValue As OLE_COLOR)
m_backColor = vNewValue
picture1.BackColor = m_backColor
PropertyChanged "ucBackColor"
End Property
Private Sub SetProperties()
picture1.BackColor = m_backColor
End Sub
Private Sub UserControl_InitProperties()
m_backColor = m_init_backColor
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_backColor = PropBag.ReadProperty("ucBackColor", m_init_backColor)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("ucBackColor", m_backColor, m_init_backColor)
End Sub
Private Sub UserControl_Resize()
SetProperties
End Sub
# 5 Re: error in calling ActiveX Property from html code
Thank u Mr.WizBang for correcting my mistake.
Your solution works great for me. and one more thing is that I already try color as OLE_COLOR , but the OLE_COLOR is may be system color. and i have to use this activeX in webpage, may OLE_COLOR not work there. I try but i gives me error message. so i drop to use that. but i am not sure.. so i decide to use string. thanks a lot once again.
# 6 Re: error in calling ActiveX Property from html code
If OLE_COLOR cannot be used, then use Long.
# 7 Re: error in calling ActiveX Property from html code
I can use backcolor as long, but i have to use this activeX control in web page and there value for color will come in hex format (#CCFFFF) so I use string.
# 8 Re: error in calling ActiveX Property from html code
Ah, I see. Now that makes sense.
For those who are reading this thread though, browser colors are Red, Green, Blue, so they aren't actually true Hex values as the windows OS uses. Hex values here are Blue, Green, Red, as a result of the byte order. That means your conversion function needs to swap Blue and Red. Otherwise you could use Replace().