Solved

Accessing a MFC combo box

Posted on 2004-08-04
7
1,533 Views
Last Modified: 2013-11-20
Hi,

1. how do I get the pointer/reference of a combo box object that I added in the MS VS 2003 GUI editor and that has got the ID "IDC_COMBO1"?

2. how do put some static strings into it's list?

3. how do I restrict the combo box to allow only the strings from the list (no manual typing)?

BTW, I'm a absolutely new to MFC and win32 but have got some C++ expirience.

Thank you for efforts.
0
Comment
Question by:x4u
  • 4
  • 2
7 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 350 total points
ID: 11718075
go to ClassWizard (Ctrl-W)
select your dialog object
select the "member variables" tab
your control label will appear, select it
press the "Add variable" button, another dialog will appear
here is the trick: write a variable name and in the "category" choose "control"
now your dialog has a proper initialized member you can use to pass any message

0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 350 total points
ID: 11718135
to avoid user to "type" another string, just go to dialog GUI editor, select combo box properties, and change style to "Drop list" (not drop down)

0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 150 total points
ID: 11718236
After creating your control var - m_cmboXYZ you can add strings like this

m_cmboXYZ.AddString("One");
m_cmboXYZ.AddString("Two");

The default behaviour is to sort them, you can stop this in the resource editor - it's one of the settings.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 350 total points
ID: 11718258
2. how do put some static strings into it's list?

In the resource editor you can insert your static list in combobox properties, "data" tab.
0
 
LVL 11

Author Comment

by:x4u
ID: 11719182
Thank you, adding items works fine now.

But the drop down list height seems to be zero, it is appears only a thick black line. I can browse the items with the cursor keys but how do I resize the list box height to a reasonable height? Can I set set it to resize automatically somehow?

BTW, I get is the same behaviour with AddString and when I type the strings into data properties field.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 350 total points
ID: 11719261
About the control height, it is a common error:
Comboboxes have 2 height: Edit portion height and drop-down list height. You have not resized the second.

Go to dialog GUI editor, select your combobox, the bounding rectangle will be selected, now press on the drop-down arrow, a diferent rectangle will be selected, drag lower boundary to desired size. That's all.
0
 
LVL 11

Author Comment

by:x4u
ID: 11719424
Ahh, cool thanks. I would never have figuered this out myself. ;-)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now