{"id":1543,"date":"2012-09-24T16:27:56","date_gmt":"2012-09-24T14:27:56","guid":{"rendered":"http:\/\/www.hjgode.de\/wp\/?p=1543"},"modified":"2012-11-15T11:31:36","modified_gmt":"2012-11-15T09:31:36","slug":"windows-mobile-disable-touch-input","status":"publish","type":"post","link":"https:\/\/www.hjgode.de\/wp\/2012\/09\/24\/windows-mobile-disable-touch-input\/","title":{"rendered":"Windows Mobile: disable touch input"},"content":{"rendered":"<p>Hello<\/p>\n<p>sometimes you might want to &#8216;lock&#8217; the screen, better say: disable touch input. For example, if you put the device in a pocket, to avoid accidentally tapped screen elements.<\/p>\n<p><!--more-->It took me a long time and deep searches and trials to find out, how that could be done. Beside there is a API function called DisableTouch, you need to reboot to re-enable touch screen input. The corresponding API EnableTouch() needs a function pointer as callback for touch input processing. How could you provide some?<\/p>\n<p>Fortunately I found TouchRegisterWindow and TouchUnregisterWindow. Although I do not know exactly what they are for and there is NO documentation to find anywhere. The only references I found was about transcriber input and at the TouchLockPro code.<\/p>\n<p>I managed to use the functions easily after some digging in the TouchLockPro (sourceforge project) code. TouchLockPro disables touch screen input by creating a window of zero size and registering this with TouchRegisterWindow. The WndProc of this zero size window does nothing and the screen is &#8216;blocked&#8217; for touch input.<\/p>\n<p>But there is an easier use: you can just register the desktop window handle of Windows Mobile. If you use it with TouchRegisterWindow(), the touch input is no more forwarded to the mobile screen elements. To &#8216;unlock&#8217; touch screen input, you just have to call TouchUnregisterWindow() with the handle of the desktop window (GetDesktopWindow()).<\/p>\n<p>Looking thru the window list with CE remote Spy you will see two Desktop windows:<\/p>\n<p><a href=\"http:\/\/www.hjgode.de\/wp\/2012\/09\/24\/windows-mobile-disable-touch-input\/desktop-window\/\" rel=\"attachment wp-att-1544\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1544\" title=\"desktop-window\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window-277x300.gif\" alt=\"\" width=\"277\" height=\"300\" srcset=\"https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window-277x300.gif 277w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window-138x150.gif 138w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window.gif 317w\" sizes=\"(max-width: 277px) 100vw, 277px\" \/><\/a>\u00a0\u00a0\u00a0 <a href=\"http:\/\/www.hjgode.de\/wp\/2012\/09\/24\/windows-mobile-disable-touch-input\/desktop-window2\/\" rel=\"attachment wp-att-1545\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1545\" title=\"desktop-window2\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window2-277x300.gif\" alt=\"\" width=\"277\" height=\"300\" srcset=\"https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window2-277x300.gif 277w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window2-138x150.gif 138w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/09\/desktop-window2.gif 317w\" sizes=\"(max-width: 277px) 100vw, 277px\" \/><\/a><\/p>\n<p>GetDesktopWindow() will return the non-zero one.<\/p>\n<p>Now, you know an easy way to lock and unlock the touch screen input.<\/p>\n<p>If you are coding a kiosk mode app, it may be easier to just code some &#8216;ignore input&#8217; function without using TouchRegisterWindow and TouchUnregisterWindow of touch.dll.<\/p>\n<p>BTW: you should use these two functions dynamically.<\/p>\n<p>As some have problems implementing a disableTouch, here is my code:<\/p>\n<pre>\/\/ disabletouch1.cpp : Defines the entry point for the console application.\r\n\/\/\r\n\r\n#include \"stdafx.h\"\r\n\r\n#include \"hooks.h\"\r\n\r\nint _tmain(int argc, _TCHAR* argv[])\r\n{\r\n\u00a0\u00a0 \u00a0if(argc==2){\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0InitializeTouchDll();\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0HWND hwnd = GetDesktopWindow();\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0DEBUGMSG(1,(L\"GetDesktopWindow() = 0x%08x\", hwnd));\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0long lCmd;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0lCmd = _wtol(argv[1]);\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if(lCmd==1){\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/disable touch\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0DEBUGMSG(1, (L\"+++ TouchRegisterWindow called\\n\"));\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return m_fpTouchRegisterWindow(hwnd);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0else if (lCmd==0){\u00a0\u00a0 \u00a0\/\/enable touch\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0SetLastError(0);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0DEBUGMSG(1, (L\"--- TouchUnregisterWindow called\\n\"));\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_fpTouchUnregisterWindow(hwnd);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return GetLastError();\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0else\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return -2;\/\/wrong arg\r\n\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0else\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return -1; \/\/no args no fun\r\n\u00a0\u00a0 \u00a0return 0;\r\n}<\/pre>\n<p>with the first function call being:<\/p>\n<pre>HMODULE\u00a0\u00a0 \u00a0m_TouchDLL;\r\nTouchRegisterWindow_t\u00a0\u00a0 \u00a0m_fpTouchRegisterWindow;\r\nTouchUnregisterWindow_t\u00a0\u00a0 \u00a0m_fpTouchUnregisterWindow;\r\n...\r\nbool InitializeTouchDll() {\r\n\u00a0\u00a0\u00a0 LOGDEBUG(L\"InitializeTouchDll()\");\r\n\u00a0\u00a0 \u00a0if (m_TouchDLL == NULL) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_TouchDLL = LoadLibrary(L\"touch.dll\");\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if(m_TouchDLL != NULL) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_fpTouchPanelPowerHandler = (TouchPanelPowerHandler_t)GetProcAddress(m_TouchDLL, L\"TouchPanelPowerHandler\");\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_fpTouchRegisterWindow = (TouchRegisterWindow_t)GetProcAddress(m_TouchDLL, _T(\"TouchRegisterWindow\"));\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_fpTouchUnregisterWindow = (TouchUnregisterWindow_t)GetProcAddress(m_TouchDLL, _T(\"TouchUnregisterWindow\"));\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if ((m_fpTouchPanelPowerHandler != NULL) &amp;&amp; (m_fpTouchRegisterWindow != NULL) &amp;&amp; (m_fpTouchUnregisterWindow != NULL)) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return true; \/\/ everything Ok\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0} else {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0LOGERROR(L\"Error in initializing Touch dll\");\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return false;\r\n\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0LOGERROR(L\"Error in finding Touch dll register\/unregister functions\");\r\n\u00a0\u00a0 \u00a0return false; \/\/ something wrong\r\n}<\/pre>\n<p>That is all you need.<\/p>\n<p>Download C source code and VS2008 project file<br \/>\n[Download not found]<\/p>\n<p>Download C source code of DLL to be used from C# or so (just use the exported disableTouch(bool bEnable) function with true or false):<br \/>\n[Download not found]<\/p>\n<p>A set of source code is available at\u00a0http:\/\/code.google.com\/p\/win-mobile-code\/source\/browse\/#svn%2Ftrunk%2FdisableTouch<\/p>\n<p>There are\u00a0 windows, command line, DLL and CSharp example codes.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello sometimes you might want to &#8216;lock&#8217; the screen, better say: disable touch input. For example, if you put the device in a pocket, to avoid accidentally tapped screen elements.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178,6,3],"tags":[539,534,463,15],"class_list":["post-1543","post","type-post","status-publish","format-standard","hentry","category-codeproject","category-kiosk-mode","category-programming","tag-codeproject","tag-kiosk-mode","tag-touchregisterwindow","tag-windows-mobile"],"_links":{"self":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts\/1543"}],"collection":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/comments?post=1543"}],"version-history":[{"count":6,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts\/1543\/revisions"}],"predecessor-version":[{"id":1623,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts\/1543\/revisions\/1623"}],"wp:attachment":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/media?parent=1543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/categories?post=1543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/tags?post=1543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}