BCX_BUTTON creates a push button that posts a WM_COMMAND message to the owner window when the user selects the button.
Syntax:hCtl = BCX_BUTTON(Caption AS STRING, _ hwndParent AS HWND, _ hCtlID AS INTEGER, _ Xpos AS INTEGER, _ Ypos AS INTEGER, _ Width AS INTEGER, _ Height AS INTEGER _ [, WinStyle AS INTEGER] _ [, ExWinStyle AS INTEGER]) Return Value:
Parameters:
|
The default window Style for a BCX_BUTTON control also can be changed by using the MODSTYLE function.
This example demonstrates colorizing BCX_BUTTON controls and text.
GUI "Ownerdraw Button Demo" DIM AS HWND Form1, hButton1, hButton2 SUB FORMLOAD Form1 = BCX_FORM("Ownerdraw Button Demo", 0, 0, 175, 100) hButton1 = BCX_BUTTON ("Ok", Form1, IDOK, 10, 30, 50, 20, WS_VISIBLE OR WS_CHILD OR WS_TABSTOP OR BS_OWNERDRAW) hButton2 = BCX_BUTTON ("Quit", Form1, IDCANCEL, 110, 30, 50, 20, WS_VISIBLE OR WS_CHILD OR WS_TABSTOP OR BS_OWNERDRAW) CENTER Form1 SHOW Form1 END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_COMMAND SELECT CASE CBCTL CASE IDOK MSGBOX "Okay!" CASE IDCANCEL IF HIWORD(CBWPARAM) = BN_CLICKED OR HIWORD(CBWPARAM) = 1 THEN END END IF END SELECT CASE WM_DRAWITEM IF CBWPARAM = IDOK THEN DrawButton(hButton1, CBLPARAM, RGB(0, 192, 0), RGB(0, 0, 0)) ' black text on green background END IF IF CBWPARAM = IDCANCEL THEN DrawButton(hButton2, CBLPARAM, RGB(255, 255, 124), RGB(255, 0, 0)) ' Red text on yellow background END IF END SELECT END EVENTS SUB DrawButton(hButton AS HWND, lParam AS LPARAM, bgColor AS COLORREF, txtColor AS COLORREF) DIM hBrush AS HBRUSH DIM lpDis AS DRAWITEMSTRUCT PTR DIM zTxt AS STRING lpDis = CAST(DRAWITEMSTRUCT PTR, lParam) hBrush = CreateSolidBrush(bgColor) ' Create background brush SetBkColor(lpDis->hDC, bgColor) ' Set background color for text SetTextColor(lpDis->hDC, txtColor) ' Set text color GetWindowText(hButton, zTxt, BCXSTRSIZE) ' Get button text IF (lpDis->itemState AND ODS_SELECTED) THEN ' Draw button frame DrawFrameControl(lpDis->hDC, &lpDis->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH OR DFCS_PUSHED) OffsetRect(&lpDis->rcItem, 1, 1) ' Adjust rect for pressed state ELSE DrawFrameControl(lpDis->hDC, &lpDis->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH) END IF InflateRect(&lpDis->rcItem, -2, -2) ' Prevents text from overlapping border FillRect(lpDis->hDC, &lpDis->rcItem, hBrush) ' Fill button background DrawText(lpDis->hDC, zTxt, -1, &lpDis->rcItem, DT_SINGLELINE OR DT_CENTER OR DT_VCENTER) IF (lpDis->itemState AND ODS_FOCUS) THEN ' Draw focus rectangle if button has focus SetTextColor(lpDis->hDC, GetSysColor(COLOR_BTNTEXT)) ' Reset text color InflateRect(&lpDis->rcItem, -1, -1) ' Adjust focus rect slightly DrawFocusRect(lpDis->hDC, &lpDis->rcItem) END IF DeleteObject(hBrush) ' Clean up END SUB
For an example of the BCX_BUTTON function see Demo.bas.
BCX_SPLITBUTTON creates a Windows Split Button control. A split button is a button divided into two parts: a main button that performs a default action, and a dropdown arrow that displays a menu of additional options. When an option is selected from the dropdown menu, the button's caption automatically updates to reflect the selection.
👉 BCX_SPLITBUTTON requires a Windows Vista / Windows 10/11 Common Controls 6.0+ manifest.
Syntax:hCtl = BCX_SPLITBUTTON(Caption AS STRING, _ hwndParent AS HWND, _ hCtlID AS INTEGER, _ Xpos AS INTEGER, _ Ypos AS INTEGER, _ Width AS INTEGER, _ Height AS INTEGER _ [, WinStyle AS INTEGER] _ [, ExWinStyle AS INTEGER]) Return Value:
Parameters:
|
BCX_SPLITBUTTON_ADDITEM, a BCX_SPLITBUTTON auxiliary procedure, adds a single menu item to the BCX_SPLITBUTTON's dropdown menu.
Syntax:BCX_SPLITBUTTON_ADDITEM(hSplitButton AS HWND, _ MenuItem AS STRING, _ ItemID AS INTEGER) Parameters: |
BCX_SPLITBUTTON_ADDSEPARATOR, a BCX_SPLITBUTTON auxiliary procedure, adds a horizontal separator line to the BCX_SPLITBUTTON's dropdown menu.
Syntax:BCX_SPLITBUTTON_ADDSEPARATOR(hSplitButton AS HWND) Parameters:
|
When a function call is made to BCX_SPLITBUTTON, a BCX_SPLITBUTTONDATA structure is defined and initialized automatically for inclusion in the C translation of the code. The structure, exemplified as BCX code, is
TYPE BCX_SPLITBUTTONDATA szLabel AS ASCIIZ * 256 ' Menu item text nID AS INT ' Menu item identifier END TYPE
BCX_SPLITBUTTON_SETITEMS, a BCX_SPLITBUTTON auxiliary procedure, can add multiple menu items, at once, from an array of BCX_SPLITBUTTONDATA structures, to the specified BCX_SPLITBUTTON's dropdown menu.
Syntax:BCX_SPLITBUTTON_SETITEMS(hSplitButton AS HWND, _ MenuItemsPtr AS BCX_SPLITBUTTONDATA, _ Count AS INTEGER) Parameters:
|
Automatic Caption Update: When the user selects an item from the dropdown menu, the split button's caption automatically updates to display the selected item's text. You do not need to call BCX_SET_TEXT manually.
Control ID Behavior: When a menu item is selected, the control's ID changes to match the selected item's ID. This means CBCTL in your event handler will contain the ID of the currently selected/clicked item.
Button Width: Ensure the button width is sufficient to display the longest menu item text plus the dropdown arrow (approximately 48 pixels for the arrow).
Using BCX_SPLITBUTTON_ADDITEM
GUI "SplitButton Demo" ENUM SB_CUT SB_COPY SB_PASTE SB_DELETE END ENUM GLOBAL AS HWND Form1, hSplitButt SUB FORMLOAD Form1 = BCX_FORM("SplitButton Demo", 0, 0, 300, 200) hSplitButt = BCX_SPLITBUTTON("Cut", Form1, SB_CUT, 10, 10, 100, 25) BCX_SPLITBUTTON_ADDITEM(hSplitButt, "Cut", SB_CUT) BCX_SPLITBUTTON_ADDITEM(hSplitButt, "Copy", SB_COPY) BCX_SPLITBUTTON_ADDITEM(hSplitButt, "Paste", SB_PASTE) BCX_SPLITBUTTON_ADDSEPARATOR(hSplitButt) BCX_SPLITBUTTON_ADDITEM(hSplitButt, "Delete", SB_DELETE) CENTER Form1 SHOW Form1 END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_COMMAND SELECT CASE CBCTL CASE SB_CUT : MSGBOX "Cut clicked" CASE SB_COPY : MSGBOX "Copy clicked" CASE SB_PASTE : MSGBOX "Paste clicked" CASE SB_DELETE : MSGBOX "Delete clicked" END SELECT END SELECT END EVENTS
Using BCX_SPLITBUTTON_SETITEMS with Array.
GUI "SplitButton Demo" ENUM SB_APPLES SB_BANANAS SB_GRAPES SB_ORANGES END ENUM GLOBAL AS HWND Form1, hSplitButt SUB FORMLOAD DIM AS BCX_SPLITBUTTONDATA MenuItems[4] Form1 = BCX_FORM("SplitButton Demo", 0, 0, 300, 200) hSplitButt = BCX_SPLITBUTTON("Apples", Form1, SB_APPLES, 10, 10, 100, 25) MenuItems[0].szLabel = "Apples" MenuItems[0].nID = SB_APPLES MenuItems[1].szLabel = "Bananas" MenuItems[1].nID = SB_BANANAS MenuItems[2].szLabel = "Grapes" MenuItems[2].nID = SB_GRAPES MenuItems[3].szLabel = "Oranges" MenuItems[3].nID = SB_ORANGES BCX_SPLITBUTTON_SETITEMS(hSplitButt, ADDRESSOF(MenuItems[0]), 4) CENTER Form1 SHOW Form1 END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_COMMAND SELECT CASE CBCTL CASE SB_APPLES : MSGBOX "Apples" CASE SB_BANANAS : MSGBOX "Bananas" CASE SB_GRAPES : MSGBOX "Grapes" CASE SB_ORANGES : MSGBOX "Oranges" END SELECT END SELECT END EVENTS