Board index » Visual Studio » Size of the drowpdow list of a combo box

Size of the drowpdow list of a combo box

Visual Studio129
Below is my attempt at creating a combo box. The item is correctly

displayed, but the dropdown list has a size of zero. How can I change this

so I can see the options?

Thanks for your help.



Miguel





HWND hWnd = GetSafeHwnd();

CWnd *dialog = CWnd::FromHandle(hWnd);

RECT ctlRect;

ctlRect.left = 130;

ctlRect.top = 50;

ctlRect.right = 220;

ctlRect.bottom = 80;

outputVolumeCB = new CComboBox();

ret =

outputVolumeCB->Create(WS_VSCROLL|CBS_DROPDOWN|CBS_DISABLENOSCROLL|CBS_HASST

RINGS,ctlRect,dialog,102);

outputVolumeCB->ShowWindow(SW_SHOW);

outputVolumeCB->AddString("Y - Brief");

outputVolumeCB->AddString("N - Full");

outputVolumeCB->AddString("L - Medium");

outputVolumeCB->SetCurSel(1);


-
 

Re:Size of the drowpdow list of a combo box

Miguel Corazao wrote:

Quote
Below is my attempt at creating a combo box. The item is correctly

displayed, but the dropdown list has a size of zero. How can I change this

so I can see the options?

Thanks for your help.



Miguel





HWND hWnd = GetSafeHwnd();

CWnd *dialog = CWnd::FromHandle(hWnd);

RECT ctlRect;

ctlRect.left = 130;

ctlRect.top = 50;

ctlRect.right = 220;

ctlRect.bottom = 80;

outputVolumeCB = new CComboBox();

ret =

outputVolumeCB->Create(WS_VSCROLL|CBS_DROPDOWN|CBS_DISABLENOSCROLL|CBS_HASST

RINGS,ctlRect,dialog,102);

outputVolumeCB->ShowWindow(SW_SHOW);

outputVolumeCB->AddString("Y - Brief");

outputVolumeCB->AddString("N - Full");

outputVolumeCB->AddString("L - Medium");

outputVolumeCB->SetCurSel(1);











It's been a while since I've done it that way, but I think Windows uses

the height you pass in to the combobox to determine the dropdown height.

You passed in a height of 30 (80-50). The "average" height of a

control on a default Windows setup is ~25. So, that leaves you with

about 5 pixels to display your dropdown. Change your height and it will

work.



ctlRect.left = 130;

ctlRect.top = 50;

ctlRect.right = 220;

ctlRect.bottom = 100; // for starters..recompile and see how it affects

the height.

-

Re:Size of the drowpdow list of a combo box

First, there is always a question as to why it is necessary to create a control at

runtime. THere are lots and lots of very good reasons, and a near-infinite number of

really bad reasons.



Assuming you have a good reason, then you should eliminate every one of those numbers.

What does "130" mean? Nothing. It means 130 pixels from the left edge, in some resolution,

for some display driver. It is a completely meaningless number. Likewise, 50, 220, and 80

are all nonsense numbers. If they happen to work this week, on your machine, with the

current video driver and display, you win. For every other machine in the known Universe,

you can assume they are wrong.



The 102 is a meaningless number. Why do you think 102 is available as a control ID? Given

that you know the coordinates and the control ID, it looks like this is one of those

places where the only reasons for creating the control at runtime are bad reasons, so

perhaps you should reconsider why you are doing this at runtime.



Given you have done this, you have no way to couple the control to any handler functions.

There is even a serious question as to why you need to do a 'new' to create a combo box at

a fixed place; simply declaring a member variable would do the job.



You are also hardwiring constant strings into the program, which is another bad idea.



You might want to check out my dynamically-resizing combo box from my MVP Tips site, or my

CIDCombo box class, which dynamically adjusts the size of the combo box.



Why are you doing GetSafeHwnd() and CWnd::FromHandle when 'this' would have sufficed for

the same purpose?



What I see here are ten lines of code that probably don't need to exist, and three which

are not well-structured, and one which is almost certainly incorrect (why SetCurSel(1)?

What makes you assume that 1 is the right value?)



Read my essays on combo boxes, and most of my "Dialog Box" series, so you can avoid doing

things like this. The code should take two lines. One to load all the values, and one to

select a specific value NOT by its position. I would do this as



in the class definition for what I'm going to call CMyDialog:

CIDCombo outputVolumeCB; // from the CComboBox outputVolumeCB declaration

// added by

ClassWizard



typedef enum {Brief, Full} outputVolume;



static const IDData values[] = {

{ IDS_BRIEF, CMyDialog::Brief }.

{ IDS_FULL, CMyDialog::Full}

{0, NULL }

};



BOOL CMyDialog::OnInitDialog()

{

...

outputVolume.LoadValues(values);

outputVolume.Select(Full);

....

}



(I may have misremembered the exact method names of my class, but you get the idea)



This will resize the combo box each time, and it is independent of knowing the control

IDs, dimensions, etc.

joe







On Fri, 13 Aug 2004 16:20:04 GMT, "Miguel Corazao" <mcorazao@cwbeilfuss.com>wrote:



Quote
Below is my attempt at creating a combo box. The item is correctly

displayed, but the dropdown list has a size of zero. How can I change this

so I can see the options?

Thanks for your help.



Miguel





HWND hWnd = GetSafeHwnd();

CWnd *dialog = CWnd::FromHandle(hWnd);

RECT ctlRect;

ctlRect.left = 130;

ctlRect.top = 50;

ctlRect.right = 220;

ctlRect.bottom = 80;

outputVolumeCB = new CComboBox();

ret =

outputVolumeCB->Create(WS_VSCROLL|CBS_DROPDOWN|CBS_DISABLENOSCROLL|CBS_HASST

RINGS,ctlRect,dialog,102);

outputVolumeCB->ShowWindow(SW_SHOW);

outputVolumeCB->AddString("Y - Brief");

outputVolumeCB->AddString("N - Full");

outputVolumeCB->AddString("L - Medium");

outputVolumeCB->SetCurSel(1);









Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-