'Module Name : mComboSetWidth
'By : Giorgio Vidali
'Copyright : © 1999 Giorgio Vidali & Automated Business Designs, Inc.
'Description : Contains functions to return/set the width of
' dropdown portion of a standard combobox control
'Created : 08-Oct-99 8:58:39 AM
'Last Update : 08-Oct-99 8:58:39 AM
'History : ABD - 08-Oct-99 8:58:39 AM - First Release
'Properties : n.a.
'Methods : ComboGetDropdownWidth
' ComboSetDropdownWidth
'Sample Calls : long_value = ComboGetDropdownWidth(cboHwnd:=Combo1)
' bool_value = ComboSetDropdownWidth(cboHwnd:=Combo1,NewWidthPixel:=250)
'------------------------------------------------------------------------------------------
Option Explicit
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_GETDROPPEDWIDTH As Long = &H15F
Private Const CB_SETDROPPEDWIDTH As Long = &H160
Private Const CB_ERR As Long = -1
Public Function ComboGetDropdownWidth(cboHwnd As Long) As Long
'To get the combo box drop-down width.
'use this function if you want
'to change the width in proportion
'i.e. double, half, 3/4 of existing width.
'NOTE: return value is in PIXELS
Dim lRetVal As Long
lRetVal = SendMessage(cboHwnd, CB_GETDROPPEDWIDTH, 0, 0)
If lRetVal <> CB_ERR Then
ComboGetDropdownWidth = lRetVal
Else
ComboGetDropdownWidth = 0
End If
End Function
Public Function ComboSetDropdownWidth(cboHwnd As Long, NewWidthPixel As Long) As Boolean
'Set combo box drop-down width
'to new value specified in passed parm
Dim lRetVal As Long
lRetVal = SendMessage(cboHwnd, CB_SETDROPPEDWIDTH, NewWidthPixel, 0)
If lRetVal <> CB_ERR Then
ComboSetDropdownWidth = True
Else
ComboSetDropdownWidth = False
End If
End Function