找回密码
 加入
搜索
查看: 1824|回复: 2

[系统综合] [已解决]怎么在当前光标插入内容?

[复制链接]
发表于 2011-8-15 04:23:42 | 显示全部楼层 |阅读模式
本帖最后由 AUFS 于 2011-8-16 23:52 编辑

下面的代码我在论坛里搜索到得到当前光标的位置...取了之后点击按钮的时候MouseClick点击的坐标不对了...有什么办法可以在当前光标插入内容?
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form2 = GUICreate("窗体1", 413, 236, 280, 244)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 393, 153)
GUICtrlSetData(-1, "内容测试测试")
$Button1 = GUICtrlCreateButton("插入内容", 24, 192, 75, 25)
$Button2 = GUICtrlCreateButton("插入内容", 128, 192, 75, 25)
GUISetState(@SW_SHOW)

Opt('MouseCoordMode',0)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $Button1
                        $Post = fn_TestCarePos()
                        If Not @error Then
                        MouseClick('left',$Post[0],$Post[1],1,0)
;~             DllCall("user32.dll", "int", "SetCursorPos", "int", $Post[0], "int", $Post[1])
                        Send('0322456')
                        EndIf
        EndSwitch
WEnd


Func fn_TestCarePos()
        Local $aResult[2]
        Local $Point = DllStructCreate("int var1;int var2")
        DllCall("user32.dll", "int", "GetCaretPos", "ptr", DllStructGetPtr($Point))
        $aResult[0] = DllStructGetData($Point, 1)
        $aResult[1] = DllStructGetData($Point, 2)
        If $aResult[0] = 0 And $aResult[1] = 0 Then Return SetError(1, 0, 0)
                ConsoleWrite('!~X:' & $aResult[0] & ' Y: ' & $aResult[1] & @CRLF)
        Return $aResult
EndFunc
发表于 2011-8-15 05:31:39 | 显示全部楼层
如果是在edit上的光标处插入没必要那么麻烦,见MSDN:EM_REPLACESEL
eg:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form2 = GUICreate("窗体1", 413, 236, 280, 244)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 393, 153)
GUICtrlSetData(-1, "内容测试测试")
$Button1 = GUICtrlCreateButton("插入内容", 24, 192, 75, 25)
$Button2 = GUICtrlCreateButton("插入内容", 128, 192, 75, 25)
GUISetState(@SW_SHOW)

Opt('MouseCoordMode', 0)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        ;$Post = fn_TestCarePos()
                        ;If Not @error Then
                        ;MouseClick('left',$Post[0],$Post[1],1,0)
;~             DllCall("user32.dll", "int", "SetCursorPos", "int", $Post[0], "int", $Post[1])
                        ;        Send('0322456')
                        ;EndIf
                        ;0xC2
                        _SendMessageTimeout(GUICtrlGetHandle($Edit1), 0x0c2, True, '测试发送成功', 0, 'wparam', 'wstr')
        EndSwitch
WEnd

Func _SendMessageTimeout($hWnd, $iMsg, $wparam = 0, $lparam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lresult", $iTimeout = 1000, $iFlags = 3)
        Local $Ret = DllCall("user32.dll", $sReturnType, "SendMessageTimeoutW", "hwnd", $hWnd, "uint", $iMsg, $wParamType, $wparam, $lParamType, $lparam, "uint", $iFlags, "uint", $iTimeout, "dword_ptr*", $iReturn)
        If (@error) Or (Not $Ret[0]) Then
                Return SetError(1, 0, "")
        EndIf
        Return SetError(0, 1, $Ret[7])
EndFunc   ;==>_SendMessageTimeout

评分

参与人数 1金钱 +20 收起 理由
AUFS + 20 解决...谢谢

查看全部评分

发表于 2011-8-15 05:33:17 | 显示全部楼层
If there is no selection, the replacement text is inserted at the caret
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-1 19:29 , Processed in 0.072611 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表