Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

I am working on old code and int this code class is derived from CDialog and CListbox object is initialized in the DoDataExchange. Now i want to remove the window and make this list box a plane data structure, without initializing with DoDataExchange.

Question 1: how can i do it??
Question 2: how can i initialize list box without using Dodataexchage ??

I want to remove the inheritance from the Cdialog. This class earlier used to output the data in a dialog now i want to save the data in other format(not dialog based). So i want to remove the dialog and use the same data structure. Currently controls are initialized in DoDataExchange but now i don't want to use it and use the same list box as my data structure.

Looking for the early reply.

Thanks.
Posted
Updated 22-Sep-11 2:37am
v3
Comments
Philippe Mori 22-Sep-11 17:50pm    
Seriously, don't do this. Rewrite the code properly not using a CListBox.

The question is confused.

I think you are mixing up a lot of different concepts.

CDialog is a UI dialog that will display a UI CListBox.
The CListBox will be initialized with data.
People usually fill up the listbox in the OnInitDialog.

The data can come from a lot of different places. it can be done in the resource edit, it can be "hard-coded", it can come from a file or database, or it can come from whatever called the dialog class (by setting a data member and filling up the list in OnInitDialog).

The listbox is not a datastructure in the strict sense of the word, it (mostly) only contains a list of strings.

I suggest check what holds the actual data that will be use to fill the listbox.

That might give you a good start.

Other than that, I'm sorry I'm not certain I understand the question.
 
Share this answer
 
Comments
Member 7704531 22-Sep-11 8:57am    
hmmm. I reframe te question...
Earlier Scenario.

1. Listbox initialized in DoDataExchange using DDX_CONTROL.
2. Added the data using AddString.
3. Output in a Dailog.

Now(what i intend to do)
1. Remove the Dialog.
2. Make this class a normal class not inherited from any class(earlier CDialog).
3. Use the existing code which has listbox.

Problem: when i use this list box as there is no DoDataExchange this list box is not initialized and thus no memory to it. So as soon as i use any member function on this list box it gives error.

Question : How can i initialize listbox without using DoDataExchange so that i need not change the existing functionality
Maximilien 22-Sep-11 11:52am    
The CListBox cannot live by itself, it must be included and created in either a dialog or another window.

The CListBox cannot be used in a "normal" non UI class (non deriving from at least CCommandTarget, i think).

You will need to split the UI from the actual data.

Review what you want to do ... because it does not make sens.
Do you mean: "I want to put my own data in listbox items"?
You can do that via ListBox_SetItemData[^], ListBox_GetItemData[^].
 
Share this answer
 
Comments
Member 7704531 22-Sep-11 8:25am    
No, this class earlier used to output the data in a dialog now i want to save the data in other format(not dialog based). So i want to remove the dialog and use the same data structure. Currently controls are initialized in DoDataExchange but now i don't want to use it and use the same list box as my data structure.
Jusr create a CListBox object in your program and use its methods[^] to initialise and manipulate entries.
 
Share this answer
 
Comments
Member 7704531 22-Sep-11 9:17am    
I have created objects in .h file but as soon as i perform any operation on it, i get an error as the objects shows null memory. I am using VC6
Richard MacCutchan 22-Sep-11 10:06am    
What do you mean "I have created objects in .h file"? This is not how to create objects in C++. You need to create the objects in your code.

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