was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

53 Visitors Online


 
...auf einen Button einer anderen Anwendung per Code klicken?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (31):  
     


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;


{
Rememeber the ampresand for underlined characters
if the 'c' is underlined, then the text is '&click'

Achte darauf, dass z.B nach '&Klick' gesucht werden muss,
wenn der Button eine Ampresand enthält
}

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners