我想查找特定窗口的特定按钮,然后发送消息,请问怎么做?(50分)

  • 主题发起人 主题发起人 jianguo_bu
  • 开始时间 开始时间
J

jianguo_bu

Unregistered / Unconfirmed
GUEST, unregistred user!
我是如下这样做的,但经调试BUF里总是为一空格,请问为什么?<br>function EnumWindowsProc(Handle: HWND; lParam: LPARAM): Boolean;<br>var<br>&nbsp; CaptionBuf: PCHAR ;<br>&nbsp; Buf: String;<br>begin<br>// &nbsp;查找特定的按钮,然后发送消息<br>&nbsp; GetMem(CaptionBuf, 256);<br>&nbsp; try<br>&nbsp; &nbsp; GetWindowText(Handle, CaptionBuf, 255);<br>&nbsp; &nbsp; Buf := strpas(CaptionBuf);<br>&nbsp; &nbsp; Form1.Memo1.Lines.Append(IntToStr(Handle) + ': ' + Buf);<br>&nbsp; &nbsp; if Buf = 'button1' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SendMessage(Handle, WM_LBUTTONDOWN, 0, 0);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; FreeMem(CaptionBuf);<br>&nbsp; end;<br>&nbsp; Result := True;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; WindowHandle: HWND;<br>&nbsp; vlParam: Integer;<br><br>begin<br>&nbsp; WindowHandle := FindWindow(nil, 'form1');<br>&nbsp; Memo1.Clear;<br>&nbsp; Memo1.Lines.Append(IntToStr(WindowHandle) + 'from1');<br>&nbsp; vlParam := 0;<br>&nbsp; EnumChildWindows(WindowHandle, @EnumWindowsProc, vlParam);<br>end;<br>
 
后退
顶部