转:好贴! vc6中引用第三方控件的方法

原文:http://andykcx.blog.51cto.com/464336/106842

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://andykcx.blog.51cto.com/464336/106842
1.检查你的系统上是否有该控件(ocx)并已注册。
2.project->add project->components and controls,

3.这时会弹出一个components and controls gallery文件选择对话框,

4.两个文件夹: registered activex controls;visual c++ components

5.选择第一文件夹出现一系列系统上已注册过的activex控件。

6.选择所需的控件。

7.点击insert将它插入工程

8.在vc对话框编辑器的controls面板上就会多出一个新图标。

9.工程中自动产生一个该控件对应的类;

10.将新控件拖入对话框中;

11.创建控件的关联类对象;

方法一,手动加入:关键是使用DDX_CONTROL()宏实现控件与类对象的关联


1.CMyDlg.h中添加 对象:

 #include "OcxClass.h"

 protected:
 COcxClass m_NewOcx;

2.CMyDlg.cpp 中增加:

 void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CMyStockDlg)
 // NOTE: the ClassWizard will add DDX and DDV calls here

 ----> DDX_Control(pDX, IDC_NEWOCX1, m_NewOcx);
 (IDC_NEWOCX1: 控件被拖入dlg上时产生的idc)

 //}}AFX_DATA_MAP
}

3. CMyDlg::OnInitDialog() 中加入 测试代码(此处易flash.ocx为例):

 RECT rc;
 this->GetClientRect(&rc);
 
 m_MyFlash1.MoveWindow( &rc, true);
 
 TCHAR strCurDrt[500];
 int nLen = ::GetCurrentDirectory(500,strCurDrt);
 if( strCurDrt[nLen]!='\\' )
 {
  strCurDrt[nLen++] = '\\';
  strCurDrt[nLen] = '\0';
 }
 
 CString strFileName = strCurDrt;
 strFileName += "startup.swf";

 m_MyFlash1.LoadMovie(0, strFileName);
 m_MyFlash1.Play();

 

你可能感兴趣的:(方法)