Click to See Complete Forum and Search --> : [RESOLVED] Touch Enable / Disable Script.


xnederlandx
January 20th, 2010, 09:41 PM
Hello,

I'm new to this forum.
I don't have much experience writing programs for the computer, but I know how to do some fairly simple stuff. I do write code for microprocessors (PICs). I do not have a visual basic compiler on any computer.

I want to make a program that turns on/off the "Use your finger as an input device" checkbox in the control panel. Currently, I'm doing it by opening the .cpl file and sending some keystrokes to it with vbs, to change the settings. This works fine, but you see the dialogue box come up.

I've originally tried to do this by changing the following registry entries:
"HKEY_CURRENT_USER\Software\Microsoft\Wisp\Touch\TouchGate"
- DWORD, 1 = Touch Enabled, 0 =Touch Disabled

"HKEY_CURRENT_USER\Software\Microsoft\Wisp\MultiTouch"
- DWORD, 1 = Multi-Touch Gestures Enabled, 0 =Multi-Touch Gestures Disabled

And then refreshing explorer.exe by killing it and then starting it. The only problem is that the Notification Area Icons then have problems, and won't re-appear.

I've read some things on this forum, and it appears that people are using "WM_SETTINGCHANGE" message to update explorer.exe.
Will this work? Is there a better alternative? How do I implement it? Do I have to download a vb6.0 compiler? Or can I use vbs?

See this thread here:
http://www.gottabemobile.com/forum/dell/7777-touch-enable-disable-script.html

Thanks in advance for any responses.

xnederlandx
January 21st, 2010, 04:21 PM
Please Move this thread to the Visual Basic.NET forum.


I have just install Microsoft Visual Basic Express Edition 2008.

This is what I have:

Public Class Form1
Private Const HWND_BROADCAST = &HFFFF
Private Const WM_SETTINGCHANGE = &H1A

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Object)
Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Int32, ByVal msg As Int32, ByVal wParam As Int32, ByVal lParam As String, ByVal fuFlags As Int32, ByVal uTimeout As Int32, ByVal lpdwResult As Int32) As Int32

Private Sub Touch_ON_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Touch_ON_Button.Click
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)
End Sub
End Class

I'm not sure what I'm doing wrong here. I'm geting a

A first chance exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in WindowsApplication1.exe

error.

Cimperiali
January 21st, 2010, 07:39 PM
try declaring sendmessage in one of these way:
(for more details see:
http://pinvoke.net/default.aspx/user32.SendMessage )


Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

or

Declare Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer,
ByVal wParam As IntPtr, ByRef lParam As StringBuilder) As IntPtr

or

Declare Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer,
ByVal wParam As IntPtr, ByRef RECT As IntPtr) As IntPtr

or

Declare Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer,
ByVal wParam As IntPtr, ByRef POINT As IntPtr) As IntPtr

xnederlandx
January 21st, 2010, 09:13 PM
Thankyou very much for the quick response.

I will try that now.

Thanks again.

Edit: The results are:

Way 1 (the first one you mentioned):
- No Visual Basic Debugger error, but application crashes.

Way 2
- "Stringbuilder" invalid.

Way 3
- Error: Unable to find an entry point named 'SendMessage' in DLL 'user32.dll'.

Way 4
- Error: Unable to find an entry point named 'SendMessage' in DLL 'user32.dll'.


From this I am assuming that Way 1 is correct, except I'm using the SendMessage function insted of the SendMessageTimeout.

xnederlandx
January 21st, 2010, 09:57 PM
I think this is way overcomplicating things.

Does anyone know a place where I can download an .exe which will refresh explorer (without killing it and restarting it). I think that would be simplest...

I've done a google search, but that returned nothing.

HanneSThEGreaT
January 22nd, 2010, 06:51 AM
SendMessageTimeOut is the appropriate API to use here, try this :

Declare Auto Function SendMessageTimeout Lib "User32" ( _
ByVal hWnd As Integer, _
ByVal Msg As UInt32, _
ByVal wParam As Integer, _
ByVal lParam As Integer, _
ByVal fuFlags As UInt32, _
ByVal uTimeout As UInt32, _
ByRef lpdwResult As IntPtr _
) As Long

Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_SETTINGCHANGE = &H1A
Private Const SMTO_ABORTIFHUNG = &H2

Public Sub EnvRefresh()
Dim dwResult As IntPtr '
SendMessageTimeout(HWND_BROADCAST, _
Convert.ToUInt32(WM_SETTINGCHANGE), _
0, 0, _
Convert.ToUInt32(SMTO_ABORTIFHUNG), _
Convert.ToUInt32(2000), _
dwResult)
End Sub

Private Sub Touch_ON_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Touch_ON_Button.Click
EnvRefresh()
End Sub

xnederlandx
January 22nd, 2010, 10:50 PM
It appears to be working.

Just tested it on my Windows 7 64-bit, and I can see explorer.exe pinging the processor for a moment when I push the button.


Thankyou very much for your assistance.

HanneSThEGreaT
January 23rd, 2010, 01:01 AM
That is great news!

Good work! :thumb:

Please just remember when your thread is answered and solved, to mark it as Resolved, as outlined here :

http://www.codeguru.com/forum/showthread.php?t=403073

xnederlandx
January 23rd, 2010, 02:13 AM
Done.

Thankyou very much for your assistance.

Credit has been given to you, HanneSThEGreaT, and Cimperiali.
See here:

http://www.gottabemobile.com/forum/dell/7777-touch-enable-disable-script-2.html#post54412