Creates an Ocx ComboBox control in the current active form, window, or dialog.
Ocx ComboBox name [= text$] [, id] [, x, y, b, h] [, style%]
text$:control text
id%:control identifier
x, y, b, h:iexp
style%:the control styles
The control is a rectangle containing a list of strings (such as filenames) from which the user can select.
The ComboBox Ocx control has the following properties, methods, and events.
Appearance | BackColor | ForeColor | BorderStyle | Columns | DisableNoScroll | Enabled | Font | FontBold | FontItalic | FontStrikethru | FontUnderline | FontName | FontSize | Height, Width | HelpContextID | hWnd | Index | IntegralHeight |ItemData | Left, Top | List | ListCount | ListIndex | MouseCursor | MouseIcon | MousePointer | Name | NewIndex | Parent | Scrollbars | Selected | Sorted | Style | TabStop | Tag | Text | ToolTiptext | TopIndex | Visible | WhatsThisHelpID
AddItem | Clear | Find | FindExact | FindNext | InsertItem | Move | Refresh | RemoveItem | SetFocus | SetFont | TextHeight | TextWidth | ZOrder
Click | DblClick | GotFocus | LostFocus | KeyDown, KeyUp | KeyPress | MouseDown | MouseUp | MouseMove | Scroll
There is no event which covers every eventually of the selected item being changed as the Click event only occurs when an object in the dropdown list is selected by using the mouse or by the up and down arrow keys, which means that occurences of the selected item being changed by physically typing in the value are missed. In the absence of a dedicated Change event, you can embed a call to Click in the KeyUp event which will effectively make the Click take on this role.
The ComboBox object lacks some of the functionality that can be found in VB6 and most other programming languages which use it as an object; this can be overcome by using the SendMessage() API as follows:
Ocx ComboBox cmb = , 10, 10, 200, 22
Local cb$ = "[Cue Banner]"
Const CBM_FIRST = &1700
Const CB_SETCUEBANNER = (CBM_FIRST + 3)
~SendMessage(cmb.hWnd, CB_SETCUEBANNER, 0, UNI$(cb$))
Do : Sleep : Until Me Is Nothing
Function UNI$(ansi$) // Acknowledgements to Peter Heinzig
Local lUni As Variant = CVar(ansi) : Return Peek$({V:lUni + 8}, Len(lUni) * 2) + #0
EndFunction
// ComboBoxes which are to have full lists must have 'Full' somewhere in their Tag property.
// To set a 'Minimum Visible' limit, the string 'MinVisxxx' (where xxx is the number of entries to show) must be somewhere in the Tag property.
// --- NB The value of the minimum visible entries can only be greater than 8.
Type COMBOBOXINFO
- Long cbSize
rcItem As RECT
rcButton As RECT
- Long stateButton
- Long hwndCombo
- Long hwndItem
- Long hwndList
EndType
Type RECT
- Long Left, Top, Right, Bottom
EndType
Const CB_GETCOMBOBOXINFO = 0x0164
OpenW 1
Local n As Int32
Ocx ComboBox cmb = "", 10, 60, 100, 22 : cmb.Tag = "Full" : For n = 1 To 20 : cmb.AddItem "Item no " & Iif(n < 10, " ", "") & Trim(n) : Next n
Ocx ComboBox cmb2 = "", 10, 120, 100, 22 : cmb2.Tag = "MinVis012" : For n = 1 To 20 : cmb2.AddItem "Item no " & Iif(n < 10, " ", "") & Trim(n) : Next n
Ocx ComboBox cmb3 = "", 10, 180, 100, 22 : For n = 1 To 20 : cmb3.AddItem "Item no " & Iif(n < 10, " ", "") & Trim(n) : Next n
Do : Sleep : Until Win_1 Is Nothing
Sub Win_1_MessageProc(hWnd%, Mess%, wParam%, lParam%, retval%, ValidRet?)
Try
If Mess% = WM_COMMAND And HiWord(wParam%) = CBN_DROPDOWN
// Check to see if control is a ComboBox
Local cn$ = Space(100) : ~GetClassName(lParam%, V:cn$, 100)
If ZTrim(Mid(cn$, 2)) = "ComboBox"
// Check to see if ComboBox list to be shown in full
Local cb As Control : Set cb = OCX(lParam%)
If InStr(Lower(cb.tag), "full") + InStr(Lower(cb.tag), "minvis") <> 0
// Retrieve ComboBox Structure Information
Local cbi As COMBOBOXINFO : cbi.cbSize = SizeOf(COMBOBOXINFO) : ~SendMessage(lParam%, CB_GETCOMBOBOXINFO, 0, cbi)
// Retrieve ListBox rectangle coordinates
Local lbr As RECT : ~GetWindowRect(cbi.hwndList, lbr)
// Retrieve Item Count and Height values
Local Int32 ct, h : h = SendMessage(cbi.hwndList, LB_GETITEMHEIGHT, 0, 0)
If InStr(Lower(cb.tag), "full") <> 0 : ct = SendMessage(cbi.hwndList, LB_GETCOUNT, 0, 0)
Else : ct = InStr(Lower(cb.tag), "minvis") : cn$ = Mid(cb.tag, ct, 9) : ct = Right(cn$, 3)
EndIf
If ct > 8 // If Item Count greater than default 8 entries
// Calculate new height for ListBox
h = (h * ct) + (Screen.cyBorder * 2)
// Redraw ListBox
~MoveWindow(cbi.hwndList, lbr.Left, lbr.Top, lbr.Right - lbr.Left, h, 1)
// Stop GB32 processing this message
ValidRet? = True
// Clear structures
Clr cbi, lbr
EndIf
EndIf
EndIf
EndIf
Catch
// Include error message here if required
EndCatch
EndSub
Animation, CheckBox, Command, CommDlg, Form, Frame, Image, ImageList, Label, ListBox, ListView, MonthView, Option, ProgressBar, RichEdit, Scroll, Slider, StatusBar, TabStrip, TextBox, Timer, TrayIcon, TreeView, UpDown
{Created by Sjouke Hamstra; Last updated: 08/03/2018 by James Gaite}