This is a good example of how messy working with MFC can be. Something apparently so easy could take a lot of time to figure out, so here you can find two easy ways out:
1) Designer - through the designer by default you can just resize the ComboBox width. If you want to resize the Drop Down List height you need to click on the dropdown arrow on the right, then you'll be able to resize the dropped control height. This seems so easy but if no-one tells you it's anything but intuitive. If you just need to statically fix height this'll save you a lot of bitchin'.
2) Programmatically - use the following function to programmatically resize you dropped control height. The function takes as input the number of items you want to display, but if you wanna modify it to take pixels or whatever as parameter it shouldn't be too hard (unless you're brain damaged as Scuffia is).
1) Designer - through the designer by default you can just resize the ComboBox width. If you want to resize the Drop Down List height you need to click on the dropdown arrow on the right, then you'll be able to resize the dropped control height. This seems so easy but if no-one tells you it's anything but intuitive. If you just need to statically fix height this'll save you a lot of bitchin'.
2) Programmatically - use the following function to programmatically resize you dropped control height. The function takes as input the number of items you want to display, but if you wanna modify it to take pixels or whatever as parameter it shouldn't be too hard (unless you're brain damaged as Scuffia is).
void SetDropDownHeight(CComboBox* pMyComboBox, int itemsToShow)
{
//Get rectangles
CRect rctComboBox, rctDropDown;
//Combo rect
pMyComboBox->GetClientRect(&rctComboBox);
//DropDownList rect
pMyComboBox->GetDroppedControlRect(&rctDropDown);
//Get Item height
int itemHeight = pMyComboBox->GetItemHeight(-1);
//Converts coordinates
pMyComboBox->GetParent()->ScreenToClient(&rctDropDown);
//Set height
rctDropDown.bottom = rctDropDown.top + rctComboBox.Height() + itemHeight*itemsToShow;
//apply changes
pMyComboBox->MoveWindow(&rctDropDown);
}
Keep the butchering up.
32 comments:
Me too! Thanks!
Me three! Damn, I have been fighting with that problem for two nights now! My drop down list wouldn't show, I just saw a thin shitty line. At first I thought it was my initialization gone wrong, but then I discovered I could scroll the items into view. It got to the point where I was convinced that it was a Z-ordering issue (because I had other controls just below the list) and that my drop down list was being overlapped/hidden by other controls. This crap just isn't very intuitive at all.
Thanks man!
Kris
Cheers - I discovered it the hard way myself :)
Thanks for the tip! it is great!
It really helped me. thanks to whoever had written this code. I have been fighting with that problem for 1 day. Thanks thanks..great work
This helped me too! thanks for the info! the butchering continues....
the butchering never stops :-)
Yes yes, months later, but thanks to your article and Google just saved me a heck of a headache.
Muchas Gracias!
You saved my skin!
Bless you
Same here. I would have never guessed it.
Two years later and still helpful. Thanks man.
"Two years later and still helpful. Thanks man."
I Suscribe to that comment. Thank you very much.
MFC :-(
This post :-)
linked from google to digg (weird, i know) to here and it's exactly what I needed. click on the dropdown area? wtf.
This article is still going strong. Could not for my life figure out this on my own. Many thanks!
This is very useful!!
Thank you.
Thank you very much
4 years later and your code is still saving lives!
You da man!
THANKS!
I wasted so much time looking for ways around this and getting rid of that stupid scroll bar. Thanks so much!
Same here. Already spent an hour on this stupid thing!! Thanx a lot :)
Yep, having to deal with old shitty MFC in VS2005, I was tearing my hair out for 30 minutes on this until I found your page. Lifesaver!
Wasted an hour before coming across this point. Four years and still going strong...
Thanks a ton. I hour down the drain for me :(
you are a genius, saved a lot of a lot of time .........................................................................
April 2013, still using these f**** mfc...
Still stuck on the same problems...
Thanks for the tip.
2013, you still rock!
Thank you very much for your help
Thanks! Thanks! Thanks!!!!
Thank you!
Thanks again!
Thx very much !
good one
Post a Comment