Hello All
O2 really is good and fun to use, and here is a Colorful ownerdrawn Listbox
' Odrawn_listbox.o2bas
' Colorful Owner drawn Listbox in color which user
' can select and high light a row
$ filename "Odrawn_listbox.exe"
use rtl64
#lookahead
' %review
uses O2Common
uses dialogs
% ID_LIST1 = 101
' The program logo icon is obtained from the resource file
' the 400 must corespondence to the 400 in the rc file
% IDI_LOGO 400
% mLeft = 10 ' ownerdrawn listbox item margins
% mRight = 5
% mTop = 5
% mBottom = 3
Sys hDlg
'====================================================================
FUNCTION O2Main
Dialog( 150, 70, 120, 175, "Ownerdrawn ListBox ", WS_CAPTION OR WS_SYSMENU )
' Add in the list box
sys LBStyle = WS_CHILD OR LBS_OWNERDRAWFIXED OR LBS_HASSTRINGS or WS_VSCROLL or WS_BORDER or WS_TABSTOP or LBS_NOTIFY
ListBox( "", ID_List1, 5,5,60,155, LBStyle , WS_EX_CLIENTEDGE or WS_EX_ACCEPTFILES , 0)
sys cbStyle = WS_CHILDWINDOW or WS_VISIBLE or BS_DEFPUSHBUTTON or WS_DLGFRAME
CONTROL "Exit", IDCANCEL,"Button", cbStyle , 85, 160, 30, 14
hDlg = CreateModalDialog( 0, @DlgProc, 0 )
END FUNCTION
'====================================================================
' Main callback function
Function DlgProc( hDlg, uint uMsg, sys wParam, lParam ) as sys callback
LONG i , cht , cLBindex , LBindex , LwantTxt
zstring sText[200] , lbtext[200]
zstring wantText[200]
sys hLB= GetDlgItem(hDlg, ID_LIST1)
SELECT CASE uMsg
CASE WM_INITDIALOG
' display the program icon
sys hInstance = GetModuleHandle(NULL)
sys hIcon = LoadIcon(hInstance, IDI_Logo)
'Set Icon to Main Window
SendMessage(hDlg, WM_SETICON, ICON_BIG, hIcon)
'Get height of line
cht = SendMessage hLB, LB_GETITEMHEIGHT, 0, 0
' Add in the top and bottom margins
cht = cht + mTop + mBottom
SendMessage hLB, LB_SETITEMHEIGHT, 0, cht
lbtext = ""
FOR i = 1 TO 50
' fill list with some data to show
lbtext = " item " + str(i)
cLBindex = SendMessage(hLB, LB_ADDSTRING, 0, lbtext )
NEXT
CASE WM_ERASEBKGND
' added to display background color for the main window
' for a PaleTurquoise background
MainWindBGColor = 4
hBGDC = wParam
' Pass the DC of the region to be repaint
DrawGradient hBGDC
FUNCTION = 1
EXIT FUNCTION
CASE WM_COMMAND
SELECT CASE LOword(wParam)
CASE IDCANCEL
EndDialog( hDlg, null )
CASE ID_LIST1
SELECT CASE HIword(wParam)
CASE LBN_DBLCLK
' When user double click on a row
' display the selection
'Gets the index of the currently selected item
LBindex = SendMessage(hLB, LB_GETCURSEL, 0, 0)
'get the Text
SendMessage(hLB, LB_GETTEXT, LBindex, @wantText)
MSGBOX wantText , MB_OK OR MB_ICONINFORMATION OR MB_TASKMODAL, _
"List message"
CASE LBN_SELCHANGE
END SELECT
END SELECT
CASE WM_DRAWITEM
IF LOword(wParam) = ID_LIST1 THEN
'make sure it's our listbox (if several exists)
' lpdis = CBLPARAM
DRAWITEMSTRUCT lpdis at lParam
IF lpdis.itemID = &HFFFFFFFF THEN
EXIT FUNCTION 'if empty list, jump out..
End If
SELECT CASE lpdis.itemAction
CASE ODA_DRAWENTIRE, ODA_SELECT
' draw cell selection color
IF (lpdis.itemState AND ODS_SELECTED) = 0 THEN
' When not selected, use the orig colors
FillRect lpdis.hDC, lpdis.rcItem, GetSysColorBrush( COLOR_WINDOW)
SetBkColor lpdis.hDC, GetSysColor( COLOR_WINDOW)
SetTextColor lpdis.hDC, GetSysColor( COLOR_WINDOWTEXT)
ELSE
' when the item is selected
' the big band around the selected item
FillRect lpdis.hDC, lpdis.rcItem,GetSysColor( COLOR_WINDOW)
' the text background
SetBkColor lpdis.hDC, O2c_YELLOW
' the text color
SetTextColor lpdis.hDC, O2c_DARK_CYAN
END IF
' Set up the margins and specified the rectangle
' of the selected row
SetRect lpdis.rcItem, lpdis.rcItem.Left + mLeft, lpdis.rcItem.Top + mTop, _
lpdis.rcItem.Right + mRight, lpdis.rcItem.Bottom + mBottom
' Get the listbox text
SendMessage(hLB, LB_GETTEXT, lpdis.itemID, VARPTR(wantText) )
' draw the text
wantText = wantText
LwantTxt = LEN(wantText)
DrawText lpdis.hDC, wantText , LwantTxt , lpdis.rcItem, DT_LEFT
FUNCTION = TRUE
END SELECT
END IF
END SELECT
END FUNCTION
'----------------------------------
' Program starts
init_common_controls()
O2Main