【发布时间】:2017-04-07 17:27:28
【问题描述】:
以下代码在该行返回“运行时错误 5:无效的过程调用或参数”:
结果 = PostMessage(h, WM_CHAR, Asc(Mid$(vbCr, i, 1)), 0&)
Private Const WM_CHAR = &H102
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Sub PostToCmdLine()
Dim h As Long
Dim result As Boolean
' find dos prompt window
h = FindWindow(vbNullString, "c:\windows\system32\cmd.exe")
Stop
If h Then
' send "calc.exe" followed by carraige return
result = PostMessage(h, WM_CHAR, Asc(Mid$(vbCr, i, 1)), 0&)
' optional, check postmessage result
If result = False Then MsgBox ("postmessage failed!")
'close the hidden dos prompt window
' SendTxt(h, "exit" & vbCr)
Else
MsgBox ("dos prompt window not found")
End If
End Sub
我做错了什么?
【问题讨论】:
标签: vba postmessage user32