R
redrain
Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现在一个程序中按下某个按钮后,相当于在另外一个程序中按下了某个菜单项,<br>怎么才能实现,各位dfw帮忙了.程序如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> FitemopenHandle, FitemcloseHandle : HWND;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>function GetitemcloseHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>var<br> buffer: array[0..255] of Char;<br> buffer1: array[0..255] of Char;<br>begin<br> Result := True;<br><br> GetClassName(hwnd,buffer,256);<br><br>if StrPas(Buffer)='MenuItem' then<br> begin<br> GetWindowText(hwnd,buffer1,100);<br> if buffer1 = '关闭' then<br> begin<br> PInteger(lparam)^ := hwnd; <br> Result:=False; <br> end;<br> end;}<br>end;<br>{$R *.dfm}<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> Handle: Integer;<br> tmpHandle: Integer;<br>begin<br> Handle := FindWindow(nil,'----(3.30版)'); //就是窗口的Caption<br> if Handle<>0 then<br> begin<br> tmpHandle := Handle;<br> if getitemclosehandle(handle,0) then<br> begin<br> EnumChildWindows(Handle,@GetitemcloseHandle,Integer(@Handle));<br> FitemcloseHandle := Handle;<br> end;<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>SendMessage(FitemcloseHandle,WM_LBUTTONDOWN,0,0);<br>SendMessage(FitemcloseHandle,WM_LBUTTONUP,0,0);<br>end;<br><br>end.<br><br>