Thread: MFC ComboBox and get the number?

  1. #1
    Registered User
    Join Date
    Apr 2010

    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:

    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 03:08 PM.

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Since you're using Microsoft libraries, make MSDN ( your friend.
    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