Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box, extremely simple

Status
Not open for further replies.

bkelly13

Programmer
Aug 31, 2006
98
US
Visual Studio 2008, MFC, Windows XP
I created a combo box with a drop down that displays the numbers 01 through 12. The range will never change. The name is IDC_STREAM_NUMBER. After creating an even handler the name IDS_STREAM_NUMBER doesn't like putting the -> or . (dot) notation after it.

I cannot figure out how to get the selected number from the combo box into my code.
Its the simple stuff that eats my lunch.

Thank you

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
You probably need to get the handle first with GetDlgItem(IDC_STREAM_NUMBER). If you assign that to a CComboBox (or something very similar in spelling), then you can access the methods from the combo box.
 
Thank you for that tip, so armed I was able to figure some things out. But I am not quite there yet.

I created the combo box and hardcoded the display values as: 1;2;3;4; and up through 12. When the code runs the combo box is displayed and the drop down shows the available selection. So far so good.

To add a varible I right clicked on the combo box, selected add variable, and changed to not be a control variable. Then I added an event handler and in there wrote:
Code:
void COMEGAUserApplicationExampleDlg::OnCbnSelchangeIdcStreamSelect()
{
   // TODO: Add your control notification handler code here
   BOOL translated_ok = true;
   BOOL is_signed     = false;
   CWnd *temp = GetDlgItem( IDC_IDC_STREAM_SELECT );
   m_stream_selection = temp->GetDlgItemInt( IDC_IDC_STREAM_SELECT,
                                          &translated_ok,
                                          is_signed );
   

}
After setting a break point at the exit brace, ran the code. After selecting "2" from the combo box the value of m_stream_selection is 0 and variable translated_ok is 0. (It was initialized to true to verify that the function really was changing the value.)

The goal is to wind up with the user's selection number in variable m_stream_selection. What do I have wrong here?

Before posting it occurred to me: Should I delete temp before exiting this method?

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
Try
Code:
   BOOL translated_ok = true;
   BOOL is_signed     = false;
   m_stream_selection = GetDlgItemInt( IDC_IDC_STREAM_SELECT,
                                          &translated_ok,
                                          is_signed );
   
[/CODE}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top