📄 actvoicectl.cpp
字号:
// ActVoiceCtl.cpp : Implementation of the CActVoiceCtrl ActiveX Control class.
#include "stdafx.h"
#include "ActVoice.h"
#include "ActVoiceCtl.h"
#include "ActVoicePpg.h"
#include "wave.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CActVoiceCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CActVoiceCtrl, COleControl)
//{{AFX_MSG_MAP(CActVoiceCtrl)
// NOTE - ClassWizard will add and remove message map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CActVoiceCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CActVoiceCtrl)
DISP_FUNCTION(CActVoiceCtrl, "start", start, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CActVoiceCtrl, "stop", stop, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CActVoiceCtrl, "readwave", readwave, VT_VARIANT, VTS_NONE)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CActVoiceCtrl, COleControl)
//{{AFX_EVENT_MAP(CActVoiceCtrl)
EVENT_CUSTOM("done", FireDone, VTS_NONE)
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CActVoiceCtrl, 1)
PROPPAGEID(CActVoicePropPage::guid)
END_PROPPAGEIDS(CActVoiceCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CActVoiceCtrl, "ACTVOICE.ActVoiceCtrl.1",
0x63a7e2bc, 0xd047, 0x11d5, 0xa4, 0x82, 0, 0x10, 0xa4, 0xf2, 0x2a, 0xd8)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CActVoiceCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DActVoice =
{ 0x63a7e2ba, 0xd047, 0x11d5, { 0xa4, 0x82, 0, 0x10, 0xa4, 0xf2, 0x2a, 0xd8 } };
const IID BASED_CODE IID_DActVoiceEvents =
{ 0x63a7e2bb, 0xd047, 0x11d5, { 0xa4, 0x82, 0, 0x10, 0xa4, 0xf2, 0x2a, 0xd8 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwActVoiceOleMisc =
OLEMISC_INVISIBLEATRUNTIME |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CActVoiceCtrl, IDS_ACTVOICE, _dwActVoiceOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl::CActVoiceCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CActVoiceCtrl
BOOL CActVoiceCtrl::CActVoiceCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_ACTVOICE,
IDB_ACTVOICE,
afxRegApartmentThreading,
_dwActVoiceOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl::CActVoiceCtrl - Constructor
CActVoiceCtrl::CActVoiceCtrl()
{
InitializeIIDs(&IID_DActVoice, &IID_DActVoiceEvents);
// TODO: Initialize your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl::~CActVoiceCtrl - Destructor
CActVoiceCtrl::~CActVoiceCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl::OnDraw - Drawing function
void CActVoiceCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Ellipse(rcBounds);
}
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl::DoPropExchange - Persistence support
void CActVoiceCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl::OnResetState - Reset control to default state
void CActVoiceCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CActVoiceCtrl message handlers
void CActVoiceCtrl::start()
{
// TODO: Add your dispatch handler code here
wave_reset(this);
wave_start();
}
void CActVoiceCtrl::stop()
{
// TODO: Add your dispatch handler code here
wave_stop();
}
VARIANT CActVoiceCtrl::readwave()
{
VARIANT vaResult;
VariantInit(&vaResult);
// TODO: Add your dispatch handler code here
V_VT(&vaResult) = VT_R8 | VT_ARRAY;
long len = wave_get_len();
if (len>0)
{
double *buff = new double[len];
if (buff)
{
SAFEARRAY *spr;
wave_get_data(buff);
spr= GetSafeArray (buff, len);
V_ARRAY(&vaResult) = spr;
delete [] buff;
}
}
return vaResult;
}
void CActVoiceCtrl::onWaveDone()
{
FireDone();
}
SAFEARRAY* CActVoiceCtrl::GetSafeArray (double *pr, long len)
{
const int nDims = 2;
double *prNew = NULL;
SAFEARRAY * sprNew = NULL;
SAFEARRAYBOUND sab[nDims];
long m = 0,
n = 0;
int count = 0;
HRESULT hr;
m = 1;
n = len;
// set up the safe array bounds based on the matrix we retrieved from MLs
sab[0].cElements = m;
sab[0].lLbound = 0;
sab[1].cElements = n;
sab[1].lLbound = 0;
count = sizeof(double) * m * n;
sprNew = SafeArrayCreate (VT_R8, nDims, sab);
if (!sprNew)
return (NULL);
hr = SafeArrayAccessData (sprNew, (void **) &prNew);
if (FAILED (hr)) {
SafeArrayDestroy (sprNew);
return (NULL);
}
// by doing memcpy we are switching row/column order
memcpy (prNew, pr, count);
SafeArrayUnaccessData (sprNew);
return (sprNew);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -