tagCANDY CGI VBレスキュー(花ちゃん)の Visual Basic 6.0用 掲示板
VBレスキュー(花ちゃん)の Visual Basic 6.0用 掲示板
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re^4: ListItemsコレクションのIcon番号を取得
投稿日: 2009/05/12(Tue) 16:09
投稿者ganchan
魔界の仮面弁士さん。投稿ありがとうございます。
> う〜む、それは「何故」ですか、と聞いていたつもりなのですけれども。
> 繰り返しの逆質問になりますが、API に変更しなければならない事情とは何でしょうか?
操作の中でImageListのあるIndex番号のIconを変更しないといけないのが1つの理由です。
APIを使わないで変更する場合は
    ListView1.Icons = Nothing
    ImageList1.ListImages.Remove (1)
    Set imgX = ImageList1.ListImages.Add(1, imgXKey, ipic)                        
    ListView1.Icons = ImageList1
のコードを実行するのですが、NotingによりListViewのTextのIconが解除されるからです。
また、ソートのためにサブクラス化をつっかているのですが、ここの中のコードはAPIでしたい
からです。最後に今後の新しい仕様で対応しやすいと言う点です。
現在、ImageListの作成、Iconの登録まではAPIで作りました。ListViewとImageListとの関連
付けでストップしています。そのコードを下に記載します。
<Module>
' ハンドル
Public hndImgLstLVL As Long     'ListView LargeIcon用
Public hndImgLstLVS As Long     'ListView SmallIcon用
Public hndImgLstTV As Long      'TreeView用
Public hndListView As Long
Public hndTreeView As Long
' インデックス
Public IndxImgLstLVL As Long    'ListView LargeIcon用
Public IndxImgLstLVS As Long    'ListView SmallIcon用
Public IndxImgLstTV As Long     'TreeView用
' カウンタ
Public CntImgLstLVL As Long     'ListView LargeIcon用
Public CntImgLstLVS As Long     'ListView SmallIcon用
Public CntImgLstTV As Long      'TreeView用
' 定数
Public Const LVM_FIRST = &H1000
Public Const LVM_SETIMAGELIST = (LVM_FIRST + 3)  
Public Const LVSIL_NORMAL = 0
Public Const LVSIL_SMALL = 1
Public Const LVSIL_STATE = 2
' 関数
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _
  As Long
' サブ関数
Public Function ListView_DeleteAllItems(hwnd As Long) As Boolean
    ListView_DeleteAllItems = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0)
End Function
Public Function ListView_SetImageList(hwnd As Long, himl As Long, _
                                                  iImage As Long) As Long
    ListView_SetImageList = SendMessage(hwnd, LVM_SETIMAGELIST, ByVal iImage, _  
                                                  ByVal himl)
End Function

<Form_load>
    Dim Icon_Full As String
    Dim imgX As ListImage
    Dim imgXCnt As Integer
    Dim imgXKey As String
    Dim colX As ColumnHeader
    Dim colL As ListItem
    Dim nodX As Node
    Dim SHFI As SHFILEINFO
    Dim ipic As IPictureDisp
    Icon_Path = "C:\TacilityLedger\icons\"
    hndImgLstLVL = ImageList_Create(32, 32, ILC_MASK Or ILC_COLOR8, 3, 0)
    If hndImgLstLVL = 0 Then
        msgbox_msg = "イメージリスト(ListView LargeIcon)のハンドルを取得できません。"
        msgbox_ret = MsgBox(msgbox_msg, 48, "エラーメッセージ")
    Else
        Icon_Full = Icon_Path + "MAINICON.ICO"
        IndxImgLstLVL = ImageList_ReplaceIcon(hndImgLstLVL, -1, _
                                                      LoadPictureIcon_Full))
        Icon_Full = Icon_Path + "FOLDER.ICO"
        IndxImgLstLVL = ImageList_ReplaceIcon(hndImgLstLVL, -1, _
                                                      LoadPicture(Icon_Full))
        Icon_Full = Icon_Path + "Iconダミー.SCC"
        Ret = SHGetFileInfo(Icon_Full, FILE_ATTRIBUTES_NORMAL, SHFI, Len(SHFI), _
          SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON Or SHGFI_LARGEICON Or _
          SHGFI_DISPLAYNAME)
        Set ipic = IconToIPicture(SHFI.hIcon)
        IndxImgLstLVL = ImageList_ReplaceIcon(hndImgLstLVL, -1, ipic)
        CntImgLstLVL = ImageList_GetImageCount(hndImgLstLVL)
    End If
    hndImgLstLVS = ImageList_Create(16, 16, ILC_MASK Or ILC_COLOR8, 3, 0)
    If hndImgLstLVS = 0 Then
        msgbox_msg = "イメージリスト(ListView SmallIcon)のハンドルを取得できません。"
        msgbox_ret = MsgBox(msgbox_msg, 48, "エラーメッセージ")
    Else
        Icon_Full = Icon_Path + "MAINICON.ICO"
        IndxImgLstLVS = ImageList_ReplaceIcon(hndImgLstLVS, -1, _
                                                       LoadPicture(Icon_Full))
        Icon_Full = Icon_Path + "FOLDER.ICO"
        IndxImgLstLVS = ImageList_ReplaceIcon(hndImgLstLVS, -1, _
                                                       LoadPicture(Icon_Full))
        Icon_Full = Icon_Path + "Iconダミー.SCC"
        Ret = SHGetFileInfo(Icon_Full, FILE_ATTRIBUTES_NORMAL, SHFI, Len(SHFI), _
                               SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON Or _
                               SHGFI_SMALLICON)
        Set ipic = IconToIPicture(SHFI.hIcon)
        IndxImgLstLVS = ImageList_ReplaceIcon(hndImgLstLVS, -1, ipic)
        CntImgLstLVS = ImageList_GetImageCount(hndImgLstLVS)
    End If
    ListView1.Arrange = lvwAutoTop
   hndListView = ListView1.hwnd
    bRet = ListView_DeleteAllItems(hndListView)
    Ret = ListView_SetImageList(hndListView, 0, LVSIL_NORMAL)
    Ret = ListView_SetImageList(hndListView, 0, LVSIL_SMALL)
    Form1.ListView1.View = lvwReport
    Form1.ListView1.Font.Name = "MS 明朝"
    Form1.ListView1.Font.Size = 9
    Form1.ListView1.Font.Bold = False
    Form1.ListView1.Font.Italic = False
    Ret = ListView_SetImageList(hndListView, hndImgLstLVL, LVSIL_NORMAL)
    Ret = ListView_SetImageList(hndListView, hndImgLstLVS, LVSIL_SMALL)
変数のRetがすべてゼロです。後はうまくいっているようです。
本題と少しずれましたが、よろしくお願いします。

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。