Can you set the combobox height after creation?

I mean the height of the dropdown list. I know you must set the height in the call to CreateWindowEx but I want to adjust the height later. Is that possible?
Check out MoveWindow(). If I recall, it has the same four x, y, cx, and cy parameters as in the CreateWindowEx() function. SetWindowPos() likely would work too, but its a more complicated function.
I'm beginning to think this is impossible. Move Window and SetWindowPos only work when the combobox has the CB_SIMPLE style.
I don't think you know what you are talking about.

I just checked on an SDK style test example I have testing this very thing you are trying to do and it is working perfectly just as specified by the documentation. I have done this very thing countless times in multiple programming languages, and here is example code of my PowerBASIC example where I've created a combobox in WM_CREATE code processing. Note in the example below my code specifies the x, y, cx, and cy parameters of the CreateWindowEx() call as all zeros, and later in the procedure I use the hCtrl of the combobox returned by CreateWindowEx() in a MoveWindow() call where I specify the dimensions and locations as 20,10,120,150...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Function fnWndProc_OnCreate(wea As WndEventArgs) As Long
  Local pCreateStruct As CREATESTRUCT Ptr
  Local szNames() As Asciiz*16
  Local hCtrl,dwStyle As Dword

  pCreateStruct=wea.lParam  :  wea.hInst=@pCreateStruct.hInstance
  dwStyle=%WS_CHILD Or %WS_VISIBLE Or %CBS_DROPDOWNLIST Or %WS_VSCROLL
  'hCtrl=CreateWindow("combobox","",dwStyle,20,10,120,150,Wea.hWnd,%IDC_COMBOBOX,Wea.hInst,ByVal 0)
  hCtrl=CreateWindow("combobox","",dwStyle,0,0,0,0,Wea.hWnd,%IDC_COMBOBOX,Wea.hInst,ByVal 0)
  Redim szNames(5) As Asciiz*16
  szNames(0)="Frederick"
  Call SendMessage(hCtrl,%CB_INSERTSTRING,-1,Varptr(szNames(0)))
  szNames(1)="Elsie"
  Call SendMessage(hCtrl,%CB_INSERTSTRING,-1,Varptr(szNames(1)))
  szNames(2)="Scott"
  Call SendMessage(hCtrl,%CB_INSERTSTRING,-1,Varptr(szNames(2)))
  szNames(3)="Joseph"
  Call SendMessage(hCtrl,%CB_INSERTSTRING,-1,Varptr(szNames(3)))
  szNames(4)="Martha"
  Call SendMessage(hCtrl,%CB_INSERTSTRING,-1,Varptr(szNames(4)))
  szNames(5)="Ruth"
  Call SendMessage(hCtrl,%CB_INSERTSTRING,-1,Varptr(szNames(5)))
  Erase szNames()
  MoveWindow(hCtrl,20,10,120,150,%FALSE)

  fnWndProc_OnCreate=0
End Function 


Also note the styles don't have the CB_SIMPLE style. Like I said, you don't know what you are talking about.
Last edited on
I'm just telling you what happened. MoveWindow and SetWindowPos are doing nothing for the height. The combobox resizes itself to fit items until it gets the height of CreateWindowEx and then the scrollbar appears. If I set x, y, cx, cy, all to 0 in CreateWindowEx and try to resize it later the dropdown never appears.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DWORD style = WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS | CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST;

hwnd = CreateWindowEx(
	0, 
	WC_COMBOBOXEX, 
	NULL, 
	style, 
	CW_USEDEFAULT, 
	CW_USEDEFAULT, 
	200, 
	200,
	parent,
	NULL,
	GetModuleHandle(NULL),
	NULL);
If I were you I'd fool around with the styles. Its been my experience that when controls are behaving badly the problem is usually in the styles. I mean, when any control is putting itself together what it does is really controlled by the styles set for it.

I personally have never used WC_COMBOBOXEX to create a combo box. Maybe just try "combobox" or L"combobox" instead. Just an idea.

I have never used WS_CLIPSIBLINGS or CBS_NOINTEGRALHEIGHT styles. Can you live without those?

I'm just saying that I have never done those things and have never experienced the problem you are seeing.
Aha. I switch to WC_COMBOBOX and it works correctly. Not sure why I was using the other but thanks for pointing it out.
Yep, I found it out too. I get exasperated when somebodty tells me something doesn't work that I've never had fail in 20 years of Windows Api coding. So I put together a little test project in C++ and found it fails exactly like you said if I use L"comboboxex" as the szClassName parameter in CreateWindowEx().

I never even knew a "comboboxex" existed. Now I know it exists and doesn't work. Suits me fine. I'm 62 years old and won't use anything new. Won't update anything either. They keep me around though because everything I do works.
Topic archived. No new replies allowed.