|
-
Jun 18th, 2001, 08:25 AM
#1
ComboBox list height with api - whats wrong with this code
Hi,
i got a code that suppose to change the vertical length of a combobox list.
Code:
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public 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 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
Public Declare Function GetWindowRect Lib _
"user32" (ByVal hwnd As Long, _
lpRect As RECT) As Long
Public Declare Function ScreenToClient Lib _
"user32" (ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long
Public Const CB_SHOWDROPDOWN = &H14F
Public Const CB_GETITEMHEIGHT = &H154
Option Explicit
Code:
Private Sub ComboHeightInit_Click()
Dim pt As POINTAPI
Dim rc As RECT
Dim cWidth As Long
Dim newHeight As Long
Dim oldScaleMode As Long
Dim numItemsToDisplay As Long
Dim itemHeight As Long
'change this number to the number you want to display
numItemsToDisplay = 10
'Save the current form scalemode, then
'switch to pixels
oldScaleMode = FrmInit.ScaleMode
FrmInit.ScaleMode = vbPixels
'the width of the combo, used below
cWidth = ComboMod.Width
'get the system height of a single
'combo box list item
itemHeight = SendMessage(ComboMod.hwnd, CB_GETITEMHEIGHT, 0, ByVal 0)
'Calculate the new height of the combo box. This
'is the number of items times the item height
'plus two. The 'plus two' is required to allow
'the calculations to take into account the size
'of the edit portion of the combo as it relates
'to item height. In other words, even if the
'combo is only 21 px high (315 twips), if the
'item height is 13 px per item (as it is with
'small fonts), we need to use two items to
'achieve this height.
newHeight = itemHeight * (numItemsToDisplay + 2)
'Get the co-ordinates of the combo box
'relative to the screen
Call GetWindowRect(ComboMod.hwnd, rc)
pt.x = rc.Left
pt.y = rc.Top
'Then translate into co-ordinates
'relative to the form.
Call ScreenToClient(FrmInit.hwnd, pt)
'Using the values returned and set above,
'call MoveWindow to reposition the combo box
Call MoveWindow(ComboMod.hwnd, pt.x, pt.y, ComboMod.Width, newHeight, True)
'Its done, so show the new combo height
Call SendMessage(ComboMod.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)
'restore the original form scalemode
'before leaving
FrmInit.ScaleMode = oldScaleMode
End Sub
the problem is; when i applied this code to my program my combobox disappeared.
when i disabled the line:
Call MoveWindow(ComboMod.hwnd, pt.x, pt.y, ComboMod.Width, newHeight, True)
the combobox appeared but the code didn't set the new list length.
it seems that this code also places my combobox somewhere in the screen and not where it originaly was.
this code works for 'RealisticGraphics' (he gave it to me).
i also applied it to a new project and it worked.
on my project it doesn't and also when i removed every other form and every code from my module the project still didn't work correctly (the combobox moved to somewhere else on the screen).
if you could help me somehow it'll be really great.
-
Jun 23rd, 2001, 03:53 PM
#2
The most common cause of this is an incorrectly defined API call or TYPE or constatant. Check that all of the top section is in a module, for reference it is easier to place the code in a module of its own and call it something like mod_ResizeCombo
It does seem strange that it works on its own but not in your project. If you have done all of the above the only alternative i can offer is that you send me the one form that you are working on and the module to go with it and i will try and find the problem. Soz i know most people dont want to do that but i cant think of any other reason without looking at the code already in the form.
Grant French
[email protected]
-
Jun 23rd, 2001, 05:29 PM
#3
thanks.. but..
thanks.. but the problem was solved long ago..
the problem was that the combobox was inside a frame.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|