تمام مطالب ذکر شده برگرفته از اینترنت و داکیومنت آفیس است و تنها یک سوم آنها تست شده
Const XBITMAP=48
Cpnst YBITMAP=48
Const BUFFER MAX_PATH
HBITMAP hbmpPencil, hbmpCrayon, hbmpMarker,hbmpPen,hbmpFork
HBITMAP hbmpPicture, hbmpOld
Sub AddItem(hwnd,pstr,hbmp)
Dim lbItem As Integer
lbItem=SendMessage(hwnd, LB_ADDSTRING,0,(LPARAM)pstr)
SendMessage(hwnd,LB_SETITEMDATA, (WPARAM)lbItem,(LPARAM)hbmp)
End Sub
DlgDrawProc :
Dim hListBox As Long
Dim pmis As PMEASUREITEMSTRUCT Dim pdis As PDRAWITEMSTRUCT
TCHAR achBuffer[BUFFER]
size_t cch
Dim yPos As Integer
Dim lbItem As Integer
Dim tm As TEXTMETRIC
Dim rcBitmap As RECT
Dim hbmp As Long
case WM_INITDIALOG
hbmpPencil=LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_PENCIL))
hListBox=GetDlgItem(hDlg, IDC_LIST_STUFF)
AddItem hListBox,L"pencil",hbmpPencil AddItem hListBox, L"crayon",hbmpCrayon
SetFocus hListBox
SendMessage hListBox,LB_SETCURSEL, 0, 0
return TRUE
case WM_MEASUREITEM
pmis = (PMEASUREITEMSTRUCT) lParam
'Set the height of the list box items.
pmis.itemHeight=YBITMAP
return TRUE
case WM_DRAWITEM
pdis = (PDRAWITEMSTRUCT) lParam
Select Case pdis.itemAction
case ODA_SELECT,ODA_DRAWENTIRE
hbmpPicture=SendMessage(pdis.hwndItem,LB_GETITEMDATA,pdis.itemID,0)
hdcMem=CreateCompatibleDC(pdis.hDC)
hbmpOld=SelectObject(hdcMem, hbmpPicture)
BitBlt(pdis.hDC,pdis.rcItem.left,pdis.rcItem.top,pdis.rcItem.right-pdis.rcItem.left
SendMessage pdis.hwndItem,LB_GETTEXT, pdis.itemID,(LPARAM)achBuffer
GetTextMetrics pdis.hDC, &tm
yPos=(pdis.rcItem.bottom+
pdis.rcItem.top-tm.tmHeight)/2
hr=StringCchLength(achBuffer,BUFFER, &cch)
TextOut pdis.hDC,XBITMAP+6,yPos, achBuffer,cch
SelectObject hdcMem,hbmpOld
DeleteDC hdcMem
if (pdis.itemState & ODS_SELECTED) Then
rcBitmap.left=pdis.rcItem.left rcBitmap.top=pdis.rcItem.top rcBitmap.right=pdis.rcItem.left+XBITMAP
rcBitmap.bottom=pdis.rcItem.top+YBITMAP
DrawFocusRect pdis.hDC,&rcBitmap
End If
Exit Function
case WM_COMMAND
Select Case (LOWORD(wParam))
case IDOK
lbItem=SendMessage(GetDlgItem(hDlg, IDC_LIST_STUFF),LB_GETCURSEL, 0, 0)
if (hbmp<>hbmpFork) Then
MessageBox hDlg,L"Try again!",L"Oops", MB_OK)
return FALSE
else
MessageBox hDlg,L"You're right!", L"Congratulations.",MB_OK)
End if
case WM_DESTROY
'Free the bitmap resources.
DeleteObject hbmpPencil
DeleteObject hbmpCrayon
DeleteObject hbmpMarker
DeleteObject hbmpPen
DeleteObject hbmpFork
return TRUE