`
isiqi
  • 浏览: 16648741 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

ATL 封装MSFLEXGRID

阅读更多

Introduction

It is bit tricky to use MSFlexGrid Control in ATL projects (I struggled lot with MSDN and net) because:

  1. MSFlexGrid Control is a Visual Basic control
  2. MSFlexGrid Control requires runtime control license.

To check the problem you can do the following:

  1. Create ATL Server Dll
  2. Add ATL Composite Control
  3. Right Click and insert MSFlexGrid Control
  4. Add Event by right clicking and expose some events.
  5. Build Dll.
  6. Deploy in a test machine along with MSFlex.ocx and other support libraries. Please Note that it will work fine on the development machine (Machine which has visual studio installed) because when you install visual studio it provides design time and runtime license for the current system by default.

See Details on:

Result

It won’t work on test machine (The machine which only has OS installed). If you are Using Visual Basic as client it will display page not found kind of HTML page in place of control.

How To use MSFlexGrid Then?

  1. Create ATL Server Dll.
  2. Add ATL Composite Control.
  3. Import msflxgrd.ocx in control header file.
    #import "C:\WINNT\System32\msflxgrd.ocx" raw_interfaces_only, 
        raw_native_types, no_namespace, named_guids
  4. Add #pragma warning(disable:4146) before #import "...msflxgrid.ocx..." otherwise it will give warning.
  5. Now the problem is: at the time of creating control you need to get the runtime license for MSFlexGrid Control. I had made a function to do so:
    Collapse
     // Create Control
     void CreateObject()
     {
       CComPtr<iunknown></iunknown> pUnkCont;
       ComQIPtr <ipersiststreaminit></ipersiststreaminit> spPerStm;
       CComPtr<iclassfactory2></iclassfactory2> pCF;
       // Add CLSID of MSFlexGrid for Runtime license
       CComBSTR bstrLicKey = "72E67120-5959-11cf-91F6-C2863C385E30";
       HRESULT hr = CoGetClassObject(CLSID_MSFlexGrid,
        CLSCTX_ALL,
        NULL,
            IID_IClassFactory2,
        reinterpret_cast<void**>(&pCF) );
    
       // Call CreateInstanceLic to create instance of control 
       // with runtime license
       if( !FAILED( hr ) )
        hr =pCF->CreateInstanceLic(NULL,NULL,IID_IUnknown,bstrLicKey,
          reinterpret_cast<void**>(&pUnk));
       
       spPerStm=pUnk;
       spPerStm->InitNew();
    
       wnd.Attach(m_hWnd);
       wnd.AttachControl(pUnk, &pUnkCont);
       m_VarGrid = pUnk;
      // Start event connection
      DispEventAdvise(pUnk); 
     }
    
  6. Add the following member variables. I’ve added it the following member variables as public.
        CAxWindow wnd;
        IUnknownPtr pUnk;
        IMSFlexGridPtr m_Grid;
            
  7. Next step is to catch the events of flxgrid control which can be done by adding the following line in class declaration:
    public IDispEventImpl < ID_VAR_GRID,CAuthorVar,&DIID_DMSFlexGridEvents,
        &LIBID_MSFlexGridLib,1,0 >
  8. Add Sink Entry (I’m feeling lazy and just using click event if you want you can use no of events as per ur requirement)
    BEGIN_SINK_MAP(CFlxCtrl)
        //Make sure the Event Handlers have __stdcall calling convention
        SINK_ENTRY_EX(ID_GRID,DIID_DMSFlexGridEvents, DISPID_CLICK, 
          OnClick_grid)
    END_SINK_MAP()   
    
  9. In Resource.h file add #define ID_GRID 201 or any ID which you like.
  10. Add Event Handler:
    VOID __stdcall Click_grid()
    {
        AfxMessageBox("Clicked");
    }
    
  11. You can also add a method to initialize gird i.e..
        void InitGrid()
        {
            CString Cols[5]={"Name","Phone No","MailID"};
            m_VarGrid->put_FixedRows(1);
            m_VarGrid->put_FixedCols(0);
            m_VarGrid->put_Rows(2);
            m_VarGrid->put_Cols(3);
    
            for(int i = 0;i!=3;i++)
            {
                m_VarGrid->put_TextMatrix(0,i,(_bstr_t)Cols[i]);    
                m_VarGrid->put_ColWidth(i,1260);
            }
        } 
    
  12. In the OnInitDialog call CreateObject() function and InitGrid().
  13. Add a method to interface ie.
    STDMETHODIMP CAuthorVar::Stop()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    
        if(pUnk)
        {
            HRESULT hr= DispEventUnadvise(pUnk);//
        }
        m_Grid.Release();
        return S_OK;
    }
    
  14. Test the control in ActiveX Control Test Container and don't forget to call stop method before closing.

I also had noticed another problem which is:

Every time you need to call DispEventUnadvise(pUnk)/DispEventAdvise(pUnk) method and it won't process any messages from container window or other controls placed there. The easiest solution I found is just wrap up your first control into another Composite Control and it will make your life easy.

If you are still feeling lazy or has already created control and don’t want to rewrite then you can cheat the test machine by adding the following in registry:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Licenses\72E67120-5959-11cf-91F6-C2863C385E30]
@="ibcbbbebqbdbciebmcobmbhifcmciibblgmf"

and be happy but I won’t recommend it. So, Have a fun with MSFlexGrid and ATL Composite Control.

<!-- Article Ends -->

Uttam Kumar Unik!

分享到:
评论

相关推荐

    atl封装ie AtlBrowser.zip

    ATL浏览器的实现,如"atl封装ie"所示,是将IE(Internet Explorer)的内核通过ATL进行包装,使得开发者可以更加方便地在应用程序中嵌入和控制Web浏览功能。 1. ATL封装IE内核:ATL提供了一种轻量级的方法来创建COM...

    ATL 封装MFC对话框

    在本案例中,“ATL封装MFC对话框”是指将MFC中的对话框类集成到ATL工程中,这样可以利用ATL的轻量化特性,同时利用MFC对话框的强大功能。这种做法在某些情况下特别有用,比如当你需要在非MFC项目中使用MFC对话框,...

    全套c#atl技术 源码

    在本套源码中,我们看到的是使用C#语言与ATL技术结合的例子,运行环境为Visual Studio 2008。 1. ATLShellExtDragAndDropHandler:这是一个实现拖放操作的外壳扩展。在Windows操作系统中,外壳是用户界面的一部分,...

    ATL技术资料

    VCL(Visual Component Library)是Delphi中的库,虽然在某些方面与ATL相似,但在程序独立性和EXE大小方面可能不如ATL。 WTL(Windows Template Library)是另一个基于ATL的库,它提供了更接近SDK的API,适合编写...

    一个简单的ATL组件

    刚开始学习ATL,做了一个简单的小程序练习练习,还有很多不详尽之处

    用COM ATL DLL编写office word的插件(Add-in).zip

    COM(Component Object Model)是微软提出的一种组件编程模型,它允许不同编程语言之间无缝交互,ATL(Active Template Library)则是微软为简化COM组件开发提供的一套模板库。本项目涉及的是利用COM ATL DLL技术来...

    ATL复合控件上的MSFlexGrid控件

    ATL复合控件上的MSFlexGrid控件是Windows应用程序开发中的一个重要组成部分,特别是在使用C++和Visual Studio 6(VC6)环境下。ATL(Active Template Library)是Microsoft提供的一套模板类库,用于简化COM...

    atl开发指南 atl开发指南 atl开发指南 atl开发指南 atl开发指南

    6. ** ATL ActiveX控件**:ATL使得创建ActiveX控件变得容易,通过使用CComControl类和一系列的控件宏,开发者可以快速构建具有标准属性和事件的ActiveX控件。 7. ** ATL COM服务器**:ATL可以用于创建本地或远程...

    ICESAT-2 +ATL03 + ATL08

    **ICESAT-2 + ATL03 + ATL08 知识点详解** ICESAT-2(Ice, Cloud, and land Elevation Satellite-2)是美国国家航空航天局(NASA)发射的一颗卫星,主要任务是通过激光雷达(Lidar)技术测量全球冰层、森林和地形的...

    ATL 技术内幕 ATL技术内幕

    在深入探讨ATL技术内幕之前,我们先来理解一下ATL的基本概念。 ATL的核心在于模板类和宏,这些模板类和宏简化了COM对象的实现,使得开发者能够快速创建接口、事件处理程序和自动化服务器。ATL通过提供诸如...

    atl 2019 头文件和库

    在VS2019中,"atlmfc"目录通常包含ATL和MFC相关的头文件和库文件,这些文件是构建和编译ATL项目的必要组成部分。通过使用这些源码和库,开发者可以充分利用ATL的功能,创建高效、轻量级的COM组件和服务。

    ATL开发指南 vc Atl编程

    2. **ATL项目结构**:了解如何创建一个基本的ATL项目,包括 ATL Simple Object Wizard 和 ATL Wizard 的使用。这些向导帮助开发者快速生成符合COM规范的项目框架。 3. **ATL COM类**:ATL提供了许多预定义的模板类...

    ATL简明教程 ( ATL.zip )

    这个ATL简明教程涵盖了ATL的基础知识和使用方法,旨在帮助开发者快速理解和应用ATL。 ATL是MFC(Microsoft Foundation Classes)的一个补充,它专注于COM编程,尤其在创建轻量级、高性能的COM服务器方面表现优越。...

    深入解析ATL(第2版) ATL internals 2nd Edition Working with ATL8

    ATL的发明人Jim Springfield亲自作序推荐 四位顶尖的Windows编程专家倾力合作,绝对经典再现 COM、ATL开发人员的必备宝典 深入分析ATL实现COM内幕细节,展示COM应用中的各类漂亮技巧 本书主要介绍了ATL技术的...

    ATL编程书籍-学习ATL的初学者必备。

    这本书籍对于想要深入理解ATL技术的初学者来说是一份宝贵的资源。ATL是C++编程中一个重要的工具,尤其在构建轻量级、高性能的COM对象时,它的优势尤为突出。 ATL编程的核心概念主要围绕以下几个方面: 1. **COM...

    ATL 2013 ,纯静态版本的ATL

    ATL+WTL,Windows平台仍然是一对锋利的组合。 主要特点: http://blogs.msdn.com/b/vcblog/archive/2013/08/20/atl-and-mfc-changes-and-fixes-in-visual-studio-2013.aspx One of the major changes we made was ...

    ATL介绍文档COM

    ATL本质上是对COM的一种封装和抽象,它通过提供一系列预定义的模板和工具,帮助开发者更轻松地构建符合COM规范的组件。相比于直接使用COM SDK或MFC,ATL具有以下优点: - **更轻量**:相比MFC,ATL生成的代码更少,...

    ATL入门核心资料

    本资料集合了ATL的入门级知识点,旨在帮助开发者快速理解和上手ATL技术。 1. ATL基础知识: - ATL的设计理念:ATL的目标是简化COM编程,通过模板和宏来减少代码量,提高开发效率。 - ATL与MFC(Microsoft ...

    深入解析ATL(第二版)

    8. ** ATL与WTL**:WTL(Windows Template Library)是基于ATL的一个轻量级UI框架,它扩展了ATL,提供了更多的Windows API封装,用于构建高效且小巧的应用程序。 9. ** ATL与音视频处理**:在音视频领域,ATL可以...

    ATL.chm.zip_ATL_ATL WTL_ATL chm_atl c_atl c++

    这个压缩包文件“ATL.chm.zip”包含了关于ATL的详细知识,特别是其内部结构图,对于深入理解和使用ATL进行组件开发极其有价值。 ATL是一种轻量级的库,它提供了一套模板类,使开发者能够更容易地创建高效、小巧的...

Global site tag (gtag.js) - Google Analytics