How to use the Real-time stylus


The Real-Time Stylus (RTS) is a Tablet PC SDK feature that simplifies customized rendering of Stylus output, enables access to powerful hardware-level information for strokes and points, and grants access to ink-related events.  The RTS works by using plug-ins that are added to via an interface that enables you to customize how the SDK is interpreting and using pen input.


 


 


Part 1:  Setting up the Project


You will be creating a simple project that just has a just a dialog and an InkPicture control.  This is described in previous blog entries here.


 


 


Part 2:  A Very Simple Example Using the Dynamic Renderer RTS plug-in


The following code demonstrates a simple way to use the Dynamic renderer plug-in, provided by Microsoft, to have a higher level of control over ink-based controls.  At this point, you shouldI have created a pretty straightforward project that has a dialog with only an InkPicture control in it.  The real-time stylus interface is attached to the ink control and then the ink control relinquishes various aspects of ink rendering and so on to the plug-ins that are then added to the real-time stylus.


 


First, you will need to declare pointers for the Real-time stylus interface and a rendering plug-in.


// Some global COM interface pointers


CComPtr<IRealTimeStylus> g_pRealTimeStylus;


CComPtr<IDynamicRenderer> g_pDynamicRenderer;


CWnd* g_hInkArea;


 


After that you will need to attach the stylus to the ink control.


(inside of InitDialog)


    g_hInkArea = this->GetDlgItem(IDC_INKPICTURE);


    // TODO: Add extra initialization here


    // Create the IRealTimeStylus object


    HRESULT hr = g_pRealTimeStylus.CoCreateInstance(CLSID_RealTimeStylus);


 


    if (SUCCEEDED(hr))


    {


        // This both sets the m_gbRTSArea member to the


        hr = g_pRealTimeStylus->put_HWND(


          reinterpret_cast<HANDLE_PTR>(g_hInkArea->m_hWnd)


        );


    }


    if (SUCCEEDED(hr))


    {


        // This both sets the m_gbRTSArea member to the


        hr = g_pRealTimeStylus->put_Enabled(TRUE);


    }


 


Finally, you will need to add a plug-in to the real-time stylus control and you will be good to go.


    if (SUCCEEDED(hr))


    {


        // Create an IDynamicRenderer object to demonstrate RTS plug-ins


        hr = g_pDynamicRenderer.CoCreateInstance(CLSID_DynamicRenderer);


    }


    if (SUCCEEDED(hr))


    {


        // Retrieve the sync version of the dynamic renderer plug-in


        CComPtr<IStylusSyncPlugin> spSyncPlugin;


        hr = g_pDynamicRenderer.QueryInterface(&spSyncPlugin);


    }


    if (SUCCEEDED(hr))


    {


        // relenquish control of the HWND to the real-time stylus


        hr = g_pDynamicRenderer->put_HWND(


          reinterpret_cast<HANDLE_PTR>(g_hInkArea->m_hWnd)


        );


    }


    if (SUCCEEDED(hr))


    {


        // Add to the plug-in collection


        g_pRealTimeStylus->AddStylusSyncPlugin(0, spSyncPlugin);


    }


    if (SUCCEEDED(hr))


    {


        // Enable the plug-in


        hr = g_pDynamicRenderer->put_Enabled(TRUE);


    }


 


Conclusion


So there you have it, in summary to use the RTS, all you need to do is create the interfaces, attach them to an Ink Overlay or a control that uses an Ink Overlay, and then add the plugins that you want.

Skip to main content