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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a Combo Box

Status
Not open for further replies.

mpsoutine

Programmer
Jan 6, 2003
87
US
Hi All,


In the following book I am using there is an example for working with Combo Boxes. It states "The Combo Box is populated from within the dialog box's OnInitDialog() function. To do this, first add a new member function named PopulateCombo() with return type void. Then edit OnInitDialog().

BOOL CDialog::OnInitDialog()
{
.
.
.
PopulateCombo();
return true;
}

I did manually add the PopulateCombo()and update the ListDlg.h file

My question is there a way to use the Class Wizard to do this.

Second question. After compiling and running the program I tried to open the Class Wizard and received the following error message:.

parsing error: Expected ";"
Input line void PopulateCombo();

I did not get this message yesterday.

MPSoutine
 
It sounds like the line above the error input line may be missing the trailing semicolon. Could you possibly add some more of the code around where the error is to your message?

--Rob
 
Hi Rob,

Here is the code: The funny thing is that it will compile and run. When I try to open the Class Wizard I get an error message popup: Parsing error: Expected "afx_msg" Input Line: "void PopulateCombo". I did put afx_msg in front of PopulateCombo() and things seem fine.

My main question is could I use the Class Wizard to add this function?

Header File ListExDlg.h

// ListExDlg.h : header file
//

#if !defined(AFX_LISTEXDLG_H__8D87AD57_5C3E_43A8_B375_E70BC67FADD6__INCLUDED_)
#define AFX_LISTEXDLG_H__8D87AD57_5C3E_43A8_B375_E70BC67FADD6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CListExDlg dialog

class CListExDlg : public CDialog
{
// Construction
public:
CListExDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CListExDlg)
enum { IDD = IDD_LISTEX_DIALOG };
CListCtrl m_lbDirDetails;
CTreeCtrl m_treeFiles;
CListBox m_lbSubDirs;
CComboBox m_cbMainDir;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListExDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CListExDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
void PopulateCombo();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LISTEXDLG_H__8D87AD57_5C3E_43A8_B375_E70BC67FADD6__INCLUDED_)

************************************************************
Here are the OnInitDialog() and PopulateCombo() functions in ListExDlg.cpp

OnInitDialog()

BOOL CListExDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
PopulateCombo();

return TRUE; // return TRUE unless you set the focus to a control
}

PopulateCombo()

void CListExDlg::populateCombo()
{
TCHAR szBuffer[MAX_PATH];

//Get the Windows directory, usually C:\Windows
//and add to the combo box

GetWindowsDirectory(szBuffer, MAX_PATH);
m_cbMainDir.AddString(szBuffer);


//** Chop off the directory to leave the drive letter C:
//** and add to the combo box


szBuffer[2]=0;

m_cbMainDir.AddString(szBuffer);

//** Get the System directory
//** Usually C:\Windows\System and add to the combo box

GetSystemDirectory(szBuffer, MAX_PATH);
m_cbMainDir.AddString(szBuffer);

//** Get the present directory and add to the combo box

GetCurrentDirectory(MAX_PATH, szBuffer);

m_cbMainDir.AddString(szBuffer);


}


 
Hi All,

Fixed the problem. No need to reply.

MPSoutine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top