Brian Frost
Brian Frost

Reputation: 13454

What is the best practice for detecting touch capability (tablet PC) in a Delphi app for Windows?

My app runs on a desktop PC and / or a tablet PC. For the latter though, I see that I have to provide an on-screen keyboard - this is not hard with the supplied TTouchKeyboard. My question is how to find out whether touch is available or not? I have found some sample code which makes WinAPi calls to GetSystemMetrics:

function GetTouchCapabilities : TTouchCapabilities;
 var ADigitizer : integer;
 begin
 result := [];
 // First check if the system is a TabletPC
 if GetSystemMetrics(SM_TABLETPC) <> 0 then begin
   include(result,tcTabletPC);
   if CheckWin32Version(6,1) then begin // If Windows 7, then we can do additional tests on input type
    ADigitizer := GetSystemMetrics(SM_DIGITIZER);
    if ((ADigitizer and NID_INTEGRATED_TOUCH) <> 0) then include(result,tcIntTouch);
    if ((ADigitizer and NID_EXTERNAL_TOUCH) <> 0) then include(result,tcExtTouch);
    if ((ADigitizer and NID_INTEGRATED_PEN) <> 0) then include(result,tcIntPen);
    if ((ADigitizer and NID_EXTERNAL_PEN) <> 0) then include(result,tcExtPen);
    if ((ADigitizer and NID_MULTI_INPUT) <> 0) then include(result,tcMultiTouch);
    if ((ADigitizer and NID_READY) <> 0) then include(result,tcReady);
   end else begin
    // If not Windows7 and TabletPC detected, we asume that it's ready
    include(result,tcReady);
   end;
 end;
 end;

There is also the Microsoft definition of a tablet PC here.

I then did a search of the RTL and Delphi source to try to locate routines that more directly gave me this information in a similar way to how Delphi wraps the OS version information but I can't see any (although it may be that I just don't know what to search for!). Is the above code style the best way of detecting touch capability? Or am I missing something much more obvious?

Upvotes: 4

Views: 2217

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596833

AFAIK, Delphi does not provide a wrapper for reporting Tablet PC capabilities, so what you have shown is what you will need to use in your code.

Upvotes: 2

Related Questions