GetComboBoxInfo API を使ってテストしてみましょう。

フォームに Button と ComboBox を貼り付けて以下のように記述します。
GCSafeHandle の Target プロパティを参照すると API から受け取った値を見ることができます。

COMBOBOXINFO をクラスとして宣言してすれば ObjPtr を使って処理できます。

Imports VB6Control
Imports System.Runtime.InteropServices

Public Class VarPtrTestForm

    <DllImport("user32.dll")>
    Public Shared Function GetComboBoxInfo(ByVal hWnd As IntPtr, ByVal pcbi As SafeHandle) As Boolean
    End Function

    <StructLayout(LayoutKind.Sequential)>
    Public Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
        Public Overrides Function ToString() As String
            Return String.Format("Left={0}, Top={1}, Right={2}, Bottom={3}", Me.Left, Me.Top, Me.Right, Me.Bottom)
        End Function
    End Structure

    <StructLayout(LayoutKind.Sequential)>
    Public Structure COMBOBOXINFO
        Public cbSize As Integer
        Public rcItem As RECT
        Public rcButton As RECT
        Public buttonState As Integer
        Public hwndCombo As IntPtr
        Public hwndEdit As IntPtr
        Public hwndList As IntPtr
        Public Overrides Function ToString() As String
            Return String.Format("cbSize={0}, rcItem=({1}), rcButton=({2}), buttonState={3}, hwndCombo={4}, hwndEdit={5}, hwndList={6}",
                                 Me.cbSize, Me.rcItem, Me.rcButton, Me.buttonState, Me.hwndCombo, Me.hwndEdit, Me.hwndList)
        End Function
    End Structure

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim info As New COMBOBOXINFO()
        info.cbSize = Marshal.SizeOf(GetType(COMBOBOXINFO))
        Dim handle As GCSafeHandle = VarPtr(info)
        GetComboBoxInfo(ComboBox1.Handle, handle)
        Debug.Print("ComboBofInfo=[{0}]", handle.Target)
    End Sub

End Class



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2017-05-19 (金) 10:39:47 (158d)