Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi HandleByExeName und GetWindowText bringt "Default IME" ?! (https://www.delphipraxis.net/121518-handlebyexename-und-getwindowtext-bringt-default-ime.html)

heidsch 29. Sep 2008 17:13


HandleByExeName und GetWindowText bringt "Default IME&q
 
EDIT: Bitte den 3.post lesen....




hallo leute,

ich komm hier einfach nicht weiter. ich habe eine funktion gefunden,
welche mir das handle aus dem namen der exe ermittelt.
nur leider bekomme ich dann einen AccessViolation-Fehler. sieht einer
von euch den fehler?

Delphi-Quellcode:
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,TLHelp32,StdCtrls, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StatusBar1: TStatusBar;
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  WindowHandle: THandle;
  ProcessHandle: THandle;
  h:HWnd;

implementation

{$R *.dfm}

function MyEnumWindowProc(AHandle: THandle; LParam: LongWord): boolean;
stdcall;
var
  ProcessID: THandle;
begin
  ProcessID := 0;
  GetWindowThreadProcessID(AHandle, ProcessID);
  Result := not (ProcessID = LParam);
  if not Result then
    WindowHandle := AHandle;
end;

function GetWindowHandleByExeName(const AExeName: string): THandle;
var
  SnapShot: THandle;
  p: TProcessEntry32;
begin
  Result := 0;
  WindowHandle := 0;
  ProcessHandle := 0;
  p.dwSize := SizeOf(p);
  SnapShot := CreateToolhelp32Snapshot(TH32CS_SnapProcess, 0);
  try
    if Process32First(SnapShot, p) then
      repeat
      if AnsiLowerCase(AExeName) = AnsiLowerCase(p.szExeFile) then
        ProcessHandle := p.th32ProcessID;
      until (ProcessHandle <> 0) or not Process32Next(SnapShot, p);
    EnumWindows(@MyEnumWindowProc, ProcessHandle);
    GetParent(WindowHandle);
    Result := WindowHandle;
  finally
    CloseHandle(SnapShot);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var myBuf: array[0..250] of Char;
begin
WindowHandle := GetWindowHandleByExeName('putty.exe');
GetWindowText(WindowHandle, myBuf, sizeof(myBuf));
StatusBar1.SimpleText:=myBuf;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
self.Left:=round((screen.Width/2)-(self.Width/2));
self.Top:=0;
end;

end.

heidsch 29. Sep 2008 17:35

Re: HandleByExeName verursacht AccessViolation
 
oh gott,

vergisst es.....sorry mein fehler.

hier liegt der fehler:

Delphi-Quellcode:
WindowHandle := GetWindowHandleByExeName('putty.exe');
GetWindowText(WindowHandle, myBuf, sizeof(myBuf));
ich muß eine andere variable als "WindowHandle" nehmen....wird ja schon in
der funktion benutzt....

bitte den thread schließen !!!!

heidsch 30. Sep 2008 15:19

Re: HandleByExeName verursacht AccessViolation
 
jetzt hab ich doch noch ein problem:

Delphi-Quellcode:
WindowHandle := GetWindowHandleByExeName('putty.exe');
GetWindowText(WindowHandle, myBuf, sizeof(myBuf));
die funktion GetWindowText() liefert mir ja den fensternamen
des handles.
das klappt ja auch auf 2 von 3 rechnern.

der eine rechner bei dem es nicht klappt gibt mir als fensternamen "Default IME"
zurück.
alle 3 rechner sind winXP-Rechner. ich gehe davon aus, das es mit windows zu tun
hat, jedoch hab ich keinerlei ideen woher diese angabe stammt.

kennt jeman dvon euch dieses "Default IME"?

mfg heidsch


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:43 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz