- PR -

Windowsエクスプローラ風のListView

投稿者投稿内容
Yun
常連さん
会議室デビュー日: 2007/01/25
投稿数: 22
投稿日時: 2007-02-20 16:14
ありがとうございます。

皆様すばらしいですね・・・。
.NETのライブラリだけにらめっこしてたらいけないのかな。
ちょっとWindowsプログラミングに片足をつっこんだ気分でした。
修行あるのみです。

*** 改訂版 ***
Imports System.Runtime.InteropServices

Public Class MyListView
Inherits ListView

Private Const LVM_GETHEADER As UInteger = 4127
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function GetClientRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure

Private _headerHeight As Integer

Public Sub New()
MyBase.New()
View = Windows.Forms.View.Details
Columns.Add("aaa")
Columns.Add("bbb")

Dim hc As IntPtr = SendMessage(Me.Handle, LVM_GETHEADER, 0, 0)
Dim r As New RECT
GetClientRect(hc, r)
_headerHeight = r.bottom
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_CONTEXTMENU As Integer = &H7B

MyBase.WndProc(m)

if m.Msg = WM_CONTEXTMENU

Dim x As Long = m.LParam.ToInt64 And &HFFFF&
Dim y As Long = m.LParam.ToInt64 \ &H10000 And &HFFFF&

Dim p As New Point(CInt(x), CInt(y))
p = PointToClient(p)

If p.Y <= _headerHeight Then
MsgBox("ColumnHeader 右クリック!")
End If
End If
End Sub

End Class

スキルアップ/キャリアアップ(JOB@IT)