【问题标题】:Autohotkey DLLcall to CreateCaret returns 0 (The function failed) but A_LastError is also 0 (The function succeeded)Autohotkey DLLcall to CreateCaret 返回 0(函数失败)但 A_LastError 也是 0(函数成功)
【发布时间】:2020-08-07 11:13:28
【问题描述】:

我正在尝试对 user32 api 函数CreateCaret 使用简单的 AHK DLLCall。我希望它给记事本一个粗体插入符号。

caretWidth := 10
NULL := 0
Ptr := A_PtrSize ? "Ptr" : "UInt" ; If A_PtrSize is not defined, use UInt instead.
WinHwnd := WinExist("A")
result := Dllcall("CreateCaret", Ptr, WinHwnd, Ptr, NULL, "Int", caretWidth, "Int", 0)
msgbox % "LE " A_lasterror  ; Gives LE 0
msgbox % result  ; Gives 0

这应该等同于以下 c++ 调用:

CreateCaret(0x37072c, NULL, 10, 0);

故意搞砸函数名会使结果为空,所以我相信该函数被正确调用。我只是不知道为什么它失败了

GetCursorBlinkRate 使用类似的代码会返回一个合理的数字。

我也试过caretWidth := 0

关于GetLastError 的类似问题是c++ 调用,并且AHK 应该确保GetLastError 被及时调用以确保正确设置A_lasterror。为什么函数明显失败时没有显示错误代码?

【问题讨论】:

    标签: autohotkey user32


    【解决方案1】:

    您无法更改外部进程的插入符号。
    例如,如果您尝试这样做,如果您拥有该流程,您会发现它工作得很好:

    #Persistent
    Gui, +hwndHWND
    Gui, Add, Edit
    Gui, Show
    
    DllCall("CreateCaret", Ptr, HWND, Ptr, 0, Int, 50, Int, 50)
    DllCall("ShowCaret", Ptr, HWND)
    
    ESC::
    GuiClose:
    ExitApp
    

    【讨论】:

    • 这令人失望,但我不相信这就是故事的结局。 AML Maple 设法改变任意进程的编辑控件的光标。公平地说,他们可能没有使用 user32 api。
    • 是的,我不怀疑有办法。不过那是什么,我不知道。
    • 你在技术上回答了这个问题,所以我会给你积分
    猜你喜欢
    • 2019-03-13
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2015-12-03
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多