InvokeHelper

InvokeHelper,當在項目中插入ActiveX控制項ClassWizard生成的CWnd的派生類時,在C++類中可以看到其成員函式的代碼中都有對InvokeHelper函式的調用,InvokeHelper函式的第一個參數都和對應的屬性或方法在ActiveX控制項中的分發(dispatch)ID(標識ActiveX控制項的方法或屬性的)相對應。

基本信息

當在項目中插入ActiveX控制項ClassWizard生成的CWnd的派生類時,在C++類中可以看到其成員函式的代碼中都有對InvokeHelper函式的調用,InvokeHelper函式的第一個參數都和對應的屬性或方法在ActiveX控制項中的分發(dispatch)ID(標識ActiveX控制項的方法或屬性的)相對應。通過查看ActiveX控制項help檔案可以發現,ActiveX控制項的方法在生存的C++類中都有同名的成員函式與之對應,ActiveX控制項的屬性都有一組Get和Set函式對其操作,其中ActiveX控制項的方法和屬性操作與生成的C++類成員函式相關聯都是通過InvokeHelper函式的調用來完成的,InvokeHelper函式的第一個參數是由Component Gallery(控制項提供者)提供的。因為經過這樣的處理,所以我們如果要調用ActiveX控制項的方法或對其屬性進行取和設定操作,只需調用生成的C++類對應的成員函式便可。

其他信息

下面對InvokeHelper單獨說明:
CWnd::InvokeHelper
void InvokeHelper( DISPID dwDispID, WORD wFlags, VARTYPE vtRet, void* pvRet, const BYTE* pbParamInfo, ... );
說明:
Call this member function to invoke the OLE control method or property specified by dwDispID, in the context specified by wFlags.
其中參數:
dwDispID:
//Identifies the method or property to be invoked. This value is usually supplied by Component Gallery.
wFlags:可以為下面些值,指明調用InvokeHelper的目的。
//[ DISPATCH_METHOD ] The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag may be set.
[ DISPATCH_PROPERTYGET ] The member is retrieved as a property or data member.
[ DISPATCH_PROPERTYPUT ] The member is changed as a property or data member.
[ DISPATCH_PROPERTYPUTREF ] The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object.
vtRet:
//Specifies the type of the return value.
VT_EMPTY void
VT_I2 short
VT_I4 long
VT_R4 float
VT_R8 double
VT_CY CY
VT_DATE DATE
VT_BSTR BSTR
VT_DISPATCH LPDISPATCH
VT_ERROR SCODE
VT_BOOL BOOL
VT_VARIANT VARIANT
VT_UNKNOWN LPUNKNOWN
pvRet:
//Address of the variable that will that will receive the property value or return value. It must match the type specified by vtRet.
pbParamInfo:一般都設定為NULL
//Pointer to a null-terminated string of bytes specifying the types of the parameters following pbParamInfo.
specifies the types of the parameters passed to the method or property.
...:
//Variable List of parameters, of types specified in pbParamInfo.
InvokeHelper()函式的用法
1、播放檔案的函式:
void CActiveMovie3::Run()
{
InvokeHelper(0x60020001, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
2、暫停播放的函式: void CActiveMovie3::Pause()
{
InvokeHelper(0x60020002, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
4、停止播放的函式: void CActiveMovie3::Stop()
{
InvokeHelper(0x60020003, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
5、獲得檔案的函式: CString CActiveMovie3::GetFileName()
{
CString result;
InvokeHelper(0xb, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}
6、設定檔案的函式: void CActiveMovie3::SetFileName(LPCTSTR lpszNewValue)
{
static BYTE parms[] = VTS_BSTR;
InvokeHelper(0xb, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}
7、獲得播放位置的函式: double CActiveMovie3::GetCurrentPosition()
{
double result;
InvokeHelper(0xd, DISPATCH_PROPERTYGET, VT_R8, (void*)&result, NULL);
return result;
}
8、設定播放位置的函式: void CActiveMovie3::SetCurrentPosition(double newValue)
{
static BYTE parms[] = VTS_R8;
InvokeHelper(0xd, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
9、獲得音量的函式: long CActiveMovie3::GetVolume()
{
long result;
InvokeHelper(0x13, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}
10、設定音量的函式: void CActiveMovie3::SetVolume(long nNewValue)
{
static BYTE parms[] = VTS_I4;
InvokeHelper(0x13, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue);
}

相關詞條

相關搜尋

熱門詞條

聯絡我們