3
votes

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?

1

1 Answers

2
votes

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