|
Hello,
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 .
thanks
|
|
|
|
|
What is the second object?
"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
|
|
|
|
|
Object of a non dialog class
|
|
|
|
|
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 )
resource.rc
// Generated by ResEdit 1.5.8
// Copyright (C) 2006-2011
// http://www.resedit.net
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOGEX 6, 5, 194, 106
STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_THICKFRAME | WS_SYSMENU
CAPTION "Code::Blocks Template Dialog App"
FONT 8, "Tahoma", 0, 0, 1
{
PUSHBUTTON "&Test", IDC_BTN_TEST, 138, 5, 46, 15
PUSHBUTTON "&Quit", IDC_BTN_QUIT, 138, 29, 46, 15
GROUPBOX "Static", IDC_STATIC, 13, 16, 114, 68
AUTORADIOBUTTON "Radio Button 1", IDC_RADIO1, 38, 32, 63, 8
AUTORADIOBUTTON "Radio Button 2", IDC_RADIO2, 38, 45, 63, 8
AUTORADIOBUTTON "Radio Button 3", IDC_RADIO3, 38, 59, 63, 8
}
resource.h
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define DLG_MAIN 101
#define IDC_BTN_TEST 1000
#define IDC_BTN_QUIT 1001
#define IDC_RADIO1 1002
#define IDC_RADIO2 1003
#define IDC_RADIO3 1004
main.cpp
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include "resource.h"
HINSTANCE hInst;
int curRadioOption = -1;
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char msgBuffer[1024];
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_BTN_TEST:
if (curRadioOption != -1)
sprintf(msgBuffer, "You clicked the \"test\" button\nCurrent radio selection: #%d", curRadioOption);
else
sprintf(msgBuffer, "No radio-button option selected...\nPlease select an option then try again");
MessageBox(hwndDlg, msgBuffer, "Information", MB_ICONINFORMATION);
return TRUE;
case IDC_RADIO1:
curRadioOption = 1;
return true;
case IDC_RADIO2:
curRadioOption = 2;
return true;
case IDC_RADIO3:
curRadioOption = 3;
return true;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
|
|
|
|
|
Thanks for your replay , I didnt understand where is the calling to the method of object 2,
if you can mark this section it will be helpfull for me.
by the way I forgot to specify that I am using MFC but as I realized it doesnt matter.
thanks
|
|
|
|
|
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
case IDC_RADIO1:
object2.handleSelectedRadioButton(1);
return true;
case IDC_RADIO2:
object2.handleSelectedRadioButton(2);
return true;
case IDC_RADIO3:
object2.handleSelectedRadioButton(3);
return true;
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
case IDC_BTN_TEST:
if (curRadioOption == -1)
MessageBox(hwndDlg, "Select a radio button first!", "Error", MB_ICONERROR);
else
object2.handleSelectedRadioButton(curRadioOption);
return TRUE;
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.
|
|
|
|
|
Pass a pointer to the object you want to notify in the constructor of the dialog, and have the dialog save that in a member variable.
Then when events occur, make a call to that object.
|
|
|
|
|
Hello
Thanks in advance.I have created different dialog for which are link by the main menu,but my problem is if i go from one dialog to another , how can i close it and save its contents
Waiting for reply soon
|
|
|
|
|
johnjitu wrote: ...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
|
|
|
|
|
Thanks
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
Thanks
|
|
|
|
|
johnjitu wrote: Do yo have any coding to calling mulitple dialogboxes in SDI applicaiton
You need to first understand the difference between modal and modeless dialogs.
"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
|
|
|
|
|
hi
i looking to load the image in an window how can i do it i tried with CpictureHolder .does any alternative way to do it.
note am not looking to load on background
Reply as soon as possible .
thanks sarfaraz
|
|
|
|
|
Perhaps CImage[^] is what you need.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hello,
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...
Alex
|
|
|
|
|
|
Thank you - this was easier than I expected.
Alex
|
|
|
|
|
I can insert my ActiveX object into Powerpoint and save/restore the data.
Now, I would like to automatically create a new object from a certain file type - ideally by drag and drop into Powerpoint. How can I achieve this?
Thank you in advance.
Alex
|
|
|
|
|
I never did that, however, I suppose you have to write a Shell Extension for that, check out the great article series[^] of Michael Dunn, here at CodeProject .
Veni, vidi, vici.
|
|
|
|
|
|
|
Please don't post the same question at multiple places.
The identical question in the Q&A section [^] already contains answers.
|
|
|
|
|
Alright, Fine, I got that. Now any answers?
|
|
|
|
|
Hi All,
I have a function in C++ dll like
FunctionCPP(int s)
{
}
I have a function in C# application(exe) like
int FunctionCSharp(int s)
{
return s;
}
what is the procedure to call FunctionCSharp from FunctionCPP?
Any help will be appriciated.
Thanks
G.Paulraj
|
|
|
|
|
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.<
|
|
|
|
|