?
Solved

About WinSight and click button on another program...

Posted on 2003-03-16
2
Medium Priority
?
1,222 Views
Last Modified: 2007-12-19
Hi to all Delphi's developers!

I am trying to press a button on another program (WinMX) by my program.. I use WinSight and I have seen there a some child before to reach the button component....

Here you can find a screen shot about the program:

http://www.foppolino.com/Software/WinSightShot.jpg

You can see a line highlights where there is the button I want to press by code trough my program. The button name is: Refresh.
I have tried with the code below but nothing happens when I press the button on my form.
Any help would be appreciated.

Thanks in advance,
Luke

below the code I use (don't works):

procedure TForm1.Button1Click(Sender: TObject);
var
uno,due,tre,
hStartBtn: HWND;
begin

uno:=FindWindow('Afx:400000:b:10011:0:0',nil);

due:=FindWindowEx(uno,0,'Afx:400000:b:10011:0:0',nil);
tre:=FindWindowEx(due,0,'Afx:400000:b:10011:0:0',nil);
hStartBtn:=FindWindowEx(tre,0,'Button','Refresh');


SetForegroundWindow(1);

Sleep(200);


SendMessage(hStartBtn,WM_LBUTTONDOWN,0,0);

SendMessage(hStartBtn,WM_LBUTTONUP,0,0);
end;
0
Comment
Question by:luke066
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
smot earned 200 total points
ID: 8147526
Hi,

Try this:

function EnumChildProc(Wnd: hWnd; SL: TStrings): BOOL; stdcall;
var
  szFull: array[0..MAX_PATH] of Char; //Buffer for window caption
begin
  Result := Wnd <> 0;
  if Result then  
  begin
    GetWindowText(Wnd, szFull, SizeOf(szFull)); // put window text in buffer
    if (Pos(SL[0], StrPas(szFull)) > 0) // Test for text
      and (SL.IndexOfObject(TObject(Wnd)) < 0) // Test for duplicate handles
      then SL.AddObject(StrPas(szFull), TObject(Wnd)); // Add item to list
    EnumChildWindows(Wnd, @EnumChildProc, Longint(SL)); //Recurse into child windows
  end;
end;

function ClickButton(ParentWindow: Hwnd; ButtonCaption: string): Boolean;
var
  SL: TStringList;
  H:  hWnd;
begin
  SL := TStringList.Create;
  try
    SL.AddObject(ButtonCaption, nil); // First item in list is text to find
    EnumChildWindows(ParentWindow, @EnumChildProc, Longint(SL));
    H := 0;
    case SL.Count of
      1: ShowMessage('Window text not found.');
      2: H := hWnd(SL.Objects[1]);
      else  
        ShowMessage('Ambiguous text detected.');
    end;
  finally
    SL.Free;
  end;
  Result := H <> 0;
  if Result then PostMessage(H, BM_CLICK, 0, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  hWinMX: HWND;
begin
 hWinMX:=FindWindow('Afx:400000:b:10011:0:0',nil);
 if hWinMX <> 0 then
 begin
   ClickButton( hWinMX,'Refresh');
 end else // WinMX not open...
end;
0
 

Author Comment

by:luke066
ID: 8150508
Thanks a lot smot. You are a genius!!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question