ش | ی | د | س | چ | پ | ج |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
vb Uses Unicode for text string so use SendMessageW instead Of SendMessageA Function
The list box has the LBS_OWNERDRAWFIXED and LBS_HASSTRINGS styles, in addition to the standard list box styles.
LBS_HASSTRINGS
LB_GETTEXT
The return value is the length of the string, in TCHARs, excluding the terminating
(null character ( hence buff+1
If the list box has an owner-drawn style but not the LBS_HASSTRINGS style, the buffer pointed to by the lParam parameter receives the value associated with the item the item data
Means Use Byval
If the list box has WS_HSCROLL style and you insert a string wider than the list box, send an LB_SETHORIZONTALEXTENT message to ensure the horizontal scroll bar appears.
Case WM_MEASUREITEM
Case WM_DRAWITEM
Dim pdis As DRAWITEMSTRUCT
Dim tm As TEXTMETRIC
Dim hDCMem As LongPtr
CopyMemory pdis, ByVal lParam, 40
Select Case pdis.itemAction
Case ODA_SELECT, ODA_DRAWENTIRE
Dim p As RECT
GetClientRect pdis.hwndItem, pdis.rcitem
BitBlt pdis.hdc
SetBkMode pdis.hdc, 0
SetTextColor pdis.hdc, vbRed
TextOutA pdis.hdc, pdis.rcitem.Left,pdis.rcitem.Top, buffer$, 5
CopyMemory lParam, pdis,40
End Select
گرفتن تعداد آیتم ها در لیست باکس
LB_GETCOUNT message
Gets the number of items in a list box
wParam,lParam
Not used; must be zero
Dim index As Integer
Dim textBuff As String
(textBuff = Space(255
(NumItems=SendMessage(hWndList,LB_GETCOUNT,0,0
index use GETCURSEL'
Gets the index of the currently selected item)'
(if any, in a single-selection list box'
SendMessageW hWndList, LB_GETTEXT,index, textBuff
MsgBox textBuff
docs.microsoft.com/enmeasureitemstruct
مثالی از کشیدن نقطه چین دور آیتم سلکت شده به زبان دیگر
if lpdis->itemState & ODS_SELECTED
* Set RECT coordinates to surround only the'
* bitmap.
rcBitmap.left=lpdis->rcItem.left
rcBitmap.top=lpdis->rcItem.top
rcBitmap.right=lpdis->rcItem.left+XBITMAP
rcBitmap.bottom=lpdis->rcItem.top + YBITMAP
* Draw a rectangle around bitmap to indicate'
* the selection.
DrawFocusRect lpdis->hDC, &rcBitmap
استفاده در مثال شکل بالا به زبان دیگر
Display the text associated with the item'
SendMessage lpdis->hwndItem
LB_GETTEXT,lpdis->itemID, (LPARAM) tchBuffer,
GetTextMetrics lpdis->hDC, &tm
GetClientRect lpdis.hwnditem,lpdis.rcItem'
-y=(lpdis->rcItem.bottom+lpdis->rcItem.top
tm.tmHeight) / 2
6+TextOutA lpdis->hDC,XBITMAP
(y,tchBuffer,len(tchBuffer,
SelectObject hdcMem, hbmpOld
DeleteDC hdcMem
The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font
BOOL GetTextMetrics( HDC hdc, LPTEXTMETRIC lptm );
Parameters
hdc
A handle to the device context
lptm
A pointer to the TEXTMETRIC structure that receives the text metrics.
Type TEXTMETRICA
tmHeight As Long
tmWeight As Long
tmItalic As Long
tmMaxCharWidth As Long
tmUnderlined As Long
tmCharSet As Long
End Type
: case WM_MEASUREITEM
;lpmis = (LPMEASUREITEMSTRUCT) lParam
;lpmis->itemHeight=20
;return TRUE
(DrawEntire(LPDRAWITEMSTRUCT lpDStruct
;(CRect rect(lpDStruct->rcItem
;HDC dc =lpDStruct->hDC
;MYLISTITEM *a = (MYLISTITEM*)lpDStruct->itemData
TextOut(dc,rect.left+20,rect.top+2,a->title,strlen(a-
;((title<
;(SelectObject(dc,hOldFont
;(SelectObject(dc,oldpen
;(SelectObject(dc,oldbrush
;("strcpy(logFont.lfFaceName,"courier
;(hFont = CreateFontIndirect(&logFont
(hOldFont = (HFONT)SelectObject(dc,hFont