Re: Stupid Question Time: Combo box items
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 24 Sep 2007 15:48:32 -0400
Never mind. I'd missed the ".Container" in the ScreenToClient changes. Works beautifully now. Thanks!
Final--working--code for any future readers of this thread is (watch out for wrapping):
Private Const cbGetItemHeight = &H154
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal
nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
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
Public Sub SetComboBoxRows(ByVal cmbToChange As VB.ComboBox, ByVal lngNumRows As Long)
Dim rc As RECT
Dim pt As POINTAPI
Dim lngCurHeight As Long
Dim lngNewHeight As Long
Dim lngScaleMode As Long
lngCurHeight = SendMessage(cmbToChange.hWnd, cbGetItemHeight, 0, ByVal 0)
lngNewHeight = lngCurHeight * (lngNumRows + 2)
GetWindowRect cmbToChange.hWnd, rc
pt.x = rc.Left
pt.y = rc.Top
ScreenToClient cmbToChange.Container.hWnd, pt
MoveWindow cmbToChange.hWnd, pt.x, pt.y, rc.Right - rc.Left, lngNewHeight, True
End Sub
Rob
"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:ufghP5t$HHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
Doesn't seem to have worked. Did I goof somewhere? Here's the code I have currently (with many of the variables renamed to
conform to my convention):
Public Sub SetComboBoxRows(ByVal cmbToChange As VB.ComboBox, ByVal lngNumRows As Long)
Dim rc As RECT
Dim pt As POINTAPI
Dim lngCurHeight As Long
Dim lngNewHeight As Long
Dim lngScaleMode As Long
Dim lngWidth As Long
lngWidth = cmbToChange.Width
lngCurHeight = SendMessage(cmbToChange.hWnd, cbGetItemHeight, 0, ByVal 0)
lngNewHeight = lngCurHeight * (lngNumRows + 2)
GetWindowRect cmbToChange.hWnd, rc
pt.x = rc.Left
pt.y = rc.Top
ScreenToClient cmbToChange.hWnd, pt
MoveWindow cmbToChange.hWnd, pt.x, pt.y, rc.Right - rc.Left, lngNewHeight, True
End Sub
Rob
"Mike Williams" <mike@xxxxxxxxxxxxxxxxx> wrote in message news:uSbxzyt$HHA.4612@xxxxxxxxxxxxxxxxxxxxxxx
"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:OWEQ9Yt$HHA.5164@xxxxxxxxxxxxxxxxxxxxxxx
Just out of curiosity, could this be made to work without
the references to the form if I were to assume that the
form's ScaleMode is always in twips (which all my forms
are) and did the appropriate conversions?
Yes. You don't even need to assume anything about the ScaleMode because it will work whatever it happens to be. Just change the
following two lines (the comented out lines are the originals and the uncommented lines are their replacements:
' Call ScreenToClient(Form1.hWnd, pt)
Call ScreenToClient(Combo1.Container.hWnd, pt)
'Call MoveWindow(Combo1.hWnd, pt.x, pt.y, _
Combo1.Width, newHeight, True)
Call MoveWindow(Combo1.hWnd, pt.x, pt.y, _
rc.Right - rc.Left, newHeight, True)
You can now remove all references to Form1 in the example code. This will enable you to easily build your required function in
which you just need to pass the Combo Box and the required number of rows.
Mike
.
- Follow-Ups:
- Re: Stupid Question Time: Combo box items
- From: Ivar
- Re: Stupid Question Time: Combo box items
- References:
- Stupid Question Time: Combo box items
- From: Robert Morley
- Re: Stupid Question Time: Combo box items
- From: Tim Rude
- Re: Stupid Question Time: Combo box items
- From: Robert Morley
- Re: Stupid Question Time: Combo box items
- From: Mike Williams
- Re: Stupid Question Time: Combo box items
- From: Robert Morley
- Stupid Question Time: Combo box items
- Prev by Date: Re: Stupid Question Time: Combo box items
- Next by Date: Re: Stupid Question Time: Combo box items
- Previous by thread: Re: Stupid Question Time: Combo box items
- Next by thread: Re: Stupid Question Time: Combo box items
- Index(es):
Relevant Pages
|