用VC开发一个应用程序,里面需要使用别人提供的OCX组件,以前没有做过ACTIVEX方面的开发,应该怎么调用这个OCX也不知道怎么做,有那位有这方面的经验,请把大致的步骤说一下,或者有例子的给一个小例子最好。请这方面的高手不吝赐教!

解决方案 »

  1.   

    There are 2 ways of importing an ActiveX control into a Visual C++ MFC application: 1) By allowing the Class Wizard to generate wrapper classes for each one of the components contained inside the ActiveX. This is done automatically when you assign a member variable to the object. 2) By using the #import directive as follows: In your precompiled header (STDAFX.H) 
    // DEFINITION of COM wrappers
    #import "sfxbar.dll" no_namespace no_implementation
    #import "Cfx4032.ocx" no_namespace no_implementation
    In your implementation (STDAFX.CPP) 
    // IMPLEMENTATION of COM wrappers
    #import "sfxbar.dll" no_namespace implementation_only
    #import "Cfx4032.ocx" no_namespace implementation_only
      

  2.   

    VC6吗?Project->Add To Project->Components and Controls
    楼上讲的也行,不过添加到窗体上时要自己写相应的代码,不能使用拖拽的方式
      

  3.   

          CoInitialize(NULL); 
          short st = 2; 
           short st1; 
          // Declare the Interface Pointer for your Visual Basic object. Here, 
          // _Class1Ptr is the Smart pointer wrapper class representing the 
          // default interface of the Visual Basic object. 
     
          _Class1Ptr ptr; 
          // Create an instance of your Visual Basic object, here 
          // __uuidof(Class1) gets the CLSID of your Visual Basic object. 
     
           ptr.CreateInstance(__uuidof(Class1)); 
           st1 = ptr->MyVBFunction(&st); 
          } 
          catch(_com_error &e) 
          { 
           bstrDesc = e.Description(); 
     
          } 
          CoUninitialize(); 
      

  4.   

    从vc编译器中导入对应的ocx控件,编译器会生产对应的包装类等....
      

  5.   

    从vc编译器中导入对应的ocx控件,编译器会生产对应的包装类等....
      

  6.   

    那位高手把这个OCx的导入, 然后创建成类,定义相应的类对象的过程给详细的说一下。刚才试了一下再project下导入OCX不成功。#import"" 进来后以后应该怎么处理?谢谢各位 !
      

  7.   

    以后就调用那些方法就好了,微软caledar控件 有例子的,看看就会了
      

  8.   

    如果在把ocx直接插入到对话框里,在资源视图,找到对话框的资源,右键--》插入activex...->找到你要插入的ocx,插入后,右键这个OCX,生成对应的类~~ 就OK了~~~~~
      

  9.   

    导入不成功可能是OCX控件没有注册,重新注册一下应该就可以了