Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to write a program in mfc and in the main dialog if you click a button I want to display another dialog using
sampledlg.DoModal();

and in it I want to use:
listbox.AddString(L"str1");

but I get an error and I can not add strings. please tell me why?
Is this for making another dlg with DoModal() function?

thanks.
Posted

1 solution

Instead of DoModal() try to put your initialization to virtual BOOL OnInitDialog() if its not there already. It was long ago I used MFC for the last time but I think that at the time DoModal() is called not all the underlying resources (HWNDs) are created, but when InitDialog() runs, they already exist (including your listbox). Another common mistak I made a lot of times when I started MFC is that I haven't attached the MFC objects to the underlying controls (HWNDs) in either DoDataExchange() with DDX_Control() or in InitDialog() with SubClassDlgItem().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900