我想在窗口 8 中禁用触摸屏,但更改注册表时遇到了一些问题。
更改注册表后,我必须重新启动计算机。如果不重新启动计算机,我无法禁用触摸屏。但我希望在不重新启动计算机的情况下禁用触摸屏。这是我的代码:
int EnableTouchScreen(bool enable)
{
EnableMulTouch(enable);
EnableTouch(enable);
DWORD dwRet = 0;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, NULL, NULL, SMTO_NORMAL,1,&dwRet);
return 0;
}
int EnableMulTouch(bool enable)
{
HKEY hkey;
LONG lResult;
DWORD dwtype;
if(IsWin64())
{
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Wisp\\MultiTouch\\"), 0, KEY_WOW64_64KEY | KEY_ALL_ACCESS |KEY_WRITE, &hkey);
}
else
{
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Wisp\\MultiTouch\\"), 0, KEY_WOW64_32KEY | KEY_ALL_ACCESS |KEY_WRITE, &hkey);
}
if (lResult == ERROR_SUCCESS)
{
DWORD value = 0;
if(enable)
{
value = 1;
lResult = RegSetValueEx(hkey, _T("MultiTouchEnabled"), 0, REG_DWORD, (PBYTE)&value, sizeof(DWORD));
}
else
{
value = 0;
lResult = RegSetValueEx(hkey, _T("MultiTouchEnabled"), 0, REG_DWORD, (PBYTE)&value, sizeof(DWORD));
}
if (lResult != ERROR_SUCCESS)
{
char strErr[256];
sprintf(strErr, "SetMulTouch --- GetLastError(): %u\n", GetLastError() );
OutputDebugStringA(strErr);
return FALSE;
}
RegCloseKey(hkey);
}
return 0;
}
int EnableTouch(bool enable)
{
HKEY hkey;
LONG lResult;
DWORD dwtype;
if(IsWin64())
{
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Wisp\\Touch\\"), 0, KEY_WOW64_64KEY | KEY_ALL_ACCESS |KEY_WRITE, &hkey);
}
else
{
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Wisp\\Touch\\"), 0, KEY_WOW64_32KEY | KEY_ALL_ACCESS |KEY_WRITE, &hkey);
}
if (lResult == ERROR_SUCCESS)
{
DWORD value = 0;
if(enable)
{
value = 1;
lResult = RegSetValueEx(hkey, _T("TouchGate"), 0, REG_DWORD, (PBYTE)&value, sizeof(DWORD));
value = 0;
lResult = RegSetValueEx(hkey, _T("PanningDisabled"), 0, REG_DWORD, (PBYTE)&value, sizeof(DWORD));
}
else
{
value = 0;
lResult = RegSetValueEx(hkey, _T("TouchGate"), 0, REG_DWORD, (PBYTE)&value, sizeof(DWORD));
value = 1;
lResult = RegSetValueEx(hkey, _T("PanningDisabled"), 0, REG_DWORD, (PBYTE)&value, sizeof(DWORD));
}
if (lResult != ERROR_SUCCESS)
{
char strErr[256];
sprintf(strErr, "SetMulTouch --- GetLastError(): %u\n"GetLastError() );
OutputDebugStringA(strErr);
return FALSE;
}
RegCloseKey(hkey);
}
return 0;
}