Imports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows フォーム デザイナで生成されたコード " Public Sub New() MyBase.New() ' この呼び出しは Windows フォーム デザイナで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後に初期化を追加します。 End Sub ' Form は dispose をオーバーライドしてコンポーネント一覧を消去します。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。 ' Windows フォーム デザイナを使って変更してください。 ' コード エディタは使用しないでください。 Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Private Sub InitializeComponent() Me.PictureBox1 = New System.Windows.Forms.PictureBox() Me.SuspendLayout() ' 'PictureBox1 ' Me.PictureBox1.Location = New System.Drawing.Point(40, 40) Me.PictureBox1.Name = "PictureBox1" Me.PictureBox1.Size = New System.Drawing.Size(104, 80) Me.PictureBox1.TabIndex = 0 Me.PictureBox1.TabStop = False ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PictureBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' アプリケーション・アイコンを取得 Dim shinfo As New SHFILEINFO() Dim hSuccess As IntPtr = SHGetFileInfo("C:\WINDOWS\notepad.exe", 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON Or SHGFI_LARGEICON) If hSuccess.Equals(IntPtr.Zero) = False Then Dim appIcon As Icon = Icon.FromHandle(shinfo.hIcon) ' ピクチャーボックスにアプリケーション・アイコンをセット Me.PictureBox1.Image = appIcon.ToBitmap() End If End Sub #Region "アイコン取得用のWin32 API" ' SHGetFileInfo関数 Private Declare Ansi Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr ' SHGetFileInfo関数で使用するフラグ Private Const SHGFI_ICON As Integer = &H100 ' アイコン・リソースの取得 Private Const SHGFI_LARGEICON As Integer = &H0 ' 大きいアイコン Private Const SHGFI_SMALLICON As Integer = &H1 ' 小さいアイコン ' SHGetFileInfo関数で使用する構造体 Private Structure SHFILEINFO Public hIcon As IntPtr Public iIcon As IntPtr Public dwAttributes As Integer _ Public szDisplayName As String _ Public szTypeName As String End Structure #End Region End Class