Results 1 to 5 of 5

Thread: Setting combo box style at runtime?

  1. #1

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Setting combo box style at runtime?

    If I want to change the style of a button control at runtime I can do this by sending it the BM_SETSTYLE message and refreshing it...

    Is there a way of doing this for a combo box that has already been created? Specifically how do I set CBS_UPPERCASE or CBS_LOWERCASE?

    Thanks in advance,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Unfortunately, not all styles can be change at run time.
    The only way to achieve this is to setup a system hook for the entire application and watch for WM_CREATE message.

  3. #3
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    A hack around it. This will convert all characters to lowercase.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
    4.      ByVal hwnd As Long, _
    5.      ByVal nIndex As Long) As Long
    6.      
    7. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
    8.      ByVal hwnd As Long, _
    9.      ByVal nIndex As Long, _
    10.      ByVal dwNewLong As Long) As Long
    11.  
    12. Private Declare Function GetWindow Lib "user32" ( _
    13.      ByVal hwnd As Long, _
    14.      ByVal wCmd As Long) As Long
    15.      
    16. Private Const GW_CHILD As Long = 5
    17. Private Const GWL_STYLE As Long = (-16)
    18. Private Const ES_LOWERCASE As Long = &H10&
    19.  
    20. Private Sub Form_Load()
    21.  
    22.     Dim lngStyle As Long, lngHWND As Long
    23.     lngHWND = GetWindow(Combo1.hwnd, GW_CHILD)
    24.    
    25.     lngStyle = GetWindowLong(lngHWND, GWL_STYLE)
    26.     lngStyle = lngStyle Or ES_LOWERCASE
    27.    
    28.     Call SetWindowLong(lngHWND, GWL_STYLE, lngStyle)
    29. End Sub
    Please rate my post.

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    This will work only for the "Edit" part of the comboxbox. All items in the list will still be the same.

  5. #5
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    You might want to check out the code here http://www.thescarms.com/vbasic/OwnerDrawn.asp also.

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