SendMessage和PostMessage
Myhwnd()内为别支程式上的控制项句柄程序代码:
Public Function PatternUnCompliar(FN As String, TP As String) As Boolean Dim pID As Long, hProcess As Long, i As Integer Dim Source As Long, OutPut As Long, Start As Long, Out As Long Dim Temp() As String, TPN As String If Right$(FN, Len(Ext2)) = Ext2 Then TPN = Replace(FN, Ext2, Ext3) TPN = TP & Mid$(TPN, InStrRev(TPN, "\") + 1) pID = Shell(Aprcg, vbNormalFocus) EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0& For i = 1 To UBound(Myhwnd) Temp = Split(Myhwnd(i), ",") If i = 1 Then Source = CLng(Temp(0)) ElseIf i = 2 Then OutPut = CLng(Temp(0)) ElseIf i = 3 Then Start = CLng(Temp(0)) ElseIf i = 4 Then Out = CLng(Temp(0)) End If Erase Temp Next i i = SendMessage(CLng(Source), WM_SETTEXT, 0, ByVal FN) Debug.Print i i = SendMessage(CLng(OutPut), WM_SETTEXT, 0, ByVal TPN) Debug.Print i ' i = SendMessage(CLng(Start), BM_CLICK, 0&, ByVal 0&) i = PostMessage(CLng(Start), BM_CLICK, CLng(0), CLng(0)) Debug.Print i ' i = SendMessage(CLng(Out), BM_CLICK, 0&, ByVal 0&) i = PostMessage(CLng(Out), BM_CLICK, CLng(0), CLng(0)) Debug.Print i KillProcess Mid$(Aprcg, InStrRev(Aprcg, "\") + 1) FN = TPN MyhwndCount = 0: ReDim Preserve Myhwnd(MyhwndCount) Else MsgBox "PatternUnCompliar Error !!" End If End Function
为何用SendMessage模拟按钮事件会出现错误讯息?
用PostMessage就OK?
我大概知道SendMessage和PostMessage之间作用的差异
想问SendMessage这样写是哪边有问题?会出现: