![]() |
InternalGetWindowText & Unicode String ---> String
Hi,
Wie wandelt man am einfachsten einen Unicode String in einen String um? lpString hat den Wert ('F', #0, 'o', #0, 'r', #0, 'm', #0, '1', #0, #0, #0, 'A', #10, #1, '&', #0, #0, ...) Wobei dann Showmessage nur 'F' anzeigt. (Klar, wegen den null-term. Strings)
Code:
function NT_InternalGetWindowText(Wnd: HWND): String;
type TInternalGetWindowText = function(Wnd: HWND;lpString: PChar;nMaxCount: Integer): Integer; stdcall; var hUserDll: THandle; InternalGetWindowText: TInternalGetWindowText; lpString: array[0..MAX_PATH] of Char; //Buffer for window caption oemStr : PChar; begin Result := ''; hUserDll := GetModuleHandle('user32.dll'); if (hUserDll > 0) then begin @InternalGetWindowText := GetProcAddress(hUserDll, 'InternalGetWindowText'); if Assigned(InternalGetWindowText) then begin InternalGetWindowText(Wnd, lpString, SizeOf(lpString)); Result := StrPas(lpString); end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(NT_InternalGetWindowText(handle)); end; |
Folgende drei Zeilen müssen geändert werden.
lpString: array[0..MAX_PATH] of WideChar; //Buffer for window caption InternalGetWindowText(Wnd, @lpString, SizeOf(lpString)); Result := AnsiString(lpString); Das wars. |
Danke.
|
Okay, die letzte Möglichkeit war nicht perfekt. Diese Lösung ist wohl besser.
Code:
Änderungen zu Deiner Lösung:
function NT_InternalGetWindowText(Wnd: HWND): String;
type TInternalGetWindowText = function(Wnd: HWND;lpString: PWideChar;nMaxCount: Integer): Integer; stdcall; var hUserDll: THandle; InternalGetWindowText: TInternalGetWindowText; lpString: array[0..MAX_PATH] of WideChar; //Buffer for window caption oemStr : PChar; begin Result := ''; hUserDll := GetModuleHandle('user32.dll'); if (hUserDll > 0) then begin @InternalGetWindowText := GetProcAddress(hUserDll, 'InternalGetWindowText'); if Assigned(InternalGetWindowText) then begin InternalGetWindowText(Wnd, lpString, SizeOf(lpString)); Result := String(lpString); end; end; end; TInternalGetWindowText = function(Wnd: HWND;lpString: PWideChar;nMaxCount: Integer): Integer; stdcall; lpString: array[0..MAX_PATH] of WideChar; //Buffer for window caption Result := String(lpString); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:13 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz