Type | Description | |||
IUnboundHandler | An object that implements IUnboundHandler notification interface. |
The control supports unbound mode. In unbound mode, user is responsible for retrieving items. In order to let the control works in unbound mode, the user has to implement the IUnboundHandler notification interface.
The following VB sample shows how to activate the control's unbound mode:
Option Explicit Dim its As Items Implements IUnboundHandler ' The ExComboBox invokes ItemsCount property, when the UnboundHandler property is called. Private Property Get IUnboundHandler_ItemsCount(ByVal Source As Object) As Long IUnboundHandler_ItemsCount = 50000 End Property ' The ExComboBox invokes ReadItem method when the Item ( ItemHandle, Index ) is required. Private Sub IUnboundHandler_ReadItem(ByVal Index As Long, ByVal Source As Object, ByVal ItemHandle As Long) its.CellCaption(ItemHandle, 0) = Index its.CellImage(ItemHandle, 0) = Index Mod 3 + 1 its.CellHasCheckBox(ItemHandle, 0) = True ' Each 8th item has a different font attribute If (Index Mod 8) = 7 Then its.CellStrikeOut(ItemHandle, 0) = True End If End Sub
Private Sub Form_Load() With ComboBox1 .BeginUpdate ' Initializes few control properties .ColumnAutoResize = True .SingleEdit = True .MarkSearchColumn = False .HeaderVisible = False ' Holds the Items object into a variable, to avoid calling ' Items property every time when ReadItem handler is invoked. ' Internally, the Items property invokes a QueryInterface method that can slow app's speed. Set its = .Items .Columns.Add "1" ' Sets the control's unbound handler. The Form implements the IUnboundHandler interface Set .UnboundHandler = Me .EndUpdate End With End Sub
The following VC sample shows how to activate the control's unbound mode. The sample requires a combo control into your dialog, and needs a new member variable associated to the control. ( in this case the MFC class wizard will generate for you a class wrapper ).
m_exCombo.BeginUpdate(); m_exCombo.SetColumnAutoResize( TRUE ); m_exCombo.SetSingleEdit( TRUE ); m_exCombo.SetHeaderVisible( FALSE ); m_exCombo.GetColumns().Add( "1" ); m_exCombo.SetUnboundHandler( &m_unboundHandler.m_xHandler ); m_exCombo.EndUpdate();
The m_unboundHandler is an object of CUnboundHandler type.
Here's the definition for CUnboundHandler class:
/************************************ REVISION LOG ENTRY Revision By: Exontrol Revised on 4/14/2002 12:44:39 PM Comments: Implements IUnboundHandler interface This code may be used in compiled form in any way you desire. This file may not be redistributed modified or unmodified without the authors written consent. ************************************/ #if !defined(_UNBOUNDHANDLER_) #define _UNBOUNDHANDLER_ // The IUnboundHandler interface is not included by class wizard so, we need to import it from the control's type library #import "c:\winnt\system32\excombobox.dll" rename( "GetItems", "exGetItems" ) class CUnboundHandler : public CCmdTarget { public: CUnboundHandler(); virtual ~CUnboundHandler(); DECLARE_INTERFACE_MAP() public: BEGIN_INTERFACE_PART(Handler, EXCOMBOBOXLib::IUnboundHandler) STDMETHOD(get_ItemsCount)(IDispatch * Source, long* pVal); STDMETHOD(raw_ReadItem)(long Index, IDispatch * Source, long ItemHandle); END_INTERFACE_PART(Handler) #ifdef _USESMARTSOURCE EXCOMBOBOXLib::IComboBoxPtr m_spComboBox; EXCOMBOBOXLib::IItemsPtr m_spItems; #endif //_USESMARTSOURCE }; #endif // !defined(_UNBOUNDHANDLER_)
Here's the implementation for CUnboundHandler class:
/************************************ REVISION LOG ENTRY Revision By: Exontrol Revised on 4/14/2002 12:44:39 PM Comments: Implements IUnboundHandler interface This code may be used in compiled form in any way you desire. This file may not be redistributed modified or unmodified without the authors written consent. ************************************/ #include "stdafx.h" #include "UnboundHandler.h" ///////////////////////////////////////////////////////////////////////////// // class CUnboundHandler ///////////////////////////////////////////////////////////////////////////// BEGIN_INTERFACE_MAP(CUnboundHandler, CCmdTarget) INTERFACE_PART(CUnboundHandler, __uuidof(EXCOMBOBOXLib::IUnboundHandler), Handler) END_INTERFACE_MAP() // Function name : CUnboundHandler::CUnboundHandler // Description : Default constrcutor // Return type : CUnboundHandler::CUnboundHandler() { } // Function name : CUnboundHandler::~CUnboundHandler // Description : Virtual destructor // Return type : CUnboundHandler::~CUnboundHandler() { } // Function name : CUnboundHandler::Handler::get_ItemsCount // Description : Gets the items count // Return type : STDMETHODIMP // Argument : long* pVal STDMETHODIMP CUnboundHandler::XHandler::get_ItemsCount(IDispatch * Source, long* pVal) { METHOD_PROLOGUE(CUnboundHandler, Handler); if ( pVal ) { *pVal = 150000; return S_OK;; } return E_POINTER; } // Function name : CUnboundHandler::XHandler::raw_ReadItem // Description : Reads the item // Return type : STDMETHODIMP // Argument : long Index // Argument : IDispatch * Source // Argument : long ItemHandle STDMETHODIMP CUnboundHandler::XHandler::raw_ReadItem(long Index, IDispatch * Source, long ItemHandle) { METHOD_PROLOGUE(CUnboundHandler, Handler); #ifndef _USESMARTSOURCE // The Source points to a ComboBox object. EXCOMBOBOXLib::IItemsPtr spItems = NULL; EXCOMBOBOXLib::IComboBoxPtr spCombo = NULL; if ( SUCCEEDED( Source->QueryInterface( &spCombo ) ) ) if ( SUCCEEDED( spCombo->get_Items( &spItems ) ) ) { _variant_t vtHandle(ItemHandle), vtColumn( (long)0 ) ; TCHAR szCaption[1024] = _T(""); wsprintf( szCaption, _T("%i"), Index ); spItems->CellCaption[vtHandle][vtColumn] = _variant_t(szCaption); } #else // To avoid calling QueryInterface and get_Items every time when an item is reading, // you can hold two smart pointers in the parent class ( CUnboundHandler ) like this: // // public: EXCOMBOBOXLib::IComboBoxPtr m_spComboBox; // public: EXCOMBOBOXLib::IItemsPtr m_spItems; // // You need to initalize the m_spComboBox, and m_spItems before calling SetUnboundHandler, like this: // m_unboundHandler.m_spComboBox = m_exCombo.GetControlUnknown(); // m_unboundHandler.m_spItems = m_exCombo.GetItems().m_lpDispatch; // m_exCombo.SetUnboundHandler( &m_unboundHandler.m_xHandler ); _variant_t vtHandle(ItemHandle), vtColumn( (long)0 ) ; TCHAR szCaption[1024] = _T(""); wsprintf( szCaption, _T("%i"), Index ); pThis->m_spItems->CellCaption[vtHandle][vtColumn] = _variant_t(szCaption); #endif return S_OK; } // Function name : CUnboundHandler::XHandler::QueryInterface // Description : Implements the IUnknown::QueryInterface method // Return type : STDMETHODIMP // Argument : REFIID riid // Argument : void** ppvObject STDMETHODIMP CUnboundHandler::XHandler::QueryInterface( REFIID riid, void** ppvObject) { METHOD_PROLOGUE(CUnboundHandler, Handler); if ( ppvObject ) { if ( IsEqualIID( __uuidof(IUnknown), riid ) ) { *ppvObject = static_cast<IUnknown*>( this ); AddRef(); return S_OK; } if ( IsEqualIID( __uuidof( EXCOMBOBOXLib::IUnboundHandler), riid ) ) { *ppvObject = static_cast<EXCOMBOBOXLib::IUnboundHandler*>( this ); AddRef(); return S_OK; } return E_NOINTERFACE; } return E_POINTER; } // Function name : CUnboundHandler::XHandler::AddRef // Description : Implements the IUnknown::AddRef property // Return type : STDMETHODIMP // Argument : REFIID riid // Argument : void** ppvObject STDMETHODIMP_(ULONG) CUnboundHandler::XHandler::AddRef() { METHOD_PROLOGUE(CUnboundHandler, Handler); return 1; } // Function name : CUnboundHandler::XHandler::QueryInterface // Description : Implements IUnkown:: Release property // Return type : // Argument : ULONG STDMETHODIMP_(ULONG) CUnboundHandler::XHandler::Release() { METHOD_PROLOGUE(CUnboundHandler, Handler); return 0; }