by 7 » 2006年1月17日(火) 21:34
> それでも引っかかります。
hWndはツリービューのハンドルをそこに書いて下さいという意味で書いただけなので、ツリービューのハンドルを書いて下さい。
tvHitTestInfoの型については、構造体の扱いを誤ってました。ポインタを渡す必要があるので下のように書き直してください。
コード: 全て選択
SendMessage(hWnd,TVM_HITTEST,NULL,VarPtr(tvHitTestInfo) As LPARAM)
> 下のようにするにはどうしたらいいですか?
>
MISSION
> Camp1
> 戦闘機
> 軽爆撃機
> 重爆撃機
> 艦船
> 地上部隊
> 地上物
> SetName
> Camp2
> 戦闘機
> 軽爆撃機
> 重爆撃機
> 艦船
> 地上部隊
> 地上物
> SetName
変数の識別名は勝手に変えちゃいました...(_ _)
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
Dim hTreeView As HWND
Dim tvi As TVINSERTSTRUCT
Dim hTreeItem As HANDLE
Dim hTreeChildItem As HANDLE
'ツリービューのハンドルを得る
hTreeView=GetDlgItem(hMainWnd,TreeView1)
'ルートの項目(アイテム)を追加する。
With tvi
.hParent =TVI_ROOT
.hInsertAfter =TVI_SORT
.item.mask =TVIF_TEXT
.item.pszText ="MISSION"
End With
hTreeItem=TreeView_InsertItem(hTreeView,tvi)
'子アイテムを追加する。
With tvi
'親(ルート)のハンドルを設定
.hParent =hTreeItem
.item.pszText="Camp1"
hTreeChildItem=TreeView_InsertItem(hTreeView,tvi)
'孫アイテムを追加する。
'親(子)ノードのハンドルを設定
.hParent =hTreeChildItem
.hInsertAfter =TVI_LAST
.item.pszText ="戦闘機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="軽爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="重爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="艦船"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上部隊"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上物"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="SetName"
TreeView_InsertItem(hTreeView,tvi)
End With
'子アイテムを追加する。
With tvi
'親(ルート)のハンドルを設定
.hParent =hTreeItem
.item.pszText="Camp2"
hTreeChildItem=TreeView_InsertItem(hTreeView,tvi)
'孫アイテムを追加する。
'親(子)ノードのハンドルを設定
.hParent =hTreeChildItem
.hInsertAfter =TVI_LAST
.item.pszText ="戦闘機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="軽爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="重爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="艦船"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上部隊"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上物"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="SetName"
TreeView_InsertItem(hTreeView,tvi)
End With
うまいコメントが思い付きません...。
所で、コードの動きをしっかりと理解していますか?
指定すべき値や戻り値をしっかりと把握していればスムーズに行くはずです。
でも、ツリービューは面倒ですよね。自分はフォルダの階層構造をツリービューに表示するのに悪戦苦闘しています...。
> それでも引っかかります。
hWndはツリービューのハンドルをそこに書いて下さいという意味で書いただけなので、ツリービューのハンドルを書いて下さい。
tvHitTestInfoの型については、構造体の扱いを誤ってました。ポインタを渡す必要があるので下のように書き直してください。
[code]SendMessage(hWnd,TVM_HITTEST,NULL,VarPtr(tvHitTestInfo) As LPARAM)[/code]
> 下のようにするにはどうしたらいいですか?
> [quote]MISSION
> Camp1
> 戦闘機
> 軽爆撃機
> 重爆撃機
> 艦船
> 地上部隊
> 地上物
> SetName
> Camp2
> 戦闘機
> 軽爆撃機
> 重爆撃機
> 艦船
> 地上部隊
> 地上物
> SetName[/quote]
変数の識別名は勝手に変えちゃいました...(_ _)
[hide][code]Dim hTreeView As HWND
Dim tvi As TVINSERTSTRUCT
Dim hTreeItem As HANDLE
Dim hTreeChildItem As HANDLE
'ツリービューのハンドルを得る
hTreeView=GetDlgItem(hMainWnd,TreeView1)
'ルートの項目(アイテム)を追加する。
With tvi
.hParent =TVI_ROOT
.hInsertAfter =TVI_SORT
.item.mask =TVIF_TEXT
.item.pszText ="MISSION"
End With
hTreeItem=TreeView_InsertItem(hTreeView,tvi)
'子アイテムを追加する。
With tvi
'親(ルート)のハンドルを設定
.hParent =hTreeItem
.item.pszText="Camp1"
hTreeChildItem=TreeView_InsertItem(hTreeView,tvi)
'孫アイテムを追加する。
'親(子)ノードのハンドルを設定
.hParent =hTreeChildItem
.hInsertAfter =TVI_LAST
.item.pszText ="戦闘機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="軽爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="重爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="艦船"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上部隊"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上物"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="SetName"
TreeView_InsertItem(hTreeView,tvi)
End With
'子アイテムを追加する。
With tvi
'親(ルート)のハンドルを設定
.hParent =hTreeItem
.item.pszText="Camp2"
hTreeChildItem=TreeView_InsertItem(hTreeView,tvi)
'孫アイテムを追加する。
'親(子)ノードのハンドルを設定
.hParent =hTreeChildItem
.hInsertAfter =TVI_LAST
.item.pszText ="戦闘機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="軽爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="重爆撃機"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="艦船"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上部隊"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="地上物"
TreeView_InsertItem(hTreeView,tvi)
.item.pszText ="SetName"
TreeView_InsertItem(hTreeView,tvi)
End With[/code][/hide]
うまいコメントが思い付きません...。
所で、コードの動きをしっかりと理解していますか?
指定すべき値や戻り値をしっかりと把握していればスムーズに行くはずです。
でも、ツリービューは面倒ですよね。自分はフォルダの階層構造をツリービューに表示するのに悪戦苦闘しています...。