'I Just included comments on every important lines.Sorry for my bad english.
'I developed this program by converting the C Documentation to VB and experiments with VB.
'You can improve this program by your experiments.I didn't done all parts of the
'ComboBoxEx.
Option Explicit
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Const WS_BORDER = &H800000
Public Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
Public Const WS_CHILD = &H40000000
Public Const WS_CLIPCHILDREN = &H2000000
Public Const WS_CLIPSIBLINGS = &H4000000
Public Const WS_DISABLED = &H8000000
Public Const WS_DLGFRAME = &H400000
Public Const WS_EX_ACCEPTFILES = &H10&
Public Const WS_EX_DLGMODALFRAME = &H1&
Public Const WS_EX_NOPARENTNOTIFY = &H4&
Public Const WS_EX_TOPMOST = &H8&
Public Const WS_EX_TRANSPARENT = &H20&
Public Const WS_GROUP = &H20000
Public Const WS_HSCROLL = &H100000
Public Const WS_MAXIMIZE = &H1000000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_MINIMIZE = &H20000000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_OVERLAPPED = &H0&
Public Const WS_POPUP = &H80000000
Public Const WS_SYSMENU = &H80000
Public Const WS_TABSTOP = &H10000
Public Const WS_THICKFRAME = &H40000
Public Const WS_VISIBLE = &H10000000
Public Const WS_VSCROLL = &H200000
Public Const WS_POPUPWINDOW = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Public Const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wparam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const GWL_EXSTYLE = (-20)
Public Const GWL_HWNDPARENT = (-8)
Public Const GWL_ID = (-12)
Public Const GWL_STYLE = (-16)
Public Const GWL_USERDATA = (-21)
Public Const GWL_WNDPROC = (-4)
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wparam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wparam As Long, lParam As Any) As Long
Public Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
Public Type WNDCLASS
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const MIN_COMBOCX = 113
Public Const MIN_COMBOCY = 42
'//====== COMMON CONTROL STYLES ================================================
Public Const CCS_TOP = &H1 'L
Public Const CCS_NOMOVEY = &H2 'L
Public Const CCS_BOTTOM = &H3 'L
Public Const CCS_NORESIZE = &H4 'L
Public Const CCS_NOPARENTALIGN = &H8 'L
Public Const CCS_ADJUSTABLE = &H20 'L
Public Const CCS_NODIVIDER = &H40 'L
#If WIN32_IE >= &H300 Then
Public Const CCS_VERT = &H80 'L
Public Const CCS_LEFT = (CCS_VERT Or CCS_TOP)
Public Const CCS_RIGHT = (CCS_VERT Or CCS_BOTTOM)
Public Const CCS_NOMOVEX = (CCS_VERT Or CCS_NOMOVEY)
#End If
'/*
' * Combo Box styles
' */
Public Const CBS_SIMPLE = &H1
Public Const CBS_DROPDOWN = &H2
Public Const CBS_DROPDOWNLIST = &H3
Public Const CBS_OWNERDRAWFIXED = &H10
Public Const CBS_OWNERDRAWVARIABLE = &H20
Public Const CBS_AUTOHSCROLL = &H40
Public Const CBS_OEMCONVERT = &H80
Public Const CBS_SORT = &H100
Public Const CBS_HASSTRINGS = &H200
Public Const CBS_NOINTEGRALHEIGHT = &H400
Public Const CBS_DISABLENOSCROLL = &H800
#If (WINVER >= &H400) Then
Public Const CBS_UPPERCASE = &H2000
Public Const CBS_LOWERCASE = &H4000
#End If '/* WINVER >= =&h0400 */
Public Const CB_SETCURSEL = &H14E
Public Const CB_ADDSTRING = &H143
'Public Const CB_DELETESTRING = &H144
Public Const CB_DIR = &H145
Public Const CB_ERR = (-1)
Public Const CB_ERRSPACE = (-2)
Public Const CB_FINDSTRING = &H14C
Public Const CB_FINDSTRINGEXACT = &H158
Public Const CB_GETCOUNT = &H146
Public Const CB_GETCURSEL = &H147
Public Const CB_GETDROPPEDCONTROLRECT = &H152
Public Const CB_GETDROPPEDSTATE = &H157
Public Const CB_GETEDITSEL = &H140
Public Const CB_GETEXTENDEDUI = &H156
Public Const CB_GETITEMDATA = &H150
Public Const CB_GETITEMHEIGHT = &H154
Public Const CB_GETLBTEXT = &H148
Public Const CB_GETLBTEXTLEN = &H149
Public Const CB_GETLOCALE = &H15A
Public Const CB_INSERTSTRING = &H14A
Public Const CB_LIMITTEXT = &H141
Public Const CB_MSGMAX = &H15B
Public Const CB_OKAY = 0
Public Const CB_RESETCONTENT = &H14B
Public Const CB_SELECTSTRING = &H14D
'Public Const CB_SETCURSEL = &H14E
Public Const CB_SETEDITSEL = &H142
Public Const CB_SETEXTENDEDUI = &H155
Public Const CB_SETITEMDATA = &H151
Public Const CB_SETITEMHEIGHT = &H153
Public Const CB_SETLOCALE = &H159
Public Const CB_SHOWDROPDOWN = &H14F
Public Const CBN_CLOSEUP = 8
Public Const CBN_DBLCLK = 2
Public Const CBN_DROPDOWN = 7
Public Const CBN_EDITCHANGE = 5
Public Const CBN_EDITUPDATE = 6
Public Const CBN_ERRSPACE = (-1)
Public Const CBN_KILLFOCUS = 4
Public Const CBN_SELCHANGE = 1
Public Const CBN_SELENDCANCEL = 10
Public Const CBN_SELENDOK = 9
Public Const CBN_SETFOCUS = 3
'Public Const CBS_AUTOHSCROLL = &H40&
'Public Const CBS_DISABLENOSCROLL = &H800&
'Public Const CBS_DROPDOWN = &H2&
'Public Const CBS_DROPDOWNLIST = &H3&
'Public Const CBS_HASSTRINGS = &H200&
'Public Const CBS_NOINTEGRALHEIGHT = &H400&
'Public Const CBS_OEMCONVERT = &H80&
'Public Const CBS_OWNERDRAWFIXED = &H10&
'Public Const CBS_OWNERDRAWVARIABLE = &H20&
'Public Const CBS_SIMPLE = &H1&
'Public Const CBS_SORT = &H100&
Public Const WM_COMMAND = &H111
'Global Window Handle & Windowprocedure Handle
Public Wnd As Long, OldProc As Long
Function CreateComboBoxEx(ByVal hwnd As Long) As Long
'This is the main function.It Creates a ComboBoxEx window and returns the window handle
'You can modify this function by including Coordinate Parameters,style etc.
Function GetItem(cbi As COMBOBOXEXITEMA, Optional ByVal idx As Long = -1) As Long
'Gets an item's information
' Dim cbi As COMBOBOXEXITEMA
With cbi
.mask = CBEIF_TEXT Or CBEIF_IMAGE Or CBEIF_SELECTEDIMAGE Or CBEIF_INDENT
.pszText = Space$(260)
.cchTextMax = Len(.pszText)
.iItem = idx '-1
.iImage = 0 '0 ' Image to display
.iSelectedImage = 0 '0 ' Image to display
.iIndent = 0
End With
GetItem = SendMessage(Wnd, CBEM_GETITEMA, 0, cbi)
'Returns nonzero if successful, or zero otherwise.
'When the message is sent, the iItem and mask members of the structure must be set to indicate the index of the target item and the type of information to be retrieved. Other members are set as needed. For example, to get text, you must set the CBEIF_TEXT flag in mask, and assign a value to cchTextMax. Setting the iItem member to -1 will retrieve the item displayed in the edit control.
End Function
Function GetItemText(Optional ByVal idx As Long = -1) As String