کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

ListBox در InputBox




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


Specifies that a list box contains items consisting of strings. The list box maintains the memory and addresses for the strings so that the application can use the LB_GETTEXT message to retrieve the text for a particular item. By default, all list boxes except owner-drawn list boxes have this style. You can create an owner-drawn list box either with or without this style.


کاملا به دو نکته ی زیر توجه شود : 

To obtain the exact length of the text, use the WM_GETTEXTLB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function



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<

(if (lpDStruct->itemState & ODS_FOCUS
}

;(DrawFocusRect(dc,rect

{

clean up //

;(SelectObject(dc,hOldFont

;(SelectObject(dc,oldpen

;(SelectObject(dc,oldbrush



;logFont.lfHeight = 16
;logFont.lfWeight = FW_BOLD

;("strcpy(logFont.lfFaceName,"courier

;(hFont = CreateFontIndirect(&logFont

(hOldFont = (HFONT)SelectObject(dc,hFont








نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد