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

Problem with Creating CListBox 1

Status
Not open for further replies.

Captrick458

Programmer
Mar 27, 2005
37
US
I am trying to create a CListBox, and it works if I use

CListBox *pTheList=new CListBox;
pTheList->Create(...
pTheList->AddString(...

however, if I use the following, it will not work.

CListBox TheList;
TheList.Create(...
TheList.AddString(...

The compiler does not complain, and there are no complaints at runtime, TheList just is not visible. According to the MS documentation, either construct should work.

Any advice will be greatly appreciated.

Rick

 
The listbox is destroyed at the end of the routine because it is on the stack. Where is your loop? Is it within the same routine as the listbox creation or somewhere else? If it is in the same routine then it is another problem (no idea what though). Easy way to test
Code:
class MyListBox: public CListBox
{
public:
   ~MyListBox()
   {
      MessageBox (NULL, _T("No more listbox"), _T("Destructor"), MB_OK);
   }
};

...
MyListBox TheList;
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top