Click to See Complete Forum and Search --> : Setting combo box style at runtime?
MerrionComputin
Feb 21st, 2002, 08:30 AM
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
Serge
Feb 21st, 2002, 10:26 AM
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.
Shawn N
Feb 24th, 2002, 01:50 PM
A hack around it. This will convert all characters to lowercase.
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Const GW_CHILD As Long = 5
Private Const GWL_STYLE As Long = (-16)
Private Const ES_LOWERCASE As Long = &H10&
Private Sub Form_Load()
Dim lngStyle As Long, lngHWND As Long
lngHWND = GetWindow(Combo1.hwnd, GW_CHILD)
lngStyle = GetWindowLong(lngHWND, GWL_STYLE)
lngStyle = lngStyle Or ES_LOWERCASE
Call SetWindowLong(lngHWND, GWL_STYLE, lngStyle)
End Sub
Serge
Feb 25th, 2002, 08:21 AM
This will work only for the "Edit" part of the comboxbox. All items in the list will still be the same. :(
MartinSmith
Feb 25th, 2002, 08:44 AM
You might want to check out the code here http://www.thescarms.com/vbasic/OwnerDrawn.asp also.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.