Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

About WinSight and click button on another program...

Posted on 2003-03-16
2
Medium Priority
?
1,228 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
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

578 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