⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rzshellopenform.pas

📁 Raize控件汉化版
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    Path: string;
    ImageIndex: Integer;
    constructor Create( IDL: TCSIDL ); overload;
    constructor Create( const Directory: string ); overload;
  end;


constructor TRzPlaceData.Create( IDL: TCSIDL );
begin
  inherited Create;
  CSIDL := IDL;
  Caption := GetFriendlyCaption( CSIDL );
  Path := '';
  ImageIndex := ShellGetSpecialFolderIconIndex( CSIDL, 0 );
end;


constructor TRzPlaceData.Create( const directory: string );
var
  s: string;
begin
  inherited Create;

  // Expand any environment variables
  s := ExpandEnvironmentVariables( directory );

  CSIDL := csidlNone;
  if Length( s ) <= 3 then
  begin
    // Dealing with a drive
    Caption := GetFriendlyCaption( s );
  end
  else
  begin
    // Dealing with a normal directory
    Caption := ExtractFileName( s );
  end;
  Path := s;
  ImageIndex := ShellGetIconIndexFromPath( s, 0 );
end;

{$ENDIF}


{==================================}
{== TRzShellOpenSaveForm Methods ==}
{==================================}


constructor TRzShellOpenSaveForm.Create( AOwner: TComponent );
begin
  inherited Create( AOwner );

  FFiles := TStringList.Create;
  FSelections := TStringList.Create;
  ShellList.OnDblClickOpen := ListDblClickOpen;
  OnHelp := FormHelp;
end;


{$IFDEF VCL60_OR_HIGHER}

procedure TRzShellOpenSaveForm.FormCreate(Sender: TObject);
begin
  ImageList1.Handle := ShellGetSystemImageList( iszLarge );
  ImageList1.ShareImages := True;
  // If ShareImages is done before assigning the handle, then the existing image list is also shared and not
  // correctly freed when overwritten by the assigning of the system image list handle.

  FPlacesList := TObjectList.Create;
  InitCustomPlaces;
end;


procedure TRzShellOpenSaveForm.InitCustomPlaces;
const
  cRegBasePlaces = 'Software\Microsoft\Windows\CurrentVersion\Policies\Comdlg32\Placesbar';
  cPlace = 'Place';
var
  I: Integer;
  RegDataInfo: TRegDataInfo;
  Reg: TRegistry;
  PlaceData: TRzPlaceData;
begin
  Reg := TRegistry.Create;
  try
    if Reg.OpenKey( cRegBasePlaces, False ) then
    begin
      // Go through all the places. Their key data will be:
      // REG_DWORD: A CSIDL value that identifies a folder.
      // REG_SZ or REG_EXPAND_SZ: A null-terminated string that specifies a valid path.

      for I := 0 to 4 do
      begin
        if Reg.ValueExists( cPlace + IntToStr( I ) ) and
           Reg.GetDataInfo( cPlace + IntToStr( I ), RegDataInfo ) then
        begin
          if RegDataInfo.RegData in [ rdString, rdExpandString ] then
          begin
            // The folder is a valid path, so add a string
            PlaceData := TRzPlaceData.Create( Reg.ReadString( cPlace + IntToStr( I ) ) );
            FPlacesList.Add( PlaceData );
          end
          else // It is a CSIDL to id the folder, so add a idl
          begin
            PlaceData := TRzPlaceData.Create( TCSIDL( Reg.ReadInteger( cPlace + IntToStr( I ) ) ) );
            FPlacesList.Add( PlaceData );
          end;
        end;
      end;
    end
    else
    begin
      PlaceData := TRzPlaceData.Create( csidlRecent );
      PlaceData.Caption:='最近文档';
      FPlacesList.Add( PlaceData );

      PlaceData := TRzPlaceData.Create( csidlDesktop );
      FPlacesList.Add( PlaceData );

      PlaceData := TRzPlaceData.Create( csidlPersonal );
      FPlacesList.Add( PlaceData );

      PlaceData := TRzPlaceData.Create( csidlDrives );
      FPlacesList.Add( PlaceData );

      PlaceData := TRzPlaceData.Create( csidlNetwork );
      FPlacesList.Add( PlaceData );
    end;


    btnPlace0.Caption := TRzPlaceData( FPlacesList[ 0 ] ).Caption;
    btnPlace0.ImageIndex := TRzPlaceData( FPlacesList[ 0 ] ).ImageIndex;

    btnPlace1.Caption := TRzPlaceData( FPlacesList[ 1 ] ).Caption;
    btnPlace1.ImageIndex := TRzPlaceData( FPlacesList[ 1 ] ).ImageIndex;

    btnPlace2.Caption := TRzPlaceData( FPlacesList[ 2 ] ).Caption;
    btnPlace2.ImageIndex := TRzPlaceData( FPlacesList[ 2 ] ).ImageIndex;

    btnPlace3.Caption := TRzPlaceData( FPlacesList[ 3 ] ).Caption;
    btnPlace3.ImageIndex := TRzPlaceData( FPlacesList[ 3 ] ).ImageIndex;

    btnPlace4.Caption := TRzPlaceData( FPlacesList[ 4 ] ).Caption;
    btnPlace4.ImageIndex := TRzPlaceData( FPlacesList[ 4 ] ).ImageIndex;

  finally
    Reg.Free;
  end;

end;

{$ELSE}

procedure TRzShellOpenSaveForm.FormCreate(Sender: TObject);
var
  IdList: PItemIdList;
begin
  {$IFDEF VCL90_OR_HIGHER}
  PopupMode := pmAuto;
  {$ENDIF}

  ImageList1.Handle := ShellGetSystemImageList( iszLarge );
  ImageList1.ShareImages := True;
  // If ShareImages is done before assigning the handle, then the existing image list is also shared and not
  // correctly freed when overwritten by the assigning of the system image list handle.

  ShellGetSpecialFolderIdList( 0, csidlRecent, IdList );
  btnPlace0.Caption := ShellGetFriendlyNameFromIdList( nil, IdList, fnNormal );
  btnPlace0.ImageIndex := ShellGetSpecialFolderIconIndex( csidlRecent, 0 );

  ShellGetSpecialFolderIdList( 0, csidlDesktop, IdList );
  btnPlace1.Caption := ShellGetFriendlyNameFromIdList( nil, IdList, fnNormal );
  btnPlace1.ImageIndex := ShellGetSpecialFolderIconIndex( csidlDesktop, 0 );

  ShellGetSpecialFolderIdList( 0, csidlPersonal, IdList );
  btnPlace2.Caption := ShellGetFriendlyNameFromIdList( nil, IdList, fnNormal );
  btnPlace2.ImageIndex := ShellGetSpecialFolderIconIndex( csidlPersonal, 0 );

  ShellGetSpecialFolderIdList( 0, csidlDrives, IdList );
  btnPlace3.Caption := ShellGetFriendlyNameFromIdList( nil, IdList, fnNormal );
  btnPlace3.ImageIndex := ShellGetSpecialFolderIconIndex( csidlDrives, 0 );

  ShellGetSpecialFolderIdList( 0, csidlNetwork, IdList );
  btnPlace4.Caption := ShellGetFriendlyNameFromIdList( nil, IdList, fnNormal );
  btnPlace4.ImageIndex := ShellGetSpecialFolderIconIndex( csidlNetwork, 0 );
end;

{$ENDIF}


procedure TRzShellOpenSaveForm.DoTranslation;

  function IMax( a, b: Integer ): Integer;
  begin
    if ( a>b ) then
      Result := a
    else
      Result := b;
  end;

var
  x: Integer;
begin
  CancelBtn.Caption := SCancelButton;
  HelpBtn.Caption := SHelpButton;
  UpOneLevelBtn.Hint := SUpOneLevelHint;
  CreateNewFolderBtn.Hint := SCreateNewFolderHint;

  ListBtn.Hint := SViewListHint + '|' + SViewListContext;
  DetailsBtn.Hint := SViewDetailsHint + '|' + SViewDetailsContext;

  ReadOnlyChk.Caption := SOpenAsReadOnly;
  FileNameTxt.Caption := SFileName;
  ShowTreeBtn.Hint := SShowTreeHint;

  {It is the responsibility of the caller to translate LookInTxt, FilesOfTypesTxt, OpenBtn and the
   form's title itSelf.}
  View1Mitm.Caption := SViewMenu;
  View1Mitm.Hint := SViewContext;

  LargeIcons1Mitm.Caption := SViewLargeIconsMenu;
  LargeIcons1Mitm.Hint := SViewLargeIconsContext;

  SmallIcons1Mitm.Caption := SViewSmallIconsMenu;
  SmallIcons1Mitm.Hint := SViewSmallIconsContext;

  List1Mitm.Caption := SViewListMenu;
  List1Mitm.Hint := SViewListContext;

  Details1Mitm.Caption := SViewDetailsMenu;
  Details1Mitm.Hint := SViewDetailsContext;

  Paste1Mitm.Caption := SEditPasteMenu;
  Paste1Mitm.Hint := SPasteContext;

  New1Mitm.Caption := SNewMenu;
  New1Mitm.Hint := SNewPopupContext;

  Folder1Mitm.Caption := SNewFolderMenu;
  Folder1Mitm.Hint := SCreateFolderContext;

  Properties1Mitm.Caption := SPropertiesMenu;
  Properties1Mitm.Hint := SPropertiesContext;

   // Adjust controls for different language text lengths
  x := IMax( FilesOfTypeTxt.BoundsRect.Right, FileNameTxt.BoundsRect.Right ) + 8;

  with FileTypesCbx.BoundsRect do
    FileTypesCbx.BoundsRect := Rect( x, Top, Right, Bottom );
  with FileNameEdt.BoundsRect do
    FileNameEdt.BoundsRect := Rect( x, Top, Right, Bottom );
  with ReadOnlyChk.BoundsRect do
    ReadOnlyChk.BoundsRect := Rect( x, Top, Right, Bottom );

end; {= TRzShellOpenSaveForm.DoTranslation =}


destructor TRzShellOpenSaveForm.Destroy;
begin
  {$IFDEF VCL60_OR_HIGHER}
  FPlacesList.Free;
  {$ENDIF}
  FSelections.Free;
  FFiles.Free;
  inherited;
end;


procedure TRzShellOpenSaveForm.CreateWnd;
begin
  inherited;
  // Create the size-grip in the bottom right corner of the window.
  FHGripWindow := CreateWindowEx( WS_EX_LEFT or WS_EX_LTRREADING or WS_EX_RIGHTSCROLLBAR, 'SCROLLBAR', '',
                                  WS_CHILDWINDOW or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or SBS_SIZEGRIP,
                                  ClientRect.Right-SIZEGRIP_SIZE, ClientRect.Bottom-SIZEGRIP_SIZE,
                                  SIZEGRIP_SIZE, SIZEGRIP_SIZE, Handle, 0,HInstance, nil );

  SetWindowPos( FHGripWindow, HWND_TOP, 0,0,0,0, SWP_NOSIZE or SWP_NOMOVE );
end;


procedure TRzShellOpenSaveForm.InitFraming( FrameColor: TColor; FrameStyle: TFrameStyle;
                                            FrameVisible: Boolean;
                                            FramingPreference: TFramingPreference );
begin
  ShellCombo.FrameColor := FrameColor;
  ShellCombo.FrameStyle := FrameStyle;
  ShellCombo.FrameVisible := FrameVisible;
  ShellCombo.FlatButtons := FrameVisible;
  ShellCombo.FramingPreference := FramingPreference;

  ShellTree.FrameColor := FrameColor;
  ShellTree.FrameStyle := FrameStyle;
  ShellTree.FrameVisible := FrameVisible;
  ShellTree.FramingPreference := FramingPreference;

  ShellList.FrameColor := FrameColor;
  ShellList.FrameStyle := FrameStyle;
  ShellList.FrameVisible := FrameVisible;
  ShellList.FramingPreference := FramingPreference;

  FileNameCbx.FrameColor := FrameColor;
  FileNameCbx.FrameStyle := FrameStyle;
  FileNameCbx.FrameVisible := FrameVisible;
  FileNameCbx.FlatButtons := FrameVisible;
  FileNameCbx.FramingPreference := FramingPreference;

  FileNameEdt.FrameColor := FrameColor;
  FileNameEdt.FrameStyle := FrameStyle;
  FileNameEdt.FrameVisible := FrameVisible;
  FileNameEdt.FramingPreference := FramingPreference;

  FileTypesCbx.FrameColor := FrameColor;
  FileTypesCbx.FrameStyle := FrameStyle;
  FileTypesCbx.FrameVisible := FrameVisible;
  FileTypesCbx.FlatButtons := FrameVisible;
  FileTypesCbx.FramingPreference := FramingPreference;
end;


procedure TRzShellOpenSaveForm.InitHotTracking( ButtonColor: TColor;
                                                HotTrack: Boolean; HighlightColor: TColor;
                                                HotTrackColor: TColor;
                                                HotTrackColorType: TRzHotTrackColorType );
begin
  ReadOnlyChk.HotTrack := HotTrack;
  ReadOnlyChk.HighlightColor := HighlightColor;
  ReadOnlyChk.HotTrackColor := HotTrackColor;
  ReadOnlyChk.HotTrackColorType := HotTrackColorType;

  OpenBtn.Color := ButtonColor;
  OpenBtn.HotTrack := HotTrack;
  OpenBtn.HighlightColor := HighlightColor;
  OpenBtn.HotTrackColor := HotTrackColor;
  OpenBtn.HotTrackColorType := HotTrackColorType;

  CancelBtn.Color := ButtonColor;
  CancelBtn.HotTrack := HotTrack;
  CancelBtn.HighlightColor := HighlightColor;
  CancelBtn.HotTrackColor := HotTrackColor;
  CancelBtn.HotTrackColorType := HotTrackColorType;

  HelpBtn.Color := ButtonColor;
  HelpBtn.HotTrack := HotTrack;
  HelpBtn.HighlightColor := HighlightColor;
  HelpBtn.HotTrackColor := HotTrackColor;
  HelpBtn.HotTrackColorType := HotTrackColorType;
end;


//  Respond to view menu or view button click. Update state of menu and buttons so they remain synchronised.

procedure TRzShellOpenSaveForm.ViewBtnClick( Sender: TObject );
var
  Tag: Integer;

  procedure CheckItems( a: array of TComponent;  prop: Shortstring );
  var i: Integer;
  begin
    for i := Low( a ) to High( a ) do
      SetOrdProp( a[i], GetPropInfo( a[i].ClassInfo, prop ), Integer( a[i].Tag=tag ) );
  end;

begin
  tag := ( sender as TComponent ).Tag;
  ShellList.ViewStyle := TViewStyle( tag );
  CheckItems( [ListBtn, DetailsBtn], 'Down' );
  CheckItems( [LargeIcons1Mitm, SmallIcons1Mitm, List1Mitm, Details1Mitm], 'Checked' );
end;


procedure TRzShellOpenSaveForm.ListDblClickOpen( Sender: TObject; var Handled: Boolean );
begin
  ModalResult := mrOk;
  Handled := True;
end;


procedure TRzShellOpenSaveForm.WMGetMinMaxInfo( var Msg: TWMGetMinMaxInfo );
begin
  Msg.minMaxInfo.ptMinTrackSize := Point( 463, 274 );
end;


procedure TRzShellOpenSaveForm.DoOnFormClose;
begin
  if Assigned( FOnFormClose ) then
    FOnFormClose( Self );
end;


procedure TRzShellOpenSaveForm.DoOnFolderChanged;
begin
  if Assigned( FOnFolderChanged ) then
    FOnFolderChanged( Self );
end;


procedure TRzShellOpenSaveForm.DoOnSelectionChanged;
begin
  if Assigned( FOnSelectionChanged ) then
    FOnSelectionChanged( Self );
end;


procedure TRzShellOpenSaveForm.DoOnFormShow;
begin
  if Assigned( FOnFormShow ) then
    FOnFormShow( Self );
end;


procedure TRzShellOpenSaveForm.DoOnTypeChanged;
begin
  if Assigned( FOnTypeChanged ) then
    FOnTypeChanged( Self );
end;


function TRzShellOpenSaveForm.GetFilename: string;
begin
  if Executing then
  begin
    GetSelectedFiles( FFiles );
    if FFiles.Count>0 then
      Result := FFiles[0]
    else
      Result := '';
  end
  else
    Result := FileNameEdt.Text;
end;


function TRzShellOpenSaveForm.GetFiles: TStrings;
begin
  GetSelectedFiles( FFiles );
  Result := FFiles;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -