XRCustomUserControlImpl<Base,IFace> (Compact 2013)

3/28/2014

This class implements the IXRCustomUserControlinterface and is the base class for classes that implement custom user controls.


template<typename Base,typename IFace = IXRCustomUserControl>
class XRCustomUserControlImpl : public XRControlThunk<IFace>

Base

Base class that implements the IFace interface. Inherits from XRCustomUserControlImpl.

IFace

[optional] Custom user-control interface that inherits from IXRCustomUserControl.

Method

Description

XRCustomUserControlImpl::ControlID

Retrieves an integer value that represents the ID of a custom user control.

XRCustomUserControlImpl::OnLoaded

The last step in preparing a custom user control for use. You can override this method to get child objects and set up delegates.

XRCustomUserControlImpl::Register

Registers a custom user control with XAML for Windows Embedded.

Members of this class are thread-safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

This class implements IUnknown and provides wrapper implementations of the methods in IXRCustomUserControl. This includes the methods that IXRCustomUserControl inherits from the following classes:

These wrapper methods pass any call to the corresponding method in the Derived class, as shown in the following example.

Ee502483.note(en-us,WinEmbedded.80).gifImportant:
For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.
virtual HRESULT STDMETHODCALLTYPE HitTest(
  __in XRRect *pRect,
  __out IXRHitTestResults** ppElements
  )
  {  
    // m_pCustomUserControlBase points to the Derived class.
    if (m_pCustomUserControlBase == NULL)
    {
      return E_FAIL;
    }
    return m_pCustomUserControlBase->HitTest(pRect, ppElements);
  }

The following code example declares both a custom user control interface and an implementation class based on the XRCustomUserControlImpl class.

Ee502483.note(en-us,WinEmbedded.80).gifImportant:
For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.
// Define a GUID for the new interface.
DEFINE_XR_IID(IMyCustomControl, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");

// Create the interface with any custom methods needed.
class IMyCustomControl: public IXRCustomUserControl
{
public:
    virtual HRESULT DoSomething() = 0;
};

// Create the implementing class 
class __declspec(uuid("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"))
  MyCustomControl:public XRCustomUserControlImpl<
    MyCustomControl, 
    IMyCustomControl
    >
{
Public:
  // Override XRCustomUserControlImpl::OnLoaded
  // to get child objects and set up delegates
  HRESULT OnLoaded(__in IXRDependencyObject *pRoot);

  static HRESULT GetXamlSource(__in XRXamlSource* pXamlSource)
  {
    pXamlSource->SetResource(
      g_hInstance,
      RT_XAML,
      MAKEINTRESOURCE(ID_MYCUSTOMCONTROL_XAML
      ));
    return S_OK;
  }

  static HRESULT Register()
  {
    return XRCustomUserControlImpl::Register(
      __uuidof(MyCustomControl),
      L"MyCustomControl",
      L"clr-namespace:MyCustomNamespace"
      );

    //Register any dependency properties.
  }

HRESULT DoSomething()
  {
    // Do something here.
  }
};

Header

xrcustomcontrol.h

sysgen

SYSGEN_XAML_RUNTIME

Show: