お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"IShellDispatch コンポーネントラッパー"






■概要
 IShellDispatch コンポーネントラッパー( TShell ) を利用した簡単な
サンプルです。

■準備
 本サンプルを試す前に以下の手順に従い IShellDispatch のラッパーを
適当なコンポーネントパレットに登録して下さい。

 1. 新規アプリケーションを作成。
 2. [プロジェクト(P)] → [タイプライブラリの取り込み(L)]  を選択。

 表示されるタイプライブラリの取り込みダイアログ内の

 3.“Microsoft Shell Controls And Automation (Version 1.0) ” を
   選択し、"コンポーネントラッパーの作成(G)" チェックボックスを
   チェックし、"インストール(I)" ボタンを押して、適当なコンポー
   ネントパレットとパッケージに TShell 他を登録して下さい。

 ※SHDOCVW.DLL( Win95 + IE4.01 以降) または、SHDOC401.DLL ( Win98
  + IE5 以降) に定義されています。
 ※詳細はヘルプの目次より [COM アプリケーションの開発] → [オート
  メーションコントローラの作成] → [タイプライブラリのインポート
  によるオートメーションコントローラの作成] をご覧下さい。(D5)

■コンポーネント
 Form1 に Shell1(上記準備で登録した TShell ), Edit1, ComboBox1 と
Button1 を適当に配置して下さい。

■注意事項
 ・動作条件:Windows95 + IE4.01 以降。
 ・Windows98SE + IE5.5 + Delphi5 Pro で動作確認。
 ・本サンプルは、ご自身の責任においてお試し下さい。m(_"_)m

■その他
 nifty:FDELPHI/MES/16/1194 参照。

■サンプルコード
//=========================================================================
{...略...}
  private
    { Private 宣言 }
    procedure ShowBrowseForFolder;
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  ShlObj;
{*************************************************************************
   BrowseForFolder Dialog 表示
   ・Root --> マイ コンピュータ。
//***********************************************************************}
procedure TForm1.ShowBrowseForFolder;
const
  MyComputer = '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';
var
  fFolder: Folder;
  i      : Integer;
begin
  fFolder := nil;
  fFolder := Shell1.BrowseForFolder( Handle,
                                     'フォルダを選択して下さい',
                                              {BIF_EDITBOX or}
                                     BIF_RETURNFSANCESTORS or
                                      BIF_RETURNONLYFSDIRS,
                                                MyComputer   );
  if fFolder = nil then Exit;
  with fFolder.ParentFolder.Items do begin
    for i := 0 to Count - 1 do begin
      if Item(i).Name = fFolder.Title then
        begin
          Edit1.Text := Item(i).Path;
          Exit;
        end;{if Item(i).Name = fFolder.Title then}
    end;{for i := 0 to Count - 1 do}
  end;{with fFolder.ParentFolder.Items do}
end;
{*************************************************************************
   Button1 OnClick
//***********************************************************************}
procedure TForm1.Button1Click(Sender: TObject);
begin
  with Shell1 do begin
    case ComboBox1.ItemIndex of
      0: ShowBrowseForFolder;            // BrowseForFolder表示.
      1: Open( Edit1.Text );             // Edit1で指定されたFolderを開く.
      2: Explore( Edit1.Text );          // 指定FolderをExplorerで開く.
      3: MinimizeAll;                    // すべてのWindowを最小化.
      4: UndoMinimizeALL;                // 最小化したWindowを復元.
      5: FileRun;                        // File名指定実行Dialogを表示.
      6: ShutdownWindows;                // Shutdown Windows.
      7: Suspend;                        // Suspend.
      8: SetTime;                        // SetTime Dialog表示.
      9: TrayProperties;                 // TrayProperties Dialog表示.
     10: FindFiles;                      // FindFiles Dialog表示.
     11: FindComputer;                   // FindComputer Dialog表示.
     12: ControlPanelItem( Edit1.Text ); // Control Panel Applet起動.
    end;{case ComboBox1.ItemIndex of}
  end;{with Shell1 do}
end;
{*************************************************************************
   ComboBox1 OnClick
   ・コントロールパネルアプレットの例、"アプリケーションの追加と削除" を
     Edit1 にセット。
   ・Button1.Caption 変更。
//***********************************************************************}
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
  with ComboBox1 do begin
    if ItemIndex = 12 then Edit1.Text := 'Appwiz.cpl';
    Button1.Caption := Items[ ItemIndex ];
  end;{with ComboBox1 do}
end;
{*************************************************************************
   Form1 OnCreate
//***********************************************************************}
procedure TForm1.FormCreate(Sender: TObject);
begin
  with ComboBox1, Items do begin
    Add( 'BrowseForFolder' );
    Add( 'Open( Edit1.Text )' );
    Add( 'Explorer( Edit1.Text )' );
    Add( 'MinimizeAll' );
    Add( 'UndoMinimizeALL' );
    Add( 'FileRun' );
    Add( 'ShutdownWindows' );
    Add( 'Suspend' );
    Add( 'SetTime' );
    Add( 'TrayProperties' );
    Add( 'FindFiles' );
    Add( 'FindComputer' );
    Add( 'ControlPanelItem( Edit1.Text )' );
    ItemIndex := 0;
    Button1.Caption := 'BrowseForFolder';
  end;{with ComboBox1, Items do}
end;
{*************************************************************************
//***********************************************************************}
{...略...}
//=========================================================================

                              00/11/27(Mon) 11:17pm  Fermion [KHF03264]

 


- FDELPHI  MES(16):玉石混淆みんなで作るSample蔵【見本蓄積】 00/11/29 -

Original document by Fermion         氏 ID:(KHF03264)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum