Autor Beitrag
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mi 02.03.05 18:14 
Hallo, das steht in einer anderen Anwendung:[url]www.vonrueti.ch/Unbenannt.bmp[/url]
Und ich möchte es gerne auselesen, doch wie mache ich das?

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 02.03.05 18:34 
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mi 02.03.05 20:53 
Ich weiss jezt was es für n' Typ ist: Static, doch wie lese ich das aus, und baue es in Mein Prog ein?

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mi 02.03.05 21:01 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  wnd: HWND;
begin
  wnd :=  FindWindow(nil, 'MyProg');
  wnd :=  FindWindowEx(wnd, 0, 'Static', nil);

  if wnd <> 0 then
  begin

  end;
end;

Wie kann ich nun das Static auslesen, und was sthet nun in wnd?

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Mi 02.03.05 21:25 
invulnerabilis hat folgendes geschrieben:
[
Wie kann ich nun das Static auslesen, und was sthet nun in wnd?


Stichwort: Suche in: Delphi-Forum, Delphi-Library WM_GETTEXT
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Do 03.03.05 07:54 
ich habe gesucht, und gefunden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var s : string;
  wnd: HWND;
begin
  wnd :=  FindWindow(nil, 'My Prog');
  wnd :=  FindWindowEx(wnd, 0, 'Static', nil);

  if wnd <> 0 then
  begin
     SendMessage( wnd, WM_GETTEXT, 256, Integer( @s ) );
     label1.Caption:= s;
end;

end;

doch etwas funktioniert daran nicht.
Was muss ich machen, damit ich den text dann auch im label habe?

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
brüse
Hält's aus hier
Beiträge: 3

WIN 2000

BeitragVerfasst: Mo 07.03.05 21:08 
Titel: GetWindowText
Hallo,
probiere doch mal GetWindowText() aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
...
const cMaxSize = 255; // <- könnte auch größer sein ;-)
var c: array[0..cMaxSize] of char;
    rc, L: integer;
    hWnd: THandle; // <- z. B. über FindWindow() holen
...
FillChar(c, SizeOf(c), #0);
L := SizeOf(c);
rc := GetWindowText(hWnd, c, L);
// Mal schaun was zurückgekommen ist ...
if rc <> 0 then
begin
     ShowMessage(StrPas(c));
end;
...


Anmerkung:
WM_GETTEXT nutze ich für Steuerelemente (Delphi: TEdit, TMemo, TRichEdit, ...) - nicht für externe Fenster;-)


Gutes Gelingen!

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt.
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Di 08.03.05 07:13 
weshalb kommt der Text in einen Interger? mussd er nicht in n'en string?

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Di 08.03.05 07:32 
Wieso Integer?

Was da falsch ist, ist dass ein String kein array of char ist, sondern ein Objekt, dass einen array of Char kapselt. Oben deklarierst du s als leeren String, d.h. aber, dass dort kein Platz für Text ist. Unten übergibst du die Adresse (@s) in der Funktion SendMessage, und unter 32Bit Windows ist die Adresse formal ein 32Bit-Wert, lässt sich also als Integer casten.

Was du aber tatsächlich brauchst, ist ein Puffer (array of Char), der auch Platz genug hat für den Text, den du abholen willst. PChar(String) funktioniert nur, wenn du den Text in deinem String hast, und nun die Adresse des internen Arrays brauchst!
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Di 08.03.05 07:35 
ok

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
brüse
Hält's aus hier
Beiträge: 3

WIN 2000

BeitragVerfasst: Mi 09.03.05 13:37 
Hallo, hab noch mal schnell in der Mittagspause eine Beispiel-Proc erstellt. Hier findest Du den Einsatz von GetWindowText(), von GetClassName() und ein bischen den Umgang mit c-Strings in Delphi. Sciher kann man auch mit AnsiString und dem Adress-Operator "@" arbeiten, hier besteht jedoch bei nicht sauber initialisierten Strings (.. SetLength() etc.) immer die Gefahr dass der Speicher nicht entsprechend zugeordnet ist. Ist zwar manchmal schneller getippt dafür sucht man länger nach dem Fehler. Reine Geschmacks- und Übungsfrage.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
procedure TForm1.Button1Click(Sender: TObject);
const cMaxSize = 255; // <- könnte auch größer sein ;-)
var cBuffer: array[0..cMaxSize] of char;
    rc, L: integer;
    hWnd: THandle; // <- z. B. über FindWindow() holen
begin
     // Puffer wieder initialisieren ...
     FillChar(cBuffer, SizeOf(cBuffer), #0);
     // Puffer mit dem Titel des gesuchten Fensters füllen ...
     StrPCopy(cBuffer, copy(Edit1.Text, 1, cMaxSize));
     // "copy(Edit1.Text, 1, cMaxSize)" stellt sicher, dass der Puffer nicht
     // überläuft ;-)
     hWnd := FindWindow(nil, cBuffer);
     if hWnd = 0 then
     begin
          // Fenster nicht gefunden ...
          ShowMessage(SysErrorMessage(GetLastError));
     end else
     begin
          // Puffer wieder initialisieren ...
          FillChar(cBuffer, SizeOf(cBuffer), #0);
          // Größe des Puffers mitgeben ...
          L := SizeOf(cBuffer);
          // Text des Fesnters holen (Fenster-Titel, Delphi: "TForm.Caption") ...
          rc := GetWindowText(hWnd, cBuffer, L);
          if rc <> 0 then
          begin
               // Mal schaun was zurückgekommen ist ...
               ShowMessage(StrPas(cBuffer));
               // Puffer wieder initialisieren ...
               FillChar(cBuffer, SizeOf(cBuffer), #0);
               // Größe des Puffers mitgeben ...
               L := SizeOf(cBuffer);
               // Klasse des Fesnters holen (Delphi: "TForm.ClassName" ) ...
               rc := GetClassName(hWnd, cBuffer, L);
               // Mal schaun was zurückgekommen ist ...
               if rc <> 0 then
               begin
                    ShowMessage(StrPas(cBuffer));
               end else
               begin
                    // Fehler anzeigen für GetClassName() ...
                    ShowMessage(SysErrorMessage(GetLastError));
               end;
          end else
          begin
               // Fehler anzeigen für GetWindowText() ...
               ShowMessage(SysErrorMessage(GetLastError));
          end;
     end;
end;


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
Lesco
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 42



BeitragVerfasst: Do 24.03.05 20:05 
bei mir kommt als fehlermeldung
inkompatible typen: Array und PAnsiChar