Sunday, August 03, 2008

The Touch List - II

I finally have some time to come back and write about the Touch List window. It's been quite some time since I wrote the first post about this code, and it has changed a lot (especially because I had to use it for a customer project), and I have also learned a lot about how to make this code work on both Windows Mobile and Windows CE devices.

Code Changes
The first challenge I had to face was to decouple the "kinetics" from the list and implement it in a more general WTL base class. This was a project requirement for one of the data windows where a bitmap is displayed and the same auto scrolling behavior was sought.

The second challenge was to implement some sort of scroll bar into the window. I could use the native Windows scroll bars but I decided to use something nicer and possibly "cooler".

All the "touch" code was put into one single header file pompously named atltouch.h (see the sample code here). This header file contains the following classes:
  • CScrollBarData - Contains scroll bar data (either horizontal or vertical) and associated calculations.
  • CTouchWindow - The "touch" base class, where you will find all generic "kinetics" functions.
  • CTouchListItem - Base class for touch list items. Implement one for your items (see sample code).
  • CTouchList - The touch list class template.
Please understand that this code is still very much under construction so you will see some redundant concepts and the occasional bug.

Finger Use
Most of the current devices are not ready for finger input, only for stylus input. Sure you can use your finger but I have found that on some devices, when you put your index finger to the screen, the application window receives the expected WM_LBUTTONDOWN, but may also receive a lot of WM_MOUSEMOVE messages... Why is this? Your finger is way larger than the expected stylus tip so you are effectively touching more than one screen point. What I have experienced is that most devices will produce the mouse move messages and your list will start scrolling just by touching it with your finger. This is less likely to happen when using the stylus.

The solution for this was to implement a "sensitivity" factor that will ignore movements within a given range (see the SetSensitivity method). If you use this with any value larger than 1 (in either direction) your list will become less sensitive, but you will have to adjust this value to your device...

Scroll Bars
Scroll bars have an unusual implementation, but I hope you find them useful (if not, suggestions
are mostly welcome). To use the vertical scroll bar, just drag your finger (or stylus) up or down and the list will scroll accordingly.

On Windows Mobile 5 and 6 devices, these are implemented as a transparent layer on top of your list so you can use the full screen size to display data.


zzattack said...

Very nice, I'll try it out now.
If you haven't already, take a look at this codeproject article: :)
I've been using that for some time now but there are still some issues with it. I hope I'll manage to use this in a managed context as well.

João Paulo Figueira said...

Looks like an interesting article and will definitely look at it for ideas. My plan is to write a native-only version of this but i don't exclude writing a managed one...

vincent said...


it seems your link to sample code is broken.


João Paulo Figueira said...

Looks like my host (Yahoo!) is doing a bad job, again! Please retry later.

zzattack said...

Hi again, I tried running this program once more. At first there were no entries in the list, but when I ran it today my address book entries were there. The software works amazingly well, the effect is really smooth, nothing like my own .NET implementation! Do you think this could be used in a managed context at all?

João Paulo Figueira said...

It is possible to host a native control in a managed application. I would say that this code is still a bit far from that, but I promise to get back to this very soon (as soon as the OLE DB Client library becomes usable).