Enabling drag events in Symbian C++ on touch-enabled devices

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 5th Edition
Keywords: CCoeControl::EnableDragEvents()
Created: tepaa (03 Oct 2008)
Last edited: hamishwillee (14 Jun 2012)



S60 5th Edition supports touch events. All AVKON UI controls handle touch UI events and you do not need to implement anything new.

If you want to listen for drag events in your custom CCoeControl UI control, use CCoeControl::EnableDragEvents().

MMP file

The following libraries are required:

LIBRARY cone.lib

Header file

void ConstructL(const TRect& aRect);
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
void Move(const TPoint& aPoint);
TPoint iMovePoint;

Source file

Enable drag event listening in the container control ConstructL().

EnableDragEvents() needs to be called only once in the entire application.
void CMyControl::ConstructL(const TRect& /*aRect*/)
// Create window of this container control
// Enable drag events listening
// ...

Drag events are received.

void CMyControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
iMovePoint = aPointerEvent.iPosition;
else if (aPointerEvent.iType == TPointerEvent::EDrag)
// Drag events received, what to do with it?
// We could move this control...
// Store current point
iMovePoint = aPointerEvent.iPosition;
// Draw this control again because we move to position of it
// ...

Moving control to dragging point:

void CMyControl::Move(const TPoint& aPoint)
TPoint offset;
// Calculate moving offset
offset.iX = aPoint.iX - iMovePoint.iX;
offset.iY = aPoint.iY - iMovePoint.iY;
TRect rect = Rect();
// Move this control


Drag events are received and control is moved to the pointer location.

See also

S60 5th Edition: Solitaire Game Example

S60 Platform: Image Converter Example

Handling pointer events in Symbian C++

CS001145 - Pointer capturing in touch-enabled devices

This page was last modified on 14 June 2012, at 02:10.
64 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.