MFC ComboBox and get the number?

This is a discussion on MFC ComboBox and get the number? within the C++ Programming forums, part of the General Programming Boards category; I've created a Combo Box in my MFC Dialog and would like to get the integer number which I select, ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    9

    MFC ComboBox and get the number?

    I've created a Combo Box in my MFC Dialog and would like to get the integer number which I select, for example:

    Code:
    void CCOMPort_ReaderDlg::ReadDevice()
    {	
    	CHAR DeviceTermSize [6];
    	
    	m_DeviceNumber.ResetContent ();
    	
    	for ( int nDevice = 1; nDevice <= 8; nDevice++ )
    	{
    		sprintf ( DeviceTermSize, "%ld", nDevice );
    
    		m_DeviceNumber.AddString ( DeviceTermSize );
    	}
    	
    	m_DeviceNumber.SetCurSel ( 1 );
      
           // int PortNumber = ??? ;
    
    }
    I have no problem to select any number from 1 to 8 in the ComboBox but I need to get the number which I select to be applied in the function: CSerialSource::Open(PortNumber); "

    This is very important to my serial communication to select the Port Number and let my program know what I have selected.

    How can I obtain the "PortNumber" value? Any suggestion and help is well appreciated. Thanks!
    Last edited by coolrox86; 05-06-2010 at 04:08 PM.

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Since you're using Microsoft libraries, make MSDN (msdn.microsoft.com) your friend.
    Code:
    I type in: CComboBox
    Results: CComboBox Class (MFC), CComboBox Members (MFC)
    Well, hey, that looks helpful. *Click* CComboBox Members. (scroll scroll scroll) What's this? GetCurSel()? That sounds like a function the GETs the CURrent SELection. *Click* GetCurSel.

    Problem solved.
    Consider this post signed

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21