Page 1 of 2
ActiveX VB with xHarbour
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Mon Aug 14, 2006 5:26 pm
by areang
Hi all !
oButton := xButton():New( oWnd )
IF !oButton:lOk
oWnd:END()
RETURN NIL
ENDIF
CLASS xButton
DATA oControl
DATA oButton
CLASSDATA lOk Init .F.
METHOD New()
METHOD Activate()
ENDCLASS
METHOD New( oWnd, nId ) CLASS xButton
IF nId != NIL
::oControl := TActiveX():Redefine( nId, oWnd, "MyOCX.myControl" )
ELSE
::oControl := TActiveX():New( oWnd, "MyOCX.myControl" )
ENDIF
IF !Empty( oWnd:hWnd )
::Activate()
ENDIF
RETURN SELF
METHOD Activate()
::oButton := TOleAuto():New( ActXPdisp( ::oControl:hActiveX ) )
RETURN NIL
My questions :
1. Can I get property on MyOCX, like VB
2. Can I create class to call MyOCX property
Areang
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Wed Aug 16, 2006 8:16 am
by Antonio Linares
Areang,
> 1. Can I get property on MyOCX, like VB
You may use Microsoft OleView to inspect the properties, methods and events of the ActiveX that you are going to use. Another choice is to install if from Microsoft Office built in VBA (macros editor in Word, Excell, etc.) and inspect it from there.
> 2. Can I create class to call MyOCX property
You may use ERROR HANDLER OnError( uParam1 ) to route PRG msgs to Class TActiveX Methods GetProp, SetProp and Do. Please review source\classes\database.prg to see how to use ERROR HANDLER.
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 12:42 am
by areang
Thank.
I will try it.
Areang
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 2:23 am
by areang
Antonio ! Can you help me about this :
I have CoolControls.ocx, viewed by oleview on :
dispinterface _jcFrames {
properties:
methods:
I can see the methods like this :
[id(0x6803000f), propput]
void Caption([in, out] BSTR* rhs);
Please give me sample about this with complete classes.
to call Caption properties
Thank
best Regard
Areang
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 6:04 am
by Antonio Linares
Areang,
Try these:
- Code: Select all Expand view
local cCaption := ""
...
oActiveX:Do( "Caption", cCaption )
MsgInfo( cCaption )
...
MsgInfo( oActiveX:GetProp( "Caption" ) )
...
oActiveX:Do( "Caption", @cCaption )
MsgInfo( cCaption )
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 6:14 am
by areang
Antonio
I Created the Class, still can't put the caption on the frames
and please also ERROR HANDLER ERROR().
Please Help me !
Here is the sample
#include "Fivewin.ch"
FUNCTION Main()
LOCAL oWnd, oFrames
DEFINE Window oWnd
oWnd:setText( "Use JcFrames from CoolControls.ocx" )
oFrames := Framesx():New( oWnd )
/*
To : Antonio
This is Work fine, I want to put caption on this frames
How to create class and use Caption properties
Here are methods on CoolControls.jcFrame, I got from oleview :
[
uuid(4C252B42-CA3D-477E-8A0E-CD2E4AB70B12),
version(1.0),
hidden,
dual,
nonextensible
]
dispinterface _jcFrames {
properties:
methods:
[id(0x68030015), propput]
void FrameColor([in, out] OLE_COLOR* rhs);
[id(0x68030015), propget]
OLE_COLOR FrameColor();
[id(0x68030014), propput, helpstring("Returns/Sets the Fill color for TextBox and Windows style")]
void FillColor([in, out] OLE_COLOR* rhs);
[id(0x68030014), propget, helpstring("Returns/Sets the Fill color for TextBox and Windows style")]
OLE_COLOR FillColor();
[id(0x68030013), propput]
void RoundedCornerTxtBox([in, out] VARIANT_BOOL* rhs);
[id(0x68030013), propget]
VARIANT_BOOL RoundedCornerTxtBox();
[id(0x68030012), propput]
void Enabled([in, out] VARIANT_BOOL* rhs);
[id(0x68030012), propget]
VARIANT_BOOL Enabled();
[id(0x68030011), propput]
void TxtBoxShadow([in, out] jcShadowConst* rhs);
[id(0x68030011), propget]
jcShadowConst TxtBoxShadow();
[id(0x68030010), propput]
void RoundedCorner([in, out] VARIANT_BOOL* rhs);
[id(0x68030010), propget]
VARIANT_BOOL RoundedCorner();
[id(0x6803000f), propput]
void Caption([in, out] BSTR* rhs);
[id(0x6803000f), propget]
BSTR Caption();
[id(0x6803000e), propput]
void Alignment([in, out] AlignmentConstants* rhs);
[id(0x6803000e), propget]
AlignmentConstants Alignment();
[id(0x6803000d), propput]
void Style([in, out] jcStyleConst* rhs);
[id(0x6803000d), propget]
jcStyleConst Style();
[id(0x6803000c), propput]
void TextBoxHeight([in, out] long* rhs);
[id(0x6803000c), propget]
long TextBoxHeight();
[id(0x6803000b), propput]
void TextColor([in, out] OLE_COLOR* rhs);
[id(0x6803000b), propget]
OLE_COLOR TextColor();
[id(0x6803000a), propput]
void TextBoxColor([in, out] OLE_COLOR* rhs);
[id(0x6803000a), propget]
OLE_COLOR TextBoxColor();
[id(0x68030009), propput]
void BackColor([in, out] OLE_COLOR* rhs);
[id(0x68030009), propget]
OLE_COLOR BackColor();
[id(0x68030008), propputref]
void Font([in, out] Font** rhs);
[id(0x68030008), propput]
void Font([in, out] Font** rhs);
[id(0x68030008), propget]
Font* Font();
[id(0x68030007), propget]
Picture* Picture();
[id(0x68030007), propputref]
void Picture([in] Picture* rhs);
[id(0x68030006), propget]
short IconSize();
[id(0x68030006), propput]
void IconSize([in] short rhs);
[id(0x68030005), propput]
void IconAlignment([in, out] IconAlignConst* rhs);
[id(0x68030005), propget]
IconAlignConst IconAlignment();
[id(0x68030004), propget]
jcThemeConst ThemeColor();
[id(0x68030004), propput]
void ThemeColor([in] jcThemeConst rhs);
[id(0x68030003), propget, helpstring("Returns/Sets the Start color for gradient")]
OLE_COLOR ColorFrom();
[id(0x68030003), propput, helpstring("Returns/Sets the Start color for gradient")]
void ColorFrom([in, out] OLE_COLOR* rhs);
[id(0x68030002), propget, helpstring("Returns/Sets the End color for gradient")]
OLE_COLOR ColorTo();
[id(0x68030002), propput, helpstring("Returns/Sets the End color for gradient")]
void ColorTo([in, out] OLE_COLOR* rhs);
[id(0x68030001), propput]
void HeaderStyle([in, out] jcHeaderConst* rhs);
[id(0x68030001), propget]
jcHeaderConst HeaderStyle();
[id(0x68030000), propput]
void GradientHeaderStyle([in, out] jcGradConst* rhs);
[id(0x68030000), propget]
jcGradConst GradientHeaderStyle();
};
*/
oWnd:oClient := oFrames:oControl
Activate Window oWnd
Return NIL
CLASS FRAMESX
DATA oControl
DATA oButton
CLASSDATA lOk Init .F.
ERROR HANDLER ERROR()
METHOD New()
METHOD Activate()
METHOD Install()
METHOD CheckOCX()
ENDCLASS
METHOD New( oWnd,nId ) CLASS FRAMESX
::CheckOCX()
IF !::lOk
MsgInfo( "Error to Install OCX Control" )
RETURN SELF
ENDIF
IF nId != NIL
::oControl := TActiveX():Redefine( nId, oWnd, "COOLCONTROLS.jcFrames" )
ELSE
::oControl := TActiveX():New( oWnd, "COOLCONTROLS.jcFrames" )
ENDIF
IF !Empty( oWnd:hWnd )
::Activate()
ENDIF
RETURN SELF
METHOD Activate()
::oButton := TOleAuto():New( ActXPdisp( ::oControl:hActiveX ) )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
METHOD CheckOCX( lAutoInstall )
DEFAULT lAutoInstall := .F.
IF !::lOk
IF IsActiveX( "CoolControls.jcFrames" )
::lOk := .T.
ELSE
IF lAutoInstall .OR. MsgAlert( "Install OCX COntrol Now ?", { "Yes", "No" } ) == 1
MsgRun( "Installing OCX Control", NIL, { || ::Install() } )
ENDIF
ENDIF
ENDIF
RETURN ::lOk
/*-----------------------------------------------------------------------------------------------*/
METHOD Install()
LOCAL cOriginal, cDestination
cOriginal := "CoolControls.ocx"
cDestination := GetSysDir() + "\CoolControls.ocx"
IF !File( cOriginal )
MsgAlert(cOriginal+" file not found")
RETURN NIL
ENDIF
if !File((cDestination))
Copy File &cOriginal TO &cDestination
endif
if File((cDestination))
WinExec( "REGSVR32 " + cDestino + " /s" )
endif
::lOk := IsActiveX( "CoolControls.jcFrames" )
IF !::lOk
MsgInfo( "Error to Register "+cOriginal+" File" )
ENDIF
RETURN NIL
METHOD ERROR( uParam1 )
LOCAL cMsg, nParam, uRet
nParam := PCount()
cMsg := __GetMessage()
IF SubStr( cMsg, 1, 1 ) == "_"
cMsg := SubStr( cMsg, 2 )
ENDIF
/*
How to handle error code start from here
*/
DO CASE
CASE nParam == 0
uRet := "I don't know"
CASE nParam == 1
uRet := "What is this"
ENDCASE
RETURN uRet
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 6:40 am
by Antonio Linares
Areang,
To set the caption try this:
oActiveX:SetProp( "Caption", "Hello world" )
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 6:45 am
by Antonio Linares
- Code: Select all Expand view
METHOD ERROR( uParam1 ) CLASS FRAMESX
local cMsg := __GetMessage()
if SubStr( cMsg, 1, 1 ) == "_"
return ::SetProp( SubStr( cMsg, 2 ), uParam1 )
else
return ::GetProp( cMsg )
endif
return nil
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 7:14 am
by areang
Thank Antonio, It's work now.
Areang
![Laughing :lol:](./images/smilies/icon_lol.gif)
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 7:40 am
by areang
Hi Antonio !
This is the first class was create by me, and so happy.
But can't put the others control on this frames to work with my windows.
How to work together between xHB control and myocx control.
when uncomment this "oWnd:oClient := oFrames:oControl"
the others control can work together, Is that true ?
In VB, I can see the properties position :
Height, Left, Top and Width but I can't see on oleview of them.
Can you help me again about this ?
Thank
Best Regard
Areang
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 8:52 am
by Antonio Linares
Areang,
>
when uncomment this "oWnd:oClient := oFrames:oControl"
the others control can work together, Is that true ?
>
Yes, because oWnd:oClient fills the entire surface of the window with the control, so if you want to use more controls on it, you can't assign it to oWnd:oClient.
>
In VB, I can see the properties position :
Height, Left, Top and Width but I can't see on oleview of them.
>
Class TActiveX inherits from Class TControl, so you can do:
oActiveX:nTop = ...
oActiveX:nLeft = ...
oActiveX:nWidth = ...
oActiveX:nHeight = ...
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 9:50 am
by areang
Antonio !
On activex.prg, I can see the class :
CLASS TActiveX FROM TControl
there is :
METHOD ReSize( nFlags, nWidth, nHeight ) INLINE ;
ActXSetLocation( ::hActiveX, 0, 0, nWidth, nHeight )
Can I use it for position my frames ?
Or I have to add this :
Class TActiveX inherits from Class TControl, so you can do:
oActiveX:nTop = ...
oActiveX:nLeft = ...
oActiveX:nWidth = ...
oActiveX:nHeight = ...
But where to write of this code below :
( Please you write here or on activex.prg )
This is my code class, next is activex class
#include "Fivewin.ch"
CLASS FRAMESX
DATA oControl
DATA oButton
CLASSDATA lOk Init .F.
ERROR HANDLER ERROR()
METHOD New()
METHOD Activate()
METHOD Install()
METHOD CheckOCX()
ENDCLASS
METHOD New( oWnd,nId ) CLASS FRAMESX
local cCaption := ""
::CheckOCX()
IF !::lOk
MsgInfo( "Error to Install OCX Control" )
RETURN SELF
ENDIF
IF nId != NIL
::oControl := TActiveX():Redefine( nId, oWnd, "COOLCONTROLS.jcFrames" )
ELSE
::oControl := TActiveX():New( oWnd, "COOLCONTROLS.jcFrames" )
ENDIF
::oControl:SetProp( "Caption", "Hello world" )
IF !Empty( oWnd:hWnd )
::Activate()
ENDIF
RETURN SELF
METHOD Activate()
::oButton := TOleAuto():New( ActXPdisp( ::oControl:hActiveX ) )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
METHOD CheckOCX( lAutoInstall )
DEFAULT lAutoInstall := .F.
IF !::lOk
IF IsActiveX( "CoolControls.jcFrames" )
::lOk := .T.
ELSE
IF lAutoInstall .OR. MsgAlert( "Install OCX COntrol Now ?", { "Yes", "No" } ) == 1
MsgRun( "Installing OCX Control", NIL, { || ::Install() } )
ENDIF
ENDIF
ENDIF
RETURN ::lOk
METHOD Install()
LOCAL cOriginal, cDestination
cOriginal := "CoolControls.ocx"
cDestination := GetSysDir() + "\CoolControls.ocx"
IF !File( cOriginal )
MsgAlert(cOriginal+" file not found")
RETURN NIL
ENDIF
if !File((cDestination))
Copy File &cOriginal TO &cDestination
endif
if File((cDestination))
WinExec( "REGSVR32 " + cDestination + " /s" )
endif
::lOk := IsActiveX( "CoolControls.jcFrames" )
IF !::lOk
MsgInfo( "Error to Register "+cOriginal+" File" )
ENDIF
RETURN NIL
METHOD ERROR( uParam1 ) CLASS FRAMESX
local cMsg := __GetMessage()
if SubStr( cMsg, 1, 1 ) == "_"
return ::SetProp( SubStr( cMsg, 2 ), uParam1 )
else
return ::GetProp( cMsg )
endif
return nil
Thank
Best Regard
Areang
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 10:06 am
by Antonio Linares
Areang,
- Code: Select all Expand view
METHOD New( oWnd, nId, nTop, nLeft, nWidth, nHeight ) CLASS FRAMESX
...
IF nId != NIL
::oControl := TActiveX():Redefine( nId, oWnd, "COOLCONTROLS.jcFrames" )
ELSE
::oControl := TActiveX():New( oWnd, "COOLCONTROLS.jcFrames" )
::oControl:nTop = nTop
::oControl:nLeft = nLeft
::oControl:nWidth = nWidth
::oControl:nHeight = nHeight
ENDIF
...
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 10:51 am
by areang
Antonio !
FUNCTION Main()
LOCAL oWnd, oFrames
DEFINE Window oWnd
oWnd:setText( "Use JcFrames from CoolControls.ocx" )
oFrames := Framesx():New( oWnd,,10,20,200,200 )
--> It's work fine
@100,100 BUTTON "Save" size 60,20 of oWnd pixel action MsgAlert("Save")
--> When I click the button, no action because the button draw on frames
--> What is your suggest ?
--> Should I add the my frames on class control ?
Activate Window oWnd
Return NIL
Thank
Best Regard
Areang
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Aug 18, 2006 5:24 pm
by Antonio Linares
Areang,
> @100,100 BUTTON "Save" size 60,20 of oWnd pixel action MsgAlert("Save")
That control is a child control of oWnd so oWnd should get notified when it gets clicked and the ACTION clause should work.