本程序实现 Visual Studio 风格的列表框(A VisualStudio-like ListBox class),如图:
// This class overrides the OnBrowseButton method.
class CMyListBoxEx: public CListBoxEx
{
public:
virtual void OnBrowseButton( int iItem )
{
iItem;
CSHBrowseDlg dlgBrowse;
if ( dlgBrowse.DoModal() ) SetEditText( dlgBrowse.GetFullPath() );
};
};
class CListBoxExDemoDlg : public CDialog
{
// Construction
public:
// standard constructor
CListBoxExDemoDlg(CWnd* pParent = NULL);
// Dialog Data
//{{AFX_DATA(CListBoxExDemoDlg)
enum { IDD = IDD_LISTBOXEXDEMO_DIALOG };
CMyListBoxEx m_ListBoxEx;
//}}AFX_DATA
};
If you want to use also the buddy class, drop a button on the dialog, change its properties and make it owner-draw and with a client edge.
Then, in your dialog OnInitDialog() subclass the button control in this way:
// Add the listbox buddy m_ListBoxExBuddy.SubclassDlgItem( IDC_LISTBUDDY, this ); m_ListBoxExBuddy.SetListbox( &m_ListBoxEx )