[已解决]关于GUICtrlCreateEdit中的强制性样式: $WS_TABSTOP 的问题
本帖最后由 zjimmy 于 2010-5-17 22:09 编辑帮助文档中指出,在 GUICtrlCreateEdit 中,$WS_TABSTOP 是强制的,这里我有一个疑问:
如果我需要在 Edit 中输入"制表符",即按下 {Tab},怎么办?
默认情况下,按下 {Tab} 就切换到另一个控件了。。。 补充一下,我的版本是 3.3.0.0 呃,没有什么人理我。。。论坛搜索也没有找到需要的。 #include <GUIEdit.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("", 400 ,300)
GUICtrlCreateEdit("", 5, 5, 390, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$hEdit = GUICtrlGetHandle(-1)
GUICtrlCreateButton("Ok", 220, 270, 80, 20)
GUICtrlCreateButton("Cancel", 310, 270, 80, 20)
$hEC = DllCallBackRegister("_EditProc", "int", "hWnd;uint;wparam;lparam")
$hOEC = _WinAPI_SetWindowLong($hEdit, -4, DllCallBackGetPtr($hEC))
GUISetState()
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
DllCallbackFree($hEC)
Func _EditProc($hWnd, $iMsg, $iwParam, $ilParam)
If ($iMsg = $WM_KEYDOWN) And ($iwParam = 9) Then
Return GUICtrlSetData(3, GUICtrlRead(3) & @Tab)
EndIf
Return _WinAPI_CallWindowProc($hOEC, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>_EditProc截取WM_KEYDOWN消息。还涉及到插入符的位置问题,参考此贴:http://autoitx.com/forum.php?mod=viewthread&tid=11760&highlight=%C1%B7%CF%B0 截取WM_KEYDOWN消息。还涉及到插入符的位置问题,参考此贴:
pusofalse 发表于 2010-5-11 09:00 http://www.autoitx.com/images/common/back.gif
强!
请问,关于这里的3怎么理解?Return GUICtrlSetData(3, GUICtrlRead(3) & @Tab) 回复 5# zjimmy
就是第一个创建的控件 那么,这里的3为什么不替换为 Edit 的 Control ID 呢?#include <GUIEdit.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("", 400 ,300)
$Edit = GUICtrlCreateEdit("", 5, 5, 390, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$hEdit = GUICtrlGetHandle(-1)
GUICtrlCreateButton("Ok", 220, 270, 80, 20)
GUICtrlCreateButton("Cancel", 310, 270, 80, 20)
$hEC = DllCallBackRegister("_EditProc", "int", "hWnd;uint;wparam;lparam")
$hOEC = _WinAPI_SetWindowLong($hEdit, -4, DllCallBackGetPtr($hEC))
GUISetState()
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
DllCallbackFree($hEC)
Func _EditProc($hWnd, $iMsg, $iwParam, $ilParam)
If ($iMsg = $WM_KEYDOWN) And ($iwParam = 9) Then
Return GUICtrlSetData($Edit, GUICtrlRead($Edit) & @Tab)
EndIf
Return _WinAPI_CallWindowProc($hOEC, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>_EditProc另外,如果有两个以上 Edit,又应该怎么处理这个_EditProc 呢?#include <GUIEdit.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("", 400 ,300)
GUICtrlCreateEdit("", 5, 5, 390, 120, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$hEdit1 = GUICtrlGetHandle(-1)
GUICtrlCreateEdit("", 5, 135, 390, 120, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$hEdit2 = GUICtrlGetHandle(-1)
GUICtrlCreateButton("Ok", 220, 270, 80, 20)
GUICtrlCreateButton("Cancel", 310, 270, 80, 20)
$hEC = DllCallBackRegister("_EditProc", "int", "hWnd;uint;wparam;lparam")
$hOEC1 = _WinAPI_SetWindowLong($hEdit1, -4, DllCallBackGetPtr($hEC))
GUISetState()
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
DllCallbackFree($hEC)
Func _EditProc($hWnd, $iMsg, $iwParam, $ilParam)
If ($iMsg = $WM_KEYDOWN) And ($iwParam = 9) Then
Return GUICtrlSetData(3, GUICtrlRead(3) & @Tab)
EndIf
Return _WinAPI_CallWindowProc($hOEC1, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>_EditProc 比较好的处理应该是这样:(感谢 A版 和 P版)#include <GUIEdit.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("", 400, 300)
GUICtrlCreateButton("Ok", 220, 270, 80, 20)
GUICtrlCreateButton("Cancel", 310, 270, 80, 20)
$Edit1 = GUICtrlCreateEdit("", 5, 5, 390, 120, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$hEdit1 = GUICtrlGetHandle(-1)
$Edit2 = GUICtrlCreateEdit("", 5, 135, 390, 120, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$hEdit2 = GUICtrlGetHandle(-1)
$hEC = DllCallbackRegister("_EditProc", "int", "hWnd;uint;wparam;lparam")
$hOEC1 = _WinAPI_SetWindowLong($hEdit1, -4, DllCallbackGetPtr($hEC))
$hOEC2 = _WinAPI_SetWindowLong($hEdit2, -4, DllCallbackGetPtr($hEC))
GUISetState()
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
DllCallbackFree($hEC)
Func _EditProc($hWnd, $iMsg, $iwParam, $ilParam)
If ($iMsg = $WM_KEYDOWN) And ($iwParam = 9) Then
If $hWnd = $hEdit1 Then Return GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @TAB)
If $hWnd = $hEdit2 Then Return GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & @TAB)
EndIf
If $hWnd = $hEdit1 Then Return _WinAPI_CallWindowProc($hOEC1, $hWnd, $iMsg, $iwParam, $ilParam)
If $hWnd = $hEdit2 Then Return _WinAPI_CallWindowProc($hOEC2, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>_EditProc
页:
[1]