특정 윈도우에서 타블렛, 터치 롱프레스 끄기(Disabling Press and Hold in Applications Written for Tablet PC)
Language/C# 2010. 5. 21. 14:18
타블렛이나 터치스크린을 사용하면 마우스의 오른쪽버튼 기능을 위해서 롱프레스 기능을 제공합니다.
그러나 가끔은 자신만의 롱프레스 기능 구현을 위해서 이런 기본 기능을 꺼야 하는 경우가 있는데 이럴 때 아래 코드를 사용하면 됩니다.
사용법은 단순히 함수 호출하면서 롱프레스 기능을 끄고 싶은 폼(윈도우, 컨트롤)의 핸들을 첫번째 매개변수로 주고, 두번째 매개변수에 false를 주면 됩니다.(반대로 다시 켜고 싶으면 true를 주면 됩니다.)
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern ushort GlobalAddAtom(string lpString);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetProp(IntPtr hWnd, string lpString, IntPtr hData);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr RemoveProp(IntPtr hWnd, string lpString);
bool TogglePressAndHold(IntPtr hWnd, bool enable)
{
ushort atomID = 0;
string tabletAtom = "MicrosoftTabletPenServiceProperty";
atomID = GlobalAddAtom(tabletAtom);
if (atomID == 0)
{
return false;
}
if (enable)
{
IntPtr ptr = RemoveProp(hWnd, tabletAtom);
if (ptr != null)
return true;
}
else
{
return SetProp(hWnd, tabletAtom, new IntPtr(1));
}
return false;
}
위의 코드는 MSDN에 잇는 코드를 단순히 C#으로 컨버팅한 것입니다. 자세한 정보와 C++, VB 코드는 아래 MSDN을 참고하세요~
(http://msdn.microsoft.com/en-us/library/ms812373.aspx)
첨부파일은 위의 코드를 이용한 샘플 프로그램의 소스이고 그 실행 화면은 아래와 같습니다.
(체크박스의 체크여부에 따라서 폼 위에서 롱프레스 가능 여부가 결정됩니다.)
(사용언어 / 제작툴 / .Net Framework버전 : C# / VS2010 / 2.0)