Click here to Skip to main content
14,981,532 members
Articles / Desktop Programming / ATL
Posted 12 Nov 2002


35 bookmarked

MSFlexGrid Control on an ATL Composite Control

Rate me:
Please Sign up or sign in to vote.
4.89/5 (6 votes)
27 Mar 2003CPOL2 min read
How To Use MSFlexGrid Control on an ATL Composite Control


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:


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:
    // Create Control
    void CreateObject()
      CComPtr<IUNKNOWN> pUnkCont;
      // Add CLSID of MSFlexGrid for Runtime license
      CComBSTR bstrLicKey = "72E67120-5959-11cf-91F6-C2863C385E30";
      HRESULT hr = CoGetClassObject(CLSID_MSFlexGrid,
       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,
      wnd.AttachControl(pUnk, &pUnkCont);
      m_VarGrid = pUnk;
     // Start event connection
  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)
        //Make sure the Event Handlers have __stdcall calling convention
  9. In Resource.h file add #define ID_GRID 201 or any ID which you like.
  10. Add Event Handler:
    VOID __stdcall Click_grid()
  11. You can also add a method to initialize gird i.e..
    void InitGrid()
        CString Cols[5]={"Name","Phone No","MailID"};
        for(int i = 0;i!=3;i++)
  12. In the OnInitDialog call CreateObject() function and InitGrid().
  13. Add a method to interface ie.
    STDMETHODIMP CAuthorVar::Stop()
            HRESULT hr= DispEventUnadvise(pUnk);//
        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


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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Uttam Kumar Unik!
Software Developer (Senior) Barclays Wealth
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

Generalcomposite Activex Pin
Nikkiee3-Dec-08 10:43
MemberNikkiee3-Dec-08 10:43 
GeneralRe: composite Activex Pin
Uttam Kumar Unik!3-Dec-08 22:51
MemberUttam Kumar Unik!3-Dec-08 22:51 
GeneralRe: composite Activex Pin
Nikkiee4-Dec-08 1:56
MemberNikkiee4-Dec-08 1:56 
GeneralRe: composite Activex Pin
Nikkiee4-Dec-08 2:02
MemberNikkiee4-Dec-08 2:02 
GeneralRe: composite Activex Pin
Uttam Kumar Unik!4-Dec-08 2:08
MemberUttam Kumar Unik!4-Dec-08 2:08 
GeneralRe: composite Activex Pin
Nikkiee4-Dec-08 2:41
MemberNikkiee4-Dec-08 2:41 
GeneralRe: composite Activex Pin
Uttam Kumar Unik!4-Dec-08 2:04
MemberUttam Kumar Unik!4-Dec-08 2:04 
GeneralRe: composite Activex [modified] Pin
Nikkiee4-Dec-08 2:25
MemberNikkiee4-Dec-08 2:25 
GeneralCrashes in release mode Pin
rahulagarwal3318-Feb-08 20:03
Memberrahulagarwal3318-Feb-08 20:03 
QuestionHow to handle ctrl/shift keys Pin
kirrik5-Mar-07 17:27
Memberkirrik5-Mar-07 17:27 
GeneralMS WEb Browser Control on a composite control. Pin
Shashikant_200611-May-06 23:31
MemberShashikant_200611-May-06 23:31 
GeneralCreate ActiveX Control using ATL Pin
rajesh_kapure15-Nov-05 0:26
Memberrajesh_kapure15-Nov-05 0:26 
GeneralRe: Create ActiveX Control using ATL Pin
Uttam Kumar Unik!15-Nov-05 0:54
MemberUttam Kumar Unik!15-Nov-05 0:54 
GeneralFlexGrid ATL Composite Control and Windows Server 2003 Pin
doris791-Jun-05 2:33
Memberdoris791-Jun-05 2:33 
GeneralEventIDs for MSFlexGrid control Pin
VKatti11-Feb-05 4:44
MemberVKatti11-Feb-05 4:44 
GeneralCreating a dialog in ATL composite control Pin
Member 52663013-Sep-04 3:46
MemberMember 52663013-Sep-04 3:46 
GeneralRe: Creating a dialog in ATL composite control Pin
Uttam Kumar Unik!13-Sep-04 8:03
MemberUttam Kumar Unik!13-Sep-04 8:03 
GeneralRe: Creating a dialog in ATL composite control Pin
Member 52663014-Sep-04 6:06
MemberMember 52663014-Sep-04 6:06 
GeneralComposite Control and Slider EDGE Pin
Balkrishna Talele22-Jul-04 19:49
MemberBalkrishna Talele22-Jul-04 19:49 
QuestionCode for CreateObject() ? Pin
1of318-Jun-04 20:53
Member1of318-Jun-04 20:53 
Generaluse of ms flex grid Pin
Anonymous22-Apr-04 5:55
MemberAnonymous22-Apr-04 5:55 
QuestionHow to use msflexgrid control w/ unicode? Pin
Anonymous13-Feb-04 23:41
MemberAnonymous13-Feb-04 23:41 
GeneralProblem with VS.Net 2003 Pin
raisch426-Feb-04 9:26
Memberraisch426-Feb-04 9:26 
GeneralPlease help in creating MappointControl on ATL Composite control Pin
bahubali1-May-03 12:46
Memberbahubali1-May-03 12:46 
GeneralZip file corrupted Pin
TW29-Mar-03 1:45
MemberTW29-Mar-03 1:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.