AUFS 发表于 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,$Post,1,0)
;~             DllCall("user32.dll", "int", "SetCursorPos", "int", $Post, "int", $Post)
                        Send('0322456')
                        EndIf
        EndSwitch
WEnd


Func fn_TestCarePos()
      Local $aResult
      Local $Point = DllStructCreate("int var1;int var2")
      DllCall("user32.dll", "int", "GetCaretPos", "ptr", DllStructGetPtr($Point))
      $aResult = DllStructGetData($Point, 1)
      $aResult = DllStructGetData($Point, 2)
      If $aResult = 0 And $aResult = 0 Then Return SetError(1, 0, 0)
                ConsoleWrite('!~X:' & $aResult & ' Y: ' & $aResult & @CRLF)
      Return $aResult
EndFunc

ceoguang 发表于 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,$Post,1,0)
;~             DllCall("user32.dll", "int", "SetCursorPos", "int", $Post, "int", $Post)
                        ;        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) Then
                Return SetError(1, 0, "")
        EndIf
        Return SetError(0, 1, $Ret)
EndFunc   ;==>_SendMessageTimeout

ceoguang 发表于 2011-8-15 05:33:17

If there is no selection, the replacement text is inserted at the caret
页: [1]
查看完整版本: [已解决]怎么在当前光标插入内容?