コンボボックスのエディットの選択範囲を指定          <TOP>


SendMessage 指定のウィンドウにメッセージを送る

CB_SETEDITSEL(&H142) コンボボックスのエディットコントロールで選択文字を設定する
CB_SHOWDROPDOWN(&H14F) コンボボックスのリストボックスの表示または非表示を切り替える

 

'================================================================
'= コンボボックスのエディットの選択範囲を指定
'=    (CB_SETEDITSEL.bas)
'================================================================
#include "Windows.bi"

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

#define CB_SETEDITSEL &H142             'コンボボックスのエディットコントロールで選択文字を設定する
#define CB_SHOWDROPDOWN &H14F           'コンボボックスのリストボックスの表示または非表示を切り替える

Var Shared Edit(1) As Object
Var Shared Text(1) As Object
Var Shared Combo1 As Object
Var Shared Button1 As Object

Combo1.Attach GetDlgItem("Combo1") : Combo1.SetFontSize 14
For i = 0 To 1
    Edit(i).Attach GetDlgItem("Edit" & Trim$(Str$(i + 1))) : Edit(i).SetFontSize 14
    Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1))) : Text(i).SetFontSize 14
Next
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Function MAKELPARAM(ByVal Start As Byte, ByVal Length As Byte) As Long
Function MAKELPARAM(ByVal Start As Byte, ByVal Length As Byte) As Long
    '下位BYTE値と16ビット左シフトした上位BYTE値の論理和
    MAKELPARAM = CLng(Length) * (2 ^ 16) Or CLng(Start)
End Function

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Var mm(11) As String
    Var Ret As Long

    For i = 0 To 11
        Read mm(i)
        Combo1.AddString mm(i)
    Next

    'マウス砂時計解除
    SetMousePointer 0
    Ret = Api_SendMessage(Combo1.GethWnd, CB_SHOWDROPDOWN, 1, ByVal 0)

    Data "January ", "February", "March", "April", "May", "June"
    Data "July", "August", "September", "October", "November", "December"
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var Start As Long
    Var Length As Long
    Var SelRange As Long
    Var Ret As Long

    '選択範囲を指定
    Start = Val(Edit(0).GetWindowtext)
    Length = Start + Val(Edit(1).GetWindowText)

    '指定した選択範囲からLPARAMを生成
    SelRange = MAKELPARAM(CByte(Start), CByte(Length))

    '選択範囲を設定
    Ret = Api_SendMessage(Combo1.GethWnd, CB_SETEDITSEL, 0, ByVal SelRange)
End Sub

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