如何能使窗口可以响应触摸点击,而窗体不被激活
想做个屏幕键盘,但有个问题就是在点击小键盘窗口时,它会得到焦点,而目标窗口则会失去焦点,虽说可在之后进行激活处理,但这样就造成了窗体的闪烁。不知有没有办法如windows8自带的屏幕键盘那样处理窗口信息,使目标窗体保持激活,或者使某窗体保持不被激活,而能响应点击?我已经找过已解决问题区,找到了鼠标点击的解决方法,但鼠标钩子对触摸屏的触摸点击是不起效的!!
附上论坛的鼠标点击的处理方法:#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $hForeground, $_exit = False, $_move = False, $hw_top
$hGUI = GUICreate('Test', 400, 300, -1, -1, 0, $WS_EX_TOPMOST)
GUICtrlCreateButton('Send "a"', 40, 40, 150, 20)
GUICtrlSetCursor(-1, 0)
$hButton = GUICtrlGetHandle(-1)
GUICtrlCreateButton('Exit', 200, 40, 150, 20)
GUICtrlSetCursor(-1, 0)
$hButton1 = GUICtrlGetHandle(-1)
GUICtrlCreateLabel(' 按住此处拖动窗口', 100, 80, 150, 15)
GUICtrlSetBkColor(-1, 0x00ff00)
GUICtrlSetCursor(-1, 9)
$hLabel = GUICtrlGetHandle(-1)
$iThreadId = _WinAPI_GetCurrentThreadId()
$hInstance = _WinAPI_GetModuleHandle(0)
$hCBTProc = DllCallbackRegister('_CBTCallBack', 'int', 'uint;wparam;lparam')
$pCBTProc = DllCallbackGetPtr($hCBTProc)
$hCBTHook = _WinAPI_SetWindowsHookEx(5, $pCBTProc, $hInstance, $iThreadId)
$hMouseProc = DllCallbackRegister('_MouseProc', 'int', 'uint;wparam;lparam')
$pMouseProc = DllCallbackGetPtr($hMouseProc)
$hMouseHook = _WinAPI_SetWindowsHookEx(14, $pMouseProc, $hInstance, 0)
$hEventProc = DllCallbackRegister('_EventProc', 'none', 'ptr;dword;hWnd;long;long;dword;dword')
$pEventProc = DllCallbackGetPtr($hEventProc)
$hEventHook = _SetWinEventHook($pEventProc, 1)
GUISetState(@SW_SHOWNOACTIVATE)
While GUIGetMsg() + 3
If $_exit Then ExitLoop
If $_move = True Then
$hw_top = _WinAPI_GetForegroundWindow()
GuiMove($hGUI)
$_move = False
EndIf
WEnd
_exit()
Func _exit()
GUIDelete($hGUI)
_WinAPI_UnhookWindowsHookEx($hCBTHook)
_WinAPI_UnhookWindowsHookEx($hMouseHook)
_UnhookWinEvent($hEventHook)
DllCallbackFree($hCBTProc)
DllCallbackFree($hMouseProc)
DllCallbackFree($hEventProc)
GUIDelete($hGUI)
EndFunc ;==>_exit
Func _CBTCallBack($iCode, $iwParam, $ilParam)
Switch $iCode
Case 5
If HWnd($iwParam) = $hGUI Then Return 1
EndSwitch
Return _WinAPI_CallNextHookEx($hCBTHook, $iCode, $iwParam, $ilParam)
EndFunc ;==>_CBTCallBack
Func _EventProc($hEventHook, $iEvent, $hWnd, $iObject, $iChild, $iEventThread, $iEventTime)
If ($iEvent = 0x8005) Then $hForeground = $hWnd
EndFunc ;==>_EventProc
Func _MouseProc($iCode, $iwParam, $ilParam)
If $_move = False Then
If ($iCode < 0) Then Return _WinAPI_CallNextHookEx($hMouseHook, $iCode, $iwParam, $ilParam)
Switch $iwParam
Case $WM_LBUTTONDOWN, $WM_LBUTTONUP, $WM_RBUTTONDOWN, $WM_RBUTTONUP, $WM_MBUTTONDOWN, $WM_MBUTTONUP
Local $tBuffer = DllStructCreate('int X;int Y', $ilParam)
Local $hWindow = _WinAPI_WindowFromPoint($tBuffer)
$tBuffer = 0
Switch $hWindow
Case $hGUI
Return 1
Case $hButton
If ($iwParam = $WM_LBUTTONUP) Then Send('a')
Return 1
Case $hButton1
$_exit = True
Return 1
Case $hLabel
$_move = True
Return 1
EndSwitch
EndSwitch
EndIf
Return _WinAPI_CallNextHookEx($hMouseHook, $iCode, $iwParam, $ilParam)
EndFunc ;==>_MouseProc
Func _SetWinEventHook($pCallBack, $iFlags, $iEventMin = 1, $iEventMax = 0x7FFFFFFF, $iProcessId = 0, $iThreadId = 0)
Local $iResult
$iResult = DllCall('User32.dll', 'ptr', 'SetWinEventHook', 'uint', $iEventMin, _
'uint', $iEventMax, 'ptr', 0, 'ptr', $pCallBack, 'dword', $iProcessId, _
'dword', $iThreadId, 'uint', $iFlags)
Return $iResult
EndFunc ;==>_SetWinEventHook
Func _UnhookWinEvent($hEventHook)
Local $iResult
$iResult = DllCall('User32.dll', 'int', 'UnhookWinEvent', 'ptr', $hEventHook)
Return $iResult
EndFunc ;==>_UnhookWinEvent
Func GuiMove($hGUI)
MouseDown('left')
Local $PY, $a_R, $PM = MouseGetPos(), $PW = WinGetPos($hGUI, '')
$PY = $PW - $PM
$PY = $PW - $PM
While 1
$a_R = DllCall('user32.dll', "short", "GetAsyncKeyState", "int", '0x01')
If @error Then Return 0
If Not BitAND($a_R, 0x8000) Then ExitLoop
$PM = MouseGetPos()
WinMove($hGUI, '', $PM + $PY, $PM + $PY)
Sleep(5)
WEnd
WinActivate($hw_top)
EndFunc ;==>GuiMove
页:
[1]