コンボボックスの情報を取得          <TOP>


GetComboBoxInfo 指定したコンボボックスに関する情報を取得
SendMessage ウィンドウにメッセージを送信
SetWindowText ウィンドウのタイトルを変更
 

 

'================================================================
'= コンボボックスの情報を取得
'=    (GetComboBoxInfo.bas)
'================================================================
#include "Windows.bi"

#define CB_ADDSTRING &H143              'コンボボックスのリストボックスに文字列を追加する
#define CB_SETITEMDATA &H151            'アプリケーション定義の値を設定する

Type RECT
    Left   As Long
    Top    As Long
    Right  As Long
    Bottom As Long
End Type

Type COMBOBOXINFO
   cbSize       As Long
   rcItem       As RECT
   rcButton     As RECT
   stateButton  As Long
   hwndCombo    As Long
   hwndEdit     As Long
   hwndList     As Long
End Type

' 指定したコンボボックスに関する情報を取得
Declare Function Api_GetComboBoxInfo& Lib "user32" Alias "GetComboBoxInfo" (ByVal hwndCombo&, pcbi As COMBOBOXINFO)

' ウィンドウにメッセージを送信
Declare Function Api_SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg&, ByVal wParam&, lParam As Any)

' ウィンドウのタイトルを変更
Declare Function Api_SetWindowText& Lib "user32" Alias "SetWindowTextA" (ByVal hWnd&, ByVal lpString$)

Var Shared Combo1 As Object
Var Shared Button1 As Object
Var Shared Button2 As Object

Combo1.Attach GetDlgItem("Combo1") : Combo1.SetFontSize 12
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14
Button2.Attach GetDlgItem("Button2") : Button2.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var cbi As COMBOBOXINFO
    Var hEdit As Long
    Var Ret As Long 

    cbi.cbSize = Len(cbi)
    Ret = Api_GetComboBoxInfo(Combo1.GethWnd, cbi)

    hEdit = cbi.hwndEdit

    Ret = Api_SetWindowText(hEdit, "Edit Handle .." & Str$(hEdit))
   
    'Edit部のハンドルを追加
    Ret = Api_SendMessage(Combo1.GethWnd, CB_ADDSTRING, 0, "GetComboBoxInfo: Edit handle .." & Str$(hEdit))
End Sub

'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var cbi As COMBOBOXINFO
    Var hList As Long
    Var Ret As Long 

    cbi.cbSize = Len(cbi)
    Ret = Api_GetComboBoxInfo(Combo1.GethWnd, cbi)

    hList = cbi.hwndList

    'List部のハンドルを追加
    Ret = Api_SendMessage(Combo1.GethWnd, CB_ADDSTRING, 0, "GetComboBoxInfo: List handle .." & Str$(hList))
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End