Size of the drowpdow list of a combo box

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);




0
mcorazao (18)
8/13/2004 4:20:04 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
821 Views

Similar Articles

[PageSpeed] 42

Miguel Corazao wrote:
> 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.
0
trevor8686 (35)
8/13/2004 9:03:28 PM
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:

>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: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
8/15/2004 12:07:53 AM
Reply:

Similar Artilces:

File view doesn't list an expected source file
Hi, File view isn't showing a file it should show. One of the last steps needed to add Help support to an existing project is to compile MyProject.hpj. To do this, msdn says that I should go to File view, open the source files list, highlight MyProj.hpj, and then select "Compile MyProject.hpj" in the Build menu. MyProject.hpj is not in the Source files list, thogh. Can someone tell me why it isn't there? The file exists in my project's MyProject\hlp directory as a result of copying the sample project's hlp directory to my project, and renaming the files so th...

How do I get a dialog box asking if I want to open a downloaded do
When I download a document, I would like a pop-up box to ask if I want to open the document. On Wed, 24 Feb 2010 18:02:01 -0800, Ron <Ron@discussions.microsoft.com> wrote: >When I download a document, I would like a pop-up box to ask if I want to >open the document. It seems to me that would be a function of whatever program you're using to do the downloading. Is that Word? -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. ...

Text box disappears on chart
I added a text box to a chart and when I click off of it, the text box disappears (goes behind the chart). I have tried Bring to Front and Bring Forward, and it may or may not stay visible and print. I have clicked on the frame of the text box (it changes pattern) and tried Bring to Front - same problem. Any ideas? Carole O The text box is on the worksheet, not the chart. To fix the problem, Select the text box, and choose Edit>Cut Select the chart (you'll see handles on its corners and sides) Choose Edit>Paste, to paste the text box onto the chart. Click away from the char...

How can I get the selected item number from a combo box?
How can I get the selected item number from a combo box. Say that combo has only two items: (Madam;Mister). If "Madam" is selected, I would like to get item number of Madam < it is zero in this example. Thank you You refer to the value via the name of the control. If it is multi-column, you append .column(number) to the name where number is 0 for the first column. -Dorian "mezzanine1974" wrote: > How can I get the selected item number from a combo box. Say that > combo has only two items: (Madam;Mister). > If "Madam" is selected, I would like to g...

Drop Down List Question #2
I have a drop down list from 5 cells merged together so as I can read the length easier, I know I cant select a field from merged cells, is there any way that when I select my choice I can get cells either side of my selection A B F 12 Jan Apples $12.00 17 Feb. Pears $14.00 I have B Column as my range in drop down , how can I get the date and price to move as well? What I want to do is select Pears and the date, Item and price would move to say K L P Columns if my drop down list was in L column...

Smart List search criteria
It would be helpful if 'ends with' was added as an operator in SmartList's search criteria. ...

Suddenly, to-do list is broken
Good afternoon. Thanks for letting me part of this forum. I am using Outlook 2007. Things have been rolling along very well. Thi morning I closed Outlook while I left for a while. Now that I am back whenever I open Outlook my to-do bar will not display any tasks (no will they show in the task list in the week view of the calendar) Instead, there is a message saying, "The Operation Failed. An objec could not be found." The tasks are still there and I can access the via the tasks tab, but the to-do bar and the calendar are missing th tasks, which is what really made me fall in love w...

Increasing recently opened files list
Does anyone know how to increase number of files shown in recently opened files list? Mine shows four, and I'd like eight or ten, the same as I get in all my other MS applications. Any auggestions?? Thanks. tabboo wrote: > Does anyone know how to increase number of files shown in > recently opened files list? Mine shows four, and I'd like > eight or ten, the same as I get in all my other MS > applications. Any auggestions?? Thanks. =================================== What is the name and version of the program you are referring to? -- John Inzer return e-mail disabled...

Show Names drop down box not working
I recently graduated to Office 2003 and I'm having a problem I don't know how to get around. I want to send this email to a large number of people, so I want to select several names from one of my contacts folders. But it won't let me. Here are the steps I'm going through: From the Mail Screen, New, To, then I want to click on the "Show Names from the" drop down box, but it won't let me. When I click on the drop down arrow, nothing happens. I have used Outlook in its various versions for years and have always used this feature. These files were imported fr...

How do you create a list with name address phone in a column form.
I have an excel file with last name, first address city state in each column. I want to prepare a two column report with each persons name first then address then phone. Can't remember how to print out a different view of excel. Making it look more like a two column word document. Maybe you can use MSWord's MailMerge. http://www.mvps.org/dmcritchie/excel/mailmerg.htm http://www.mvps.org/word/FAQs/MailMerge The first is from David McRitchie and the second is by Beth Melton and Dave Rado. denise108 wrote: > > I have an excel file with last name, first address city state ...

hyperlink list in excel that stays put when it jumps to linked cel
I am trying to use internal hyperlinks in a huge sheet but want the hyperlinks to remain in view - and just for good measure, it has to open with the links visible on other machines. Any suggestions would be much appreciated, TIA ...

send/receive dialogue box #2
I have ticked the box to remove details from my send/receive dialogu box. Cannot find how to get it back to show any errors etc. Thanks for any help Philk:confused ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com ...

Exchange 5.5 Distribution Lists
I am running in Exchange 5.5/2000 mixed mode and I have noticed that if I change ownership of a distribution list using Exchange Admin, the permissions of that object are not automatically updated (I have to manually give the "owner" the permission needed to add members to the list). Is this some old Exchange 5.5 thing??? ...

delegates permission using a distribution list
I am having problems with permissions on delegates in Outlook. I have a distribution list which has editor rights in a users calendar. When I try and access the calendar it doesn't work. When I go back into the delegates properties again the permission has gone back to NONE. It does however work fine on some clients. Outlook 2000 is being used and Exchange 2003. Convert the DL to a security group. "Gareth Hutchins" <anonymous@discussions.microsoft.com> wrote in message news:29a401c4ad33$4bb88de0$a601280a@phx.gbl... > I am having problems with permissions on d...

Listing a selection of data from one worksheet on another
At the moment I have a worksheet with a list of client in one column and then in another column that uses an IF formula to display either the number of days to the deadline or text which says No Deadline. What I want to do is enter some kind of formula so that a list of clients with deadlines between 1 and 7 days appears on another worksheet automatically with the number of days to the deadline next to them. To make it even harder the list is currently in name order but on the new worksheet I would like it to automatically appear in days til deadline order with lowest number of days a...

Using check boxes to limit a report.
I have a table which lists all possible items for a vendor. I want to create a form that shows all of the items. I want the user to be able to place check marks next to the items they want. I then want to run a report which shows all of the information about the items, but only for the items that had been checked. What is a good way to approach this? I can't seem to find a way to link the check boxes to the item table and don't know how to create a report once they are linked. Can someone please direct me on how to do this? Or at least to somewhere that I can find out how to do ...

Adding the users name to a new list item
Is there a way to create a list so that when the logged in user creates a new item, it automatically insert's their user name into a column? I'm creating a time entry list, and don't want the users to have to type their name in every time they add a time record. The controller will review this list once a week and create reports based on the user, client, etc. Thanks in advance! Gavin Use the Created by column. -- Daniel A. Galant Imagine what we could be... if we could just imagine. "Gavin Steiner" <gavin@interprom.com> wrote in mes...

MSN Stock Watch List in Money 2006 Deluxe Portfolio Manager
I inadvertently deleted the MSN Stock Watch list from my Portfolio Manager. Now, despite the list still being in existence under my Passport, I cannot seem to restore it intact into Portfolio Manager via either Money 2006 Deluxe or MSN Money. I'd greatly appreciate any insight from those who may know how to restore this list as an active Portfolio Manager account, which would be much more preferable to creating a new watch list, which would not only not auto-sync with the entries made from the MSN pages, but would also require re-entry of the huge list I have now. I really want m...

Max size of OST files
Hi all, I'm making this post on behalf of a friend. They have a single Exchange2000 server. Not sure if it's SBS or Exchange2000 Std. There are approx 20 mailboxes on this server. The users all use Outlook 2003 (SP3) as their mail client and Outlook's account type is Exchange and not POP3 or IMAP. One of the users mailboxes is approx 6Gb in size. What they would like to do is use offline mode to create a .ost file of this persons mailbox for his laptop however the file limit on ost files appears to be 2Gb. We did find a MS k/b article that explained how to create the requi...

Drop Down boxes #8
I want to create a drop down box where if no options are used within the drop down, then you are able to type your own answer You can enter any item in a cell with a data validation list, if you remove the check mark from 'Show error alert after invalid data is entered', on the Error Alert tab in the Data Validation dialog box. The box is shown here: http://www.contextures.com/xlDataVal04.html#Error Brian wrote: > I want to create a drop down box where if no options are used within the drop down, then you are able to type your own answer -- Debra Dalgleish Excel FAQ...

setup a text box as a lined page
I'd like to simulate text on lined paper. Is it possible in Word or Publisher? Thanks Find a lined paper background or graphic, put it on the Master page. On the the publication page create a text box. View, turn on baseline guides. Go to Arrange, Layout guides, baseline tab, adjust it to match your lined graphic. Select the text box, Format, paragraph, check align text to baseline guides. http://images.google.com/images?hl=en&q=lined+paper&gbv=2 -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "tridev" <tr...

Outlook 2003: How to show multiple task lists?
Does anyone know if it is possible to show multiple task lists (i.e. a personal list and a work-related list) side by side in the task list view by default? It's simple in the calendar to show two calendars simultaneously, and it seems completely ridiculous not to include the same functionality in the task list view. Any help would be appreciated. No, but you can use the right click on the additional task list you want to display and select "Open in new window" - then resize your windows to show them side by side. Why would one want to show task lists in the same way as cal...

Zoom Size in a Report
All the reports in my database (AC2000) open at 100% in printpreview. the database is split and the backend is on only 1 unit. I have the database on 5 PCs: 3 local and 2 in another state. the local user has 2 desktop units and 1 laptop. the remote user has one of each, both with the frontend resident and the backend on an external hard drive that can be switched as necessary. The problem is that all reports open as 'Fit' on both remove units but as 100% on the local units. I have checked and 'Track name Auto Correct' is NOT checked on any PC. why wou...

Combo box for related records AND non-related records
Hello, Sorry if this question has been answered, but my searches have not yielded the posts. Here is what I want to do: I have a form with a combo box for City and one for State. I have two lookup tables: lkpCity cityID, City, stateID lkpState stateID, State I have the combo box for City set up, and the one for State to depend on the control for City. These are necessary because we've got a lot of spelling errors. Very often, however, the respondents whose data we are entering fail to provide a city, but list their state. If this happens, I can't get a l...

What is the size limit of the notes field in an Outlook contact re
When I looked at the properties of the notes field within a contact record in Outlook, it displayed he following information Field Properties Name: Notes Type: Integer Format: 1,234 I was expecting a memo or text data type? ...