• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

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 :(
0
Zdravko_Monov
Asked:
Zdravko_Monov
  • 4
1 Solution
 
AlexFMCommented:
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.
0
 
AlexFMCommented:
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.
0
 
Zdravko_MonovAuthor Commented:
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?
0
 
AlexFMCommented:
If you write using API, there is no other choice. API Windows programming is done using global functions, which have access only to parameters passed to them, local and global variables.
In my non-MFC Windows programs I prefer to keep one global structure which keeps all data. At least, this allows to keep only one global variable. This is not pointer, so it cannot be deleted.
If you want to keep program 100% object-oriented, consider using WTL.
There are still some programming areas where C++ is not working for 100%. Non-MFC Windows applications, services, drivers. The reason is that programming interface exposed for developer is C-style. I don't see big problem here.
0
 
AlexFMCommented:
I think my answer is OK.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now