Adding items to a list box in a dialog. [modified]
-
The following refers to an application I am writing in VC++ 6. I want to add some items to a list box in a dialog. I understand that this involves something called DDX, which, as far as I am aware is something that the IDE sorts out for me. I have added a public variable to the dialog class via the Class Wizard to be associated with the List box - m_listGTTimeUnits. Now, the application is a Windows Explorer style application and the dialog appears when I right-click over the right hand pane. I have tried a couple of ways to add values to the list box, both of which allow the code to compile but cause the program to crash with the message "Debug assertion failed" when the dialog is called... Firstly...
void CRightView::OnRightmenuEditnode() { ... CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days"); ...
and secondlyvoid CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ...
If anyone has any idea of what it is that I am doing wrong, I would be very glad to hear! Thanks, Ben.modified on Saturday, January 26, 2008 10:47:25 AM
-
The following refers to an application I am writing in VC++ 6. I want to add some items to a list box in a dialog. I understand that this involves something called DDX, which, as far as I am aware is something that the IDE sorts out for me. I have added a public variable to the dialog class via the Class Wizard to be associated with the List box - m_listGTTimeUnits. Now, the application is a Windows Explorer style application and the dialog appears when I right-click over the right hand pane. I have tried a couple of ways to add values to the list box, both of which allow the code to compile but cause the program to crash with the message "Debug assertion failed" when the dialog is called... Firstly...
void CRightView::OnRightmenuEditnode() { ... CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days"); ...
and secondlyvoid CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ...
If anyone has any idea of what it is that I am doing wrong, I would be very glad to hear! Thanks, Ben.modified on Saturday, January 26, 2008 10:47:25 AM
Ben Aldhouse wrote:
CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days");
Ben Aldhouse wrote:
void CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ...
In the above handlers, you created an instance of your dialog but you never created the dialog window. Why do you need to update the list box from the view? Cannot you update it from the dialog itself?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Ben Aldhouse wrote:
CEditNodeDlg dlg; dlg.m_listGTTimeUnits.AddString("days");
Ben Aldhouse wrote:
void CRightView::OnRightmenuEditnode() { ... CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS); pList->AddString("days"); ...
In the above handlers, you created an instance of your dialog but you never created the dialog window. Why do you need to update the list box from the view? Cannot you update it from the dialog itself?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]These are just snippets, I have the following lines later on
if (dlg.DoModal () == IDOK) { myPNode->SetNodeDescr(dlg.m_strNodeDesc); if (dlg.m_strNodeDesc != oldDesc) pDoc->SetModifiedFlag(); }
I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...bool CEditNodeDlg::OnInitDialog() { m_listGTTimeUnits.AddString("days"); } but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.
-
These are just snippets, I have the following lines later on
if (dlg.DoModal () == IDOK) { myPNode->SetNodeDescr(dlg.m_strNodeDesc); if (dlg.m_strNodeDesc != oldDesc) pDoc->SetModifiedFlag(); }
I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...bool CEditNodeDlg::OnInitDialog() { m_listGTTimeUnits.AddString("days"); } but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.
Ben Aldhouse wrote:
I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...
This is the way to go.
Ben Aldhouse wrote:
bool CEditNodeDlg::OnInitDialog()
Replace
bool
withBOOL
. BTW Why don't you make the Visual Studio make the work for you (select your dialog on class explorer, right click and chooseAdd Windows Message Handler
item)?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
These are just snippets, I have the following lines later on
if (dlg.DoModal () == IDOK) { myPNode->SetNodeDescr(dlg.m_strNodeDesc); if (dlg.m_strNodeDesc != oldDesc) pDoc->SetModifiedFlag(); }
I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...bool CEditNodeDlg::OnInitDialog() { m_listGTTimeUnits.AddString("days"); } but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.
I've got it! Thanks for your help! Basically I needed to change 'bool' to 'BOOL'.
BOOL CEditNodeDlg::OnInitDialog() { CDialog::OnInitDialog(); m_listGTTimeUnits.AddString("days"); return TRUE; }
-
Ben Aldhouse wrote:
I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...
This is the way to go.
Ben Aldhouse wrote:
bool CEditNodeDlg::OnInitDialog()
Replace
bool
withBOOL
. BTW Why don't you make the Visual Studio make the work for you (select your dialog on class explorer, right click and chooseAdd Windows Message Handler
item)?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]Thanks!