- Delphiartiklar, tips, forum, länksamling - 

      

START | DELPHI | LÄNKARGÄSTBOK 




 Forum

Grundkurs
  »Introduktion
  »Snabbguide
  »Komponenter
  »Händelser
  »Strängar
  »Räkna med Delphi   »Egna typer
  »Selektion
  »Iteration
  »Menyer
  »Funktioner
  »Arraystrukturer

Tips & Tricks
  »Nya tips
  »Blandat
  »Databaser
  »Filer
  »Forms
  »Grafik
  »Internet
  »Komponenter
  »Matematik
  »Multimedia
  »Objekt/ActiveX
  »Skrivare
  »Strängar
  »System
  »Mest lästa tips

Artiklar
  »Delphi och ADO
  »Bygga en DLL
  »Skapa en enkel rapport
  »Hantera registret
  »Enheter, units
  »Klassen TCanvas
  »Använd LookUp Controls

 Nya tips
 Lägg till tips
 Delphilänkar
 Gästbok

 

Klicka på en knapp i ett annat program Kategori: System
Inlagt: 2005-08-13
Läst: 1658
Inlagt av: Staffan Berg
Beskrivning
Ett lite roligt exempel för att genom programmet klicka på en kommandoknapp i en annan applikation.
Kod
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; 
 

 
 
© Copyright 2005 - Staffan Berg
- Alla rättigheter förbehålles -