Einzelnen Beitrag anzeigen

Benutzerbild von FriFra
FriFra

Registriert seit: 19. Apr 2003
1.291 Beiträge
 
Delphi 2005 Professional
 
#1

"Arbeitsplatz" in der Sprache des installierten Wi

  Alt 18. Nov 2006, 17:30
Um die Beschriftung vom "Arbeitsplatz" in der jeweils gültigen Sprache zu bekommen habe ich mir die folgende Funktion geschrieben. Der optionale Parameter "Default" wird nur dann verwendet, wenn das Auslesen einmal nicht funktionieren sollte.
Delphi-Quellcode:
function GetMyComputerName(Default: string = ''): string;
    function ExpandEnvStr(const szInput: string): string;
    begin
      SetLength(Result, ExpandEnvironmentStrings(pChar(szInput), nil, 0));
      ExpandEnvironmentStrings(pChar(szInput), @Result[1], Length(Result));
      Result := StrPas(@Result[1]);
    end;
  var
    Buffer: array[0..MAX_PATH] of char;
    h: hwnd;
    SrcFile: string;
    Index: int64;
    RDF: TRegistry;
  const
    CLSID_MYCOMPUTER = '{20D04FE0-3AEA-1069-A2D8-08002B30309D}';
  begin
    Result := '';

    RDF := TRegistry.Create;
    try
      RDF.RootKey := HKEY_CLASSES_ROOT;
      RDF.OpenKey('CLSID\' + CLSID_MYCOMPUTER, false);

      if (RDF.ValueExists('LocalizedString') = True) and
        (RDF.ReadString('LocalizedString') <> '') then
      begin
        SrcFile := copy(RDF.ReadString('LocalizedString'), 2, MAX_PATH);
        Index := StrToIntDef(Copy(SrcFile, Pos(',', SrcFile) + 1,
          Length(SrcFile)), 0);
        if Index < 0 then
          Index := Index - (2 * Index);
        SrcFile := Copy(SrcFile, 1, Pos(',', SrcFile) - 1);
        SrcFile := ExpandEnvStr(SrcFile);
        if (FileExists(SrcFile) = True) and (Index <> 0) then
        begin
          h := loadlibrary(PAnsiChar(SrcFile));
          try
            if h <> 0 then
            begin
              if Loadstring(h, Index, @Buffer, MAX_PATH) > 0 then
              begin
                Result := StrPas(buffer);
              end
              else
                Result := Default;
            end
            else
              Result := Default;
          finally
            freelibrary(h)
          end;
        end;
      end;
      if (Result = Default) and (RDF.ValueExists('') = True) and
        (RDF.ReadString('') <> '') then
        Result := RDF.ReadString('');
    finally
      RDF.Free;
    end;
  end;
Elektronische Bauelemente funktionieren mit Rauch. Kommt der Rauch raus, geht das Bauteil nicht mehr.
  Mit Zitat antworten Zitat