AbbasVB
شنبه 28 دی 1392, 17:12 عصر
سلام دوستان
چه طوری میشه تمام آیتم های یک کمبو باکس رو از یک برنامه دیگه به دست آورد؟
به این صورت که هندل کمبو باکس رو بدهیم و متن آیتم ها برای ما لیست شود.
AbbasVB
شنبه 28 دی 1392, 17:25 عصر
مشکل حل شد 
دوستانی که نیاز دارند می توانند از کد زیر برای این کار استفاده کنند
Option Explicit
Private Declare Function SendMessage _
                Lib "user32" _
                Alias "SendMessageA" (ByVal hWnd As Long, _
                                      ByVal wMsg As Long, _
                                      ByVal wParam As Long, _
                                      lParam As Any) As Long
     
Private Const CB_GETCOUNT = &H146
Private Const CB_GETLBTEXT = &H148
Private Const CB_GETLBTEXTLEN = &H149
Private Const CB_ERR = (-1)
     
Private Sub Command1_Click()
        Dim N As Long, sItems() As String
        sItems = GetComboBoxItems(Combo1.hWnd)
        For N = LBound(sItems) To UBound(sItems)
                Print sItems(N)
        Next N
End Sub
     
Private Function GetComboBoxItems(ByVal hWndComboBox As Long) As String()
        Dim nCount   As Long, I As Long, nLen As Long
        Dim sItems() As String
       
        nCount = SendMessage(hWndComboBox, CB_GETCOUNT, 0, 0)
        If (nCount = CB_ERR) Or (nCount = 0) Then Exit Function
     
        ReDim Preserve sItems(nCount - 1)
        For I = 0 To nCount - 1
                nLen = SendMessage(hWndComboBox, CB_GETLBTEXTLEN, I, 0)
                If nLen = CB_ERR Then Exit Function
                sItems(I) = String(nLen, vbNullChar)
                If SendMessage(hWndComboBox, CB_GETLBTEXT, I, ByVal sItems(I)) = CB_ERR Then Exit Function
        Next
     
        GetComboBoxItems = sItems
End Function
Private Sub Form_Load()
        Combo1.AddItem ("a")
        Combo1.AddItem ("b")
        Combo1.AddItem ("c")
        Combo1.AddItem ("d")
End Sub
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.