我看到有位大哥这样说的!用EnumWindows根据目标窗口的标题找到它的句柄,再用EnumChildWindows找到Edit的句柄,然后SendMessage WM_SetText.这样好象可以.但是问题又出现了.因为我的外部程序上有2个EDIT,分别是2个路径.而找到EDIT句柄再修改的话,会同时把2个一同修改了.怎么样单独修改呢?代码如下:希望高手指教!
function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption:array[0..254] of Char;
begin
GetWindowText(Hwnd,WindowCaption,255);
if StrPas(WindowCaption)='MXIC Speech Utility' then
begin
cnt := 0;
EnumChildWindows(Hwnd,@EnumChildProc,0);
Result := False;
Exit;
end;
Result := True;
end;
function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption,WindowClass:array[0..254] of Char;
begin
GetClassName(Hwnd,WindowClass,255);
if Pos('EDIT',UpperCase(StrPas(WindowClass))) > 0 then
begin
Inc(cnt);
SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(s)));
////此处换成SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar('你想送的字符串')));即可
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aHandle:THandle;
i:integer;
s1:string;
begin
shellexecute(aHandle,'open','c:/MSU.exe',nil,'',sw_shownormal);
timedelay(1000);
Wnd := FindWindow(nil,'MXIC Speech Utility');
if Wnd <> 0 then
begin
SetForegroundWindow(Wnd);
s:='c:/60s.bin';
Enumwindows(@EnumWindowsProc,0); //往外部EXE的第一个EDIT填第一个路径
for i:=1 to 2 do //--2个tab
begin
keybd_event(VK_Tab, MapVirtualKey(VK_Tab, 0), 0, 0);
keybd_event(VK_Tab, MapVirtualKey(VK_Tab, 0), KEYEVENTF_KEYUP, 0);
end;
s:='c:/60s.wav';
Enumwindows(@EnumWindowsProc,0); //往外部EXE的第2个EDIT填第2个路径