Results 1 to 4 of 4

Thread: Send Message API

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    48

    Send Message API

    I m using VB6.
    I want to increase the maximum number of charaters that an be entered in the combo box from 256(which is the default limit) to 2048.
    I think it can be done using SendMessage API but i m not able to do it.
    Can anyone help...

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    I was just tested and

    s = "A" & Space(2500) & "a"
    Combo1.AddItem s

    worked fine. If there's a item length limit, I've never come close to hitting it.

    So I'm going to assume you meant to ask for including a horizontal scrollbar and/or autosizing.

    VB Code:
    1. ' call with
    2. '
    3. 'Dim x As Boolean
    4. '
    5. 'x = AutosizeCombo(Combo1)
    6.  
    7. Option Explicit
    8.  
    9. Private Const CB_SETDROPPEDWIDTH = &H160
    10. Private Const CB_GETDROPPEDWIDTH = &H15F
    11. Private Const DT_CALCRECT = &H400
    12.  
    13. Private Type RECT
    14.    Left As Long
    15.    Top As Long
    16.    Right As Long
    17.    Bottom As Long
    18. End Type
    19.  
    20. Private Declare Function SendMessageLong Lib "user32" Alias _
    21.         "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    22.         ByVal wParam As Long, ByVal lparam As Long) As Long
    23.  
    24. Private Declare Function DrawText Lib "user32" Alias _
    25.     "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, _
    26.     ByVal nCount As Long, lpRect As RECT, ByVal wFormat _
    27.     As Long) As Long
    28.  
    29. Public Function AutosizeCombo(Combo As ComboBox) As Boolean
    30.    
    31.     'Automatically sizes a combo box to
    32.     'hold the longest item within it
    33.  
    34.     Dim lngRet As Long
    35.     Dim lngCurrentWidth As Single
    36.     Dim rectCboText As RECT
    37.     Dim lngParentHDC As Long
    38.     Dim lngListCount As Long
    39.     Dim lngCounter As Long
    40.     Dim lngTempWidth As Long
    41.     Dim lngWidth As Long
    42.     Dim strSavedFont As String
    43.     Dim sngSavedSize As Single
    44.     Dim blnSavedBold As Boolean
    45.     Dim blnSavedItalic As Boolean
    46.     Dim blnSavedUnderline As Boolean
    47.     Dim blnFontSaved As Boolean
    48.  
    49. On Error GoTo ErrorHandler
    50.  
    51.     'Grab the combo handle and list count
    52.  
    53.     lngParentHDC = Combo.Parent.hdc
    54.     lngListCount = Combo.ListCount
    55.  
    56.     If lngParentHDC = 0 Or lngListCount = 0 Then Exit Function
    57.  
    58.     'Save combo box fonts, etc. to the parent
    59.     'object (form), for testing lengths with the API
    60.  
    61.     With Combo.Parent
    62.  
    63.         strSavedFont = .FontName
    64.         sngSavedSize = .FontSize
    65.         blnSavedBold = .FontBold
    66.         blnSavedItalic = .FontItalic
    67.         blnSavedUnderline = .FontUnderline
    68.        
    69.         .FontName = Combo.FontName
    70.         .FontSize = Combo.FontSize
    71.         .FontBold = Combo.FontBold
    72.         .FontItalic = Combo.FontItalic
    73.         .FontUnderline = Combo.FontItalic
    74.  
    75.     End With
    76.  
    77.     blnFontSaved = True
    78.  
    79.     'Get the width of the widest item
    80.  
    81.     For lngCounter = 0 To lngListCount
    82.        DrawText lngParentHDC, Combo.List(lngCounter), -1, rectCboText, _
    83.             DT_CALCRECT
    84.  
    85.         'Add twenty to the the number as a margin
    86.        lngTempWidth = rectCboText.Right - rectCboText.Left + 20
    87.  
    88.         If (lngTempWidth > lngWidth) Then
    89.            lngWidth = lngTempWidth
    90.         End If
    91.  
    92.     Next
    93.  
    94.     'Get current width of combo
    95.  
    96.     lngCurrentWidth = SendMessageLong(Combo.hwnd, CB_GETDROPPEDWIDTH, _
    97.         0, 0)
    98.  
    99.     'If big enough then that's all A-OK
    100.     If lngCurrentWidth > lngWidth Then
    101.  
    102.         AutosizeCombo = True
    103.         GoTo ErrorHandler
    104.         Exit Function
    105.    
    106.     End If
    107.  
    108.     '... but if not big enough, first calculate
    109.     'the screen width to ensure we don't exceed it!
    110.  
    111.     If lngWidth > Screen.Width \ Screen.TwipsPerPixelX - 20 Then _
    112.         lngWidth = Screen.Width \ Screen.TwipsPerPixelX - 20
    113.  
    114.     'Set the width of our combo
    115.     lngRet = SendMessageLong(Combo.hwnd, CB_SETDROPPEDWIDTH, lngWidth, 0)
    116.  
    117.     'Set the function to True/False depending on API success
    118.     AutosizeCombo = lngRet > 0
    119.    
    120. ErrorHandler:
    121.        
    122.     'If anything goes wrong, revert back!
    123.    
    124.     On Error Resume Next
    125.    
    126.     If blnFontSaved Then
    127.       With Combo.Parent
    128.         .FontName = strSavedFont
    129.         .FontSize = sngSavedSize
    130.         .FontUnderline = blnSavedUnderline
    131.         .FontBold = blnSavedBold
    132.         .FontItalic = blnSavedItalic
    133.      End With
    134.     End If
    135.  
    136. End Function

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    48
    Please help urgently

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    48

    Cool

    I have solved it

    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, Param As Any) As Long

    Public Const CB_LIMITTEXT = &H141



    and using this statement in form Load


    SendMessage combo1.hwnd, CB_LIMITTEXT, 2048, 0&

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width