Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the option strings for an MFC Combo Box stored?

Given a resource file, containing a combo box definition, for a C++ MFC program, is there a way to programmatically obtain the option strings?

When defining a dialog in the Visual Studio resource editor, one can specify the options with a ;-delimited string. Where are these strings then stored? I understand as well that one can programmatically add strings to the dialog box during dialog init, obtaining them is another story.

Nevertheless, my problem is that I don't have access to the dialog object, neither is it visible at the time I wish to obtain the option strings. Is that even possible?

like image 706
Mike Caron Avatar asked Dec 04 '25 13:12

Mike Caron


1 Answers

You can create a member variable for combobox or

CComboBox* pBoxOne;
pBoxOne = (CComboBox*) GetDlgItem(IDC_COMBO1);

  CString str, str2;
  int n;
  for (int i=0;i < pBoxOne->GetCount();i++)
  {
    n = pBoxOne->GetLBTextLen( i );
    pBoxOne->GetLBText( i, str.GetBuffer(n) );
    str.ReleaseBuffer();

    str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
    afxDump << str2;
   }

The option strings are stored in the resource file itself. I have added options as 1;2;3 and the resource file entries are

IDD_MFC_DIALOG_DIALOG DLGINIT
BEGIN
    IDC_COMBO1, 0x403, 2, 0
0x0031, 
    IDC_COMBO1, 0x403, 2, 0
0x0032, 
    IDC_COMBO1, 0x403, 2, 0
0x0033 
END
like image 87
Jeeva Avatar answered Dec 07 '25 02:12

Jeeva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!