I have a dialog that contains some radio buttons and a list box I wondered how can I pass a message to another object that the user chaghed his selection by press one of the redio buttons, I need to call to a method of the second object accordeing the user selction .
It depends how the objects are subclassed (or derived) and who their parent is. Just about all buttons in MFC are CWnd derived, but their event handlers are usually managed by the parent window (usually some CDialog or some sort of form).
If the second object that you're referring to is another button type of object, that is owned by the same parent window, then it's ok to make direct calls to access the other object. On the other hand, if that other object is in a separate dialog or form, then you should pass a message using SendMessage or PostMessage to the parent window and let it handle the event.
It's going to make quite a big difference as to what these "objects" you are talking about are and who the owner is. A number of different solutions will probably work, but you should be careful and follow framework guidelines as you may end up with an unstable solution.
Its a simple process with a number of small steps.
1. Wire-up the message handling of the radio buttons so that you get a WM_NOTIFY (or whatever the pertinent message is) whenever the active radio-button in the group changes.
2. Call method of object 2 with the selected option passed in as a variable somehow - either as text, or (preferably) as an INT that represents the choice number.
Here's a dialog-based app that demonstrates the principle. Whether you call the method of the second object when the selection changes or when an 'action' button is pressed, is up to you.
(And yes, I do realize that as they're radio-buttons, one of the options should be checked by default - just can't remember how just this minute - it was easier and quicker to add a test case to check if an option had been selected yet or not )
That's okay. In fact - I didn't make any call to the method of object 2. Please accept my apology for being unclear.
As I alluded to earlier, I can see two places where such a call would make sense.
In the first case, there would be action immediately after a radio button was pressed.
I imagine you would not have the same need to keep track of the currently selected option, so I've omitted that code from the following case statements.
Example 1: Immediate response
In this second example, you'll need to remember which radio-button is selected somewhere, before taking the appropriate action when the trigger is received (in this case, the pressing of the button labelled Test) Example 2: Action taken in response to another input
if (curRadioOption == -1)
MessageBox(hwndDlg, "Select a radio button first!", "Error", MB_ICONERROR);
Something else I should mention, is that MFC will most likely allow the state of any control to be quickly and easily queried (not sure if there's an object used to represent a group of radio buttons - I'd imagine that there was) This will make my global variable curRadioOption redundant.
...if i go from one dialog to another , how can i close it and save its contents
The dialog is closed by clicking the Cancel button, the X, Esc, Alt+F4, or by calling EndDialog(). Where are you wanting to save its data to? Some internal data structure, or some external storage like a file?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
I did not put any cancel or close,it is without title bar.I make sdi application with
full screen and in menu of upper level i put the chose where you can open the new
dialog.I am calling dialog boxes from the Viewclass.but didnot find how to close or switch to other dialog when user click the other options of open other dialogs
Do yo have any coding to calling mulitple dialogboxes in SDI applicaiton
is there any c++ tutorial or (simple) open source sample how to write an OLE object that can be embedded into MS Office applications such as powerpoint?
Just like, for example, an Origin Graph or a corel draw image which are directly embedded into a powerpoint presentation.
When I search for OLE, I most often only find how to automate Office...
Not sure how this would work with a C++ DLL loaded into a C# application, but read what MSDN[^] says here, maybe it can get you going.
Registering/Using somekind of inbetween COM interface sounds like a good idea.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
Last Visit: 31-Dec-99 19:00 Last Update: 27-Feb-24 13:23