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(Text 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.