Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#1

InternalGetWindowText & Unicode String ---> String

  Alt 24. Jun 2002, 15:33
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;
Thomas
  Mit Zitat antworten Zitat