dlg.DoModal() is making the dialog box modal to the application and not to the previous dialogue box - visual-c++

if (IDOK == dlg.DoModal())
{
csFile = dlg.GetPathName();
return (LPCTSTR)csFile;
}
return NULL;
I have a desktop application and in this I have a dialog box. When I click on open button in this dialog box another open dialog box should pop up. Once this open dialogue box is displayed I am able to again go to the previous dialogue box and click on open. So second instance of open dialog box is displayed. I can do this many times. The open dialog box is modal to the whole application and not to the previous dialog box. Can anyone help me with this? As per design once open dialog box is displayed nothing else should be active till this is closed.

The standard wizard-generated constructor for the dialog box contains an optional constructor-parameter where you can specify the parent window:
class CMyOpenDialog : public CDialog
{
// Construction
public:
CMyOpenDialog(CWnd* pParent = NULL); // standard constructor
...
When you invoke this second dialog from your dialog, supply the parent, like
CMyOpenDialogdlg(this);

Related

C++ Windows form application Switching between forms

So i have my main form and i open a second form using this code
this->Hide();
Form2^ dlg=gcnew Form2();
dlg->ShowDialog();
how do i go back from the second form to the main one?
In the dialog code set the DialogResult property, this will close the dialog and return to the main form, ShowDialog will return the DialogResult value you set.
Alternatively you can have a button on the dialog that has a DialogResult property set and then clicking the button will close the dialog and return the value associated with the button.

How to prevent a dialog from closing when hitting enter or escape?

I have a dialog that I would like to stay open except if the [x] or exit buttons are clicked. Dialogs seem to always close if you hit escape or if you hit enter when most objects are selected (e.g. string boxes), whether you use pose() or display(). Is there a way to prevent this?
Some public examples of when this occurs are DM Mitchell's "Example: Thread and Dialog Interaction" and "Example: Single Button Dialog" but it seems to apply to any dialog.
The exception seems to be a docked palette, but this functionality seems to be rather limited in GMS2.3/GMS3.
Example code to test:
class myUItest:UIframe
{
object Init( object self )
{
TagGroup dlgTGitems
TagGroup dlgTG = DLGCreateDialog("Modal",dlgTGitems)
TagGroup dlgField = DLGCreateIntegerField(12,20)
dlgTGitems.DLGAddElement(dlgField)
return self.super.init(dlgTG)
}
}
{
object DLG = ALLOC(myUItest).Init()
DLG.Pose()
DLG.display("Modeless")
}
There seems to be no way to prevent termination of modal dialogs (those presented via the Pose method of UIFrame) via the keystrokes you mention. However, would a modeless dialog work for your application? Such a dialog is created by invoking the Display method on your UIFrame object and it is not closed via esc or enter.

How to save state of dialog so that it not closed?

I design mfc dialog based application in which first i design main parent window containing multiple child windows with tab control,it works fine.After i add one dialog before parent dialog and call parent dialog from it.So call to new dialog insert Back button on parent dialog,it works well,but second time parent dialog failed to open and application close.So how to save state of parent dialog second time initialization.I used methodlogy for above scenario given below:
I call new dialog in OnInitDialog() of parent dialog as DoMOdal() method.
Back button code given below:
void CParent::OnBnClickedBack()
{
UpdateData(TRUE);
NewDlg dlg=new NewDlg();
OnOK();
dlg.DoModal();
}

Change Edit Box content when Button is clicked in mfc

I have an Edit Box and a Button on a dialog. How can I change the content in the edit box runtime as the button is clicked? I have to read a new record from a file and post it in the Edit Box as the Button is clicked and I am using mfc.
Once you have trapped the button press, in most cases the easiest way to change text in an Edit Control is:
SetDlgItemText(IDC_EDIT_ID, "Desired Text String")
Where IDC_EDIT_ID is the ID of the Edit Control (set in the properties window)
You can set the text of an Edit control (wrapped by the CEdit class in MFC) by calling the SetWindowText method, which it inherits from the CWnd base class.
So then all you need to do is respond to a click event on your button control. You do this by listening for the BN_CLICKED notification from the appropriate button control within your parent window's OnCommand method.
Something like:
BOOL CMyDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (HIWORD(wParam) == BN_CLICKED && LOWORD(lParam) == IDC_MYBUTTON)
{
m_Edit.SetWindowText(TEXT("My string"));
}
return CWnd::OnCommand(wParam, lParam);
}
Obtaining and reading a book on MFC would be very helpful. This is fairly basic stuff, but it's a lot to cover in a single answer if you don't already understand the fundamental concepts.
Using the Class Wizard would make this even easier... Invoke it with the Ctrl+W keys and follow the on-screen instructions. You'll end up with something like:
void CMyDialog::OnMyButton()
{
m_Edit.SetWindowText(TEXT("My string"));
}

ShowWindow()...mfc

I am calling one dialog box from another.....before calling 2nd dialog box i am hiding the 1st dialog box using ShowWindow(SW_HIDE) and after finishing the operation on 2nd dialog box i destroy it....now when the control comes back to the function i am using ShowWindow(SW_SHOW) to show the 1st dialog again but it remains hidden..can anybody help me how to show it again????
EX:
Funcn(){
ShowWindow(SW_HIDE);//hide the dialog box 1st
SecondDlg var;//Class variable of 2nd dialog box
var.DoModal();//call the 2nd dialog box
ShowWindow(SW_SHOW);//after executing this statement the dialog still remains hidden...how to show it??
}
Maybe you want to call ShowWindow(SW_RESTORE) instead of SW_SHOW?

Resources