Link to home
Start Free TrialLog in
Avatar of Zdravko_Monov
Zdravko_Monov

asked on

How do I send input data from a dialog box to an object?

Hi there!
I am completely new to this place and I am still confused where to post a question and further more - whether this is the exact place for my problem. Please, forgive me if I am wrong.
I am working on a project under .NET's Visual C++ Win32 Application. I am not using Managed Extensions for C++. The program consists of a main window and a dialog, called when the user clicks on a menu from the main window. The dialog appears and then the user inputs data in some edit boxes. How do I elicit the input information from the dialog and send it to a container, that is developed by me. I have created a class, that encapsulates a list of some objects. My aim is creating a pointer to this class(by creating the object dynamically) as a local variable in a function and then using the pointer as a control in order to push data into the list. Well, the problem is that by calling the DialogBoxProcedure, this pointer is no more visible. By clicking, for example, the OK button, the input data must be read and then pushed into the list. Does anybody know how to deal with this problem. Declarating the pointer as a global variable sounds terrible for me :(
Avatar of AlexFM
AlexFM

Use DialogBoxParam Function instead of DialogBox. This allows to get pointer to this class in WM_INITDIALOG handler. You still need to keep this pointer for using in other message handlers. You can do this using global variable, static DialogBoxProcedure member, class member etc. - according to your program structure.
BTW, when you write Windows application using API, there is no other way except using of global variables. Object-oriented wrappers like MFC or WTL allows to use only class members, but in pure API program data is kept in global variables.
Avatar of Zdravko_Monov

ASKER

Ok, I see. So, having a global variable in the program does not make things so wrong? I mean, the data is encapsulated in the class quite hard. Unfortunately the global variable is a pointer to the class. This means that by typing "delete GlobalPointer;" my data will be lost. Further more the GlobalPointer is visible from every part of my program. Thus, using the pointer, every module will have access to the data and may modify it in any way. Is there a way to make some methods private and then to give permission to some functions to use them? Can I set the destructor to be a private method, and then in some way declaring that some part of the program can use it?
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think my answer is OK.