Code:
'------------------------------------------------------------------------------ ' Ownerdrawn Button example ' ' Uses the BS_OWNERDRAW button style and paints buttons with red border. ' ' K.G.Peel, May 2003. '------------------------------------------------------------------------------ #Compile Exe #Dim All #Register All %USEMACROS = 1 #Include "win32api.inc Function PBMain Local hDlg As Dword Dialog New 0, "Ownerdrawn Button Test", , , 200, 150, %WS_OVERLAPPEDWINDOW To hDlg Control Add Button, hDlg, 100, "1", 5, 10, 60, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_OWNERDRAW Control Add Button, hDlg, 101, "2", 5, 30, 60, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_OWNERDRAW Control Add Button, hDlg, 102, "3", 5, 50, 60, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_OWNERDRAW Control Add Button, hDlg, 103, "4", 5, 70, 60, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_OWNERDRAW Control Add Button, hDlg, 104, "5", 5, 90, 60, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_OWNERDRAW Dialog Show Modal hDlg Call dlgProc End Function CallBack Function dlgProc Select Case CbMsg Case %WM_DRAWITEM Local hOldFnt As Dword, szText As Asciiz * 128, rc As RECT Local dis As DRAWITEMSTRUCT Ptr, hPen As Dword, hBrush As Dword dis = CbLParam Select Case @dis.CtlId Case 100, 101, 102, 103, 104 Case Else: Exit Function End Select rc = @dis.rcItem hOldFnt = SelectObject(@dis.hDc, GetStockObject(%ANSI_VAR_FONT)) If (@dis.itemState And %ODS_FOCUS) Then hPen = SelectObject(@dis.hDC, CreatePen(%PS_SOLID, 3, RGB(255,0,0))) hBrush = SelectObject(@dis.hDC, GetSysColorBrush(%COLOR_BTNFACE)) Rectangle @dis.hDC, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom SelectObject @dis.hDC, hBrush DeleteObject SelectObject(@dis.hDC, hPen) Else FillRect @dis.hDc, rc, GetSysColorBrush(%COLOR_BTNFACE) End If rc.nLeft = rc.nLeft + 3: rc.nTop = rc.nTop + 3 rc.nBottom = rc.nBottom - 3: rc.nRight = rc.nRight - 3 If (@dis.itemState And %ODS_SELECTED) Then DrawEdge @dis.hDc, rc, %BDR_SUNKEN, %BF_RECT Or %BF_MIDDLE Or %BF_SOFT rc.nLeft = rc.nLeft + 2 rc.nTop = rc.nTop + 2 Else DrawEdge @dis.hDc, rc, %BDR_RAISED, %BF_RECT Or %BF_MIDDLE Or %BF_SOFT End If SetBkMode @dis.hDc, %Transparent If (@dis.itemState And %ODS_DISABLED) Then SetTextColor @dis.hDc, GetSysColor(%COLOR_GRAYTEXT) Else SetTextColor @dis.hDc, GetSysColor(%COLOR_BTNTEXT) End If SendMessage @dis.hWndItem, %WM_GETTEXT, SizeOf(szText), VarPtr(szText) DrawText @dis.hDc, szText, Len(szText), rc, %DT_CENTER Or %DT_VCENTER Or %DT_SINGLELINE SelectObject @dis.hDc, hOldFnt Function = %True End Select End Function
------------------
Kev Peel
KGP Software (Custom Programming Solutions), UK.
[This message has been edited by Kev Peel (edited May 14, 2003).]