This is a very simple problem, but I could not find a solution to it. I have a dialog A, which when clicked a button opens another dialog B with a single edit box. I want to add an integer variable to it.
The usual way of adding variables which is right clicking the edit box and "add variable" is greyed out. I presume that it's because I haven't declared a separate class for the dialog, since the variable is used only in Dialog A code I don't want to add a separate class for Dialog B.
What should I do?
Thanks.
If you want to customise the behaviour of dialog B in any way (including adding variables for controls), you must declare a class for it.
You say that the variable is only used in dialog A code, but that doesn't mean that dialog A is the owner of that variable. Dialog B owns it, so dialog B needs a class.
Related
I have an dialog with several buttons and sliders on it and am adding another button that should close the dialog and open another that is essentially a mini version it.
I need access to the buttons in the first dialog in the second mini dialog (since they should have the same functionality).
Is there a way to use the class from the first dialog on the second so that I have access to those buttons? I've tried right clicking the dialog and adding a class, but it makes me make a new one instead of being able to use an existing one.
Thanks in advance!
I have my Main Dialog and some minor dialogs opened by buttons in Main.
I got object X of class ABC declared as a member of Main Dialog.
I want to edit (get and set values) object X from any dialog.
How can I do it? I read that it impossible to declare variable globally (tryed it in MyApp.h, or in MyApp class but there was linker error with redefinition)
The only solution that came to my main is to add to buttons:
CNewDialog newdialog;
newdialog.A=A;
newdialog.DoModal();
A=newdialog.A;
Will it work? Or is there any other solution?
On the other hand, there will be visible changes in Main Dialog only after closing newdialog and I don't want this.
I would use Common Configuration Facility designed using Singleton pattern to solve your task.
The main dialog object can be accessed from anywhere by calling AfxGetMainWnd. Cast the returned pointer into a pointer to your main dialog class.
I want to build a MFC application, with one main dialog, and all the other dialogs are child of this main dialog (and embedded in it).
Now, i was able to embed the first child in the main dialog, but i want to pass to the next dialog (note that the order of opened dialogs is random), so i need to hide the first dialog and show another. To know which dialog is shown at the moment and hide it, i've tried using a CDialog variable to store the current opened dialog, but i get a CObject::operator =' : cannot access private member declared in class 'CObject' error.
Is there another way to do this "hide and show dialogs" game?
EDIT: Could i store some ID of the dialogs and use it to acomplish this task?
So i managed to accomplish this task using classes IDDs.
First, i store the last opened dialog's IDD
m_dlgStartPage.Create(CStartPageDlg::IDD, this);
m_openedWin.nDialogIDD = m_dlgStartPage.IDD;
m_dlgStartPage.ShowWindow(SW_SHOW);
Then, when a new dialog needs to be shown, i send a message to my main dialog (nIDD is the IDD of pending dialog to show):
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND_CHANGE_WINDOW, nIDD, 0);
And last, in my main dialog, i parse all the child dialogs and check if m_openedWin.nDialogIDD matches with each dialog's IDD, so i can hide it. After this, i parse once again all the chid dialogs and use the nIDD from the sent message to show the correct one.
I don't really like this approach, because of all the parsing and sent messages to the main dialog's class, so if anyone has a better idea or method, please post it.
I need to create dialog and button.When I click on button with arrow dialog hide, it should looks like dialog moves to top and in ahother case shows for user.
ShowWindow(SW_HIDE). I know about it. I guess to get CRect from window, change it and after that set it to ScreeToClient().
Probably somebody knows some examples with it or another ways?
thanks
To hide or show a window, you use ShowWindow() as you indicated. No rectangle needed.
Otherwise, please re-explain your question, I can't make head or tails of it.
Normally, if you need to show a dialog that contains settings (similar to the Visual Studio "Options" dialog) then what you would typically do is this:
List item.
Create a CDialog-derived class.
Create an instance of that class.
call DoModal on that object. This shows the dialog.
Do nothing else. Once DoModal returns the dialog has been closed.
I'm fairly new to VC++ and MFC, so bear with me. I have created a new dialog, and I want to figure out how to display it when the user clicks a button.
I have not create a class or header file for the dialog -- I tried using the class wizard, but it pretty much sucked and didn't work. That, or I was doing something wrong. Either one is equally as likely if you ask me.
So what steps do I need to take when creating the source/header files and getting the dialog to launch/display? It is a modal dialog.
CLARIFICATION: I understand that I need to create an instance of the dialog class, then just call DoModal() on it, but I'm not sure how to create the class file (with and/or without the wizard).
Right click the project and select
Add | Resource...
Select Dialog under Resource
type and click New.
Select Project | Add Class...
Enter CMyDialog for the Class
name, CDialog for the Base class
and Click Finish.
Read more: How to Make MFC Dialog Boxes
Seems to me you can make the button click just create a new instance of the dialog object and activate it. You'll probably have to keep a reference to the dialog so it doesn't get killed when the button action fxn returns it doesn't get garbage collected..