使用带有Windows API的Excel VBA清除其他应用程序编辑控件中的文本值

时间:2015-05-14 04:29:19

标签: vba winapi sendmessage

渲染输出

降价

-1

投票

评论:代码对齐

使用带有Windows API的Excel VBA清除其他应用程序编辑控件中的文本值

hTarget是其他应用程序的句柄值。 [失败]

  • ret = SendMessage(hTarget,WM_SETFOCUS,0&,0&)
    • ret = SendMessage(hTarget,WM_KEYDOWN,VK_CONTROL,0) -ret = SendMessage(hTarget,WM_KEYDOWN,97,0)
    • ret = SendMessage(hTarget,WM_KEYDOWN,VK_DELETE,0)
    • 睡觉(300)
    • ret = SendMessage(hTarget,WM_KEYUP,VK_DELETE,0)
    • ret = SendMessage(hTarget,WM_KEYUP,97,0) -ret = SendMessage(hTarget,WM_KEYUP,VK_CONTROL,0)

[失败]
-Const EM_SETSEL =& HB1

-Const EM_REPLACESEL =& HC2

-Const EM_GETSEL =& HB0

-hTarget = FindWindowEx(hTarget,0&," TPlusMemoU",vbNullString)

-Call SendMessage(hTarget,EM_SETSEL,0,-1)

-Call SendMessage(hTarget,EM_REPLACESEL,1,"")

[失败]
-Call SendMessage(hTarget,WM_KEYDOWN,VK_BACK,0) -Call SendMessage(hTarget,WM_CHAR,8,0)

hTarget是其他应用程序的句柄值。 [失败] ret = SendMessage(hTarget,WM_SETFOCUS,0&,0&)
ret = SendMessage(hTarget,WM_KEYDOWN,VK_CONTROL,0)
ret = SendMessage(hTarget,WM_KEYDOWN,97,0)
ret = SendMessage(hTarget,WM_KEYDOWN,VK_DELETE,0)
睡觉(300)
ret = SendMessage(hTarget,WM_KEYUP,VK_DELETE,0)
ret = SendMessage(hTarget,WM_KEYUP,97,0)
ret = SendMessage(hTarget,WM_KEYUP,VK_CONTROL,0)

[失败] Const EM_SETSEL =& HB1

Const EM_REPLACESEL =& HC2 Const EM_GETSEL =& HB0

hTarget = FindWindowEx(hTarget,0&," TPlusMemoU",vbNullString)

调用SendMessage(hTarget,EM_SETSEL,0,-1) 调用SendMessage(hTarget,EM_REPLACESEL,1,"")

[失败] 调用SendMessage(hTarget,WM_KEYDOWN,VK_BACK,0) 调用SendMessage(hTarget,WM_CHAR,8,0)

1 个答案:

答案 0 :(得分:0)

你做不到。这些规范说你可以从另一个进程的编辑控件中获取文本。

  

GetWindowText功能

     

GetWindowText函数将指定窗口标题栏的文本(如果有的话)复制到缓冲区中。如果指定的窗口是控件,则复制控件的文本。但是,GetWindowText无法在另一个应用程序中检索控件的文本。