Close a dialog on clicking CANCEL button ignoring EN_KILLFOCUS - visual-c++

I have a CEdit field in my dialog where I have implemented EN_KILLFOCUS, so when the user enters invalid data a warning message is displayed when the focus moves away from this field and the focus returns to the CEdit field so that the user can enter proper data. If the user enters invalid data and clicks on the CANCEL button, then also a warning message is displayed which is undesirable because the user is anyway trying to cancel his actions. I have tried implementing PostQuitMessage when the user clicks on CANCEL button, but this closes the entire application. I want only my dialog to close when the user clicks CANCEL button. Is there any way that I can close the dialog instantly after I click on CANCEL button. This is the code that I tried.
void CMARPropWnd::OnParentNotify(UINT message, LPARAM lParam)
{
CCDialog::OnParentNotify(message, lParam);
// TODO: Add your message handler code here
CPoint ptButtonDown(LOWORD(lParam),HIWORD(lParam));
if ((message == WM_LBUTTONDOWN) && (ChildWindowFromPoint(ptButtonDown) == GetDlgItem(eMARPropWndCancelBtnId)))
{
PostQuitMessage(0);
}
}

Try
OnCancel();
instead of PostQuitMessage(0);
Note that OnCancel() is a virtual method of CDialog, so this is the "most correct", and will do any special code that may override the default CDialog behavior.

Related

What's the difference between endDialog() and endConversion() in Bot-Framework (node.js)?

I am confused with endDialog() and endConversion() when using bot-framework.
What's the difference between them?
If I don't invoke them, just using send()? What constraint will be?
When inside a dialog, you can invoke some other dialog. For e.g.
bot.dialog("/", [
function(session, data, next()){
session.send("Hi");
if(session.message.text === "hello"){
// starts a new dialog
session.beginDialog("helloDialog");
next();
} else {
next();
}
}, function(sesion, data){
session.send("end of root dialog");
}
]);
bot.dialog("helloDialog",[
function(session){
session.send("inside the hello dialog");
session.endDialog(); // explicitly ends the dialog
}
])
When user input is hello, output is
Hi
inside the hello dialog
end of root dialog
When user input is anything else, output is
Hi
end of root dialog
session.endDialog ends the current dialog, and resumes the parent dialog.
session.endConversation ends the conversation itself.
In Technical terms, when a dialog is called, the dialog moves into a stack called dialogStack. When another dialog is called from current dialog, that new dialog is placed at the top of dialogStack. When this new dialog completes its operation, this dialog is popped from the stack, and the last dialog resumes.
When session.endConversation is invoked, the dialog stack is emptied right away (this is a behavior am not fully sure though)

I have 5 forms and I want to know how to return to the main form after closing 5th form

I have two questions:
1- I have a project that contains 5 forms, So I want to know how to return to the first form when closing the 5th form.
2- I have two buttons, one is visible on the form and the second one is not. What I wanted to do is to display the second button when the first button is clicked.
I added this code on the Form_load event: btn2.Visible= false, and I added this code under btn1_Click: btn2_Visible=true, but it didn't work. Can anyone help me please?
Form4 newform = new Form4(TextBox1.Text,TextBox2.Text);
newform.Show(); // this code is in form1.
this.Hide();
Then I created a button in Form4 to create Form 5 using the same code:
RForm Form5 = new RForm(Label1.Text, Label2.Text);
this.Hide(); // this is in Form 4
Form5.Show();
To return to Form1, I created a button in form5 :
private void c_Button_Click(object sender, EventArgs e)
{
this.Close();
Set the Parent property of your forms. For instance, to open Form4,
Form4 form4 = new Form4();
form4.Parent = this; // Reference to current Form1 instance
this.Hide();
form4.Show();
In the event handler in Form4, check for the parent property and show that.
(form4.Parent as Form1).Show();
this.Close();
You would also want to handle the Closing event if user closes the form any other way than your button.
For the second part, as long as event handlers are wired up properly, this should work. In the event handler, btn2.Visible = true would work.

Get dialog window handler

I have MFC dialog based window application. Main dialog form creation is shown in code below. I have some code that runs on separate thread and sometimes I need to send message to dialog window. For this I need window handler.
Line MyAppDlg.GetSafeHwnd() returns 0. Why ? How to get dialog window handler?
BOOL CMyApp::InitInstance()
{
CWinApp::InitInstance();
// Activate "Windows Native" visual manager for enabling themes in MFC controls
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
startAll(NULL);
CMyAppDlg MyAppDlg;
m_pMainWnd = &MyAppDlg;
m_pActiveWnd = &MyAppDlg;
AuthMsgHWND = MyAppDlg.GetSafeHwnd();
INT_PTR nResponse = MyAppDlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
The dialog object has been created but the dialog window (and its HWND) are not created until after DoModal is called. The first place you can get access to this HWND is in the dialog's OnInitDialog function.
You've tried to get the HWND of the object before the dialog has been created with DoModal - that won't work. And since DoModal won't return until the dialog has been destroyed, you can't do it after. You'll have to find another point where you can capture that handle.
P.S. Don't call SendMessage from another thread. You're asking for trouble. Use PostMessage instead.

Confirm dialog window when closing a tab

I'm new to JavaFX. I want to create Listener which calls question dialog when user closes a tab into the TabPane. So far I managed to create tabs dynamically and add some custom configuration.
tabAvLabel = new Label(ss);
tabPane.getTabs().add(0, tab); // Place the new tab always first
tabPane.getSelectionModel().select(tab); // Always show the new tab
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs
I don't know what event listener I need to use and how to define it. Would you show me how to implement this?
You can try onCloseRequest for Tab class
tab.setOnCloseRequest(new EventHandler<Event>()
{
#Override
public void handle(Event arg0)
{
//your code
}
});
Try this code :
tabAvLabel = new Label(ss);
tabPane.getTabs().add(0, tab); // Place the new tab always first
tabPane.getSelectionModel().select(tab); // Always show the new tab
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs
tabPane.getOnClosed(), setOnClosed(new EventHandler<Event>(){
#Override void handle(Event e){
// What you have to do here
}
})
For more information, see http://docs.oracle.com/javafx/2/api/javafx/scene/control/Tab.html#onClosedProperty
I've hacked a similar support you have in jdk8 support into 2.2 (https://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.e4.controls.fx2/src/org/eclipse/fx/e4/controls/fx2)
The answer of #VagrantAI can work. But you have to add the following codes on your 'OK' button click action function:
stage.fireEvent(
new WindowEvent(
stage,
WindowEvent.WINDOW_CLOSE_REQUEST
)
);
While the problem of this approach is the event is triggered when you click 'X' to close the window too. This should not be the purpose normally.
To solve this, add a flag (or static variable) in the class that loads the window. So every time the window is loaded, set the flag to false. When the window is closed, set the flag only when the 'OK' button is clicked. Then you can do your action regarding the value of this flag.

How to "chain" modal dialogs in YUI 2?

I have a modal dialog box presented in Yahoo UI. The user selects a value from dialog "A", and then I want to present another modal dialog box to collect some more data in dialog "B".
I have been using the YAHOO.widget.Dialog successfully. The problem seems to be that you can't initiate dialog window "B" from the handler function of dialog "A". So, how can you programmatically launch a second dialog window after the user hits the "OK" button on the first ?
(I had tried to create an additional Listener for a field that is updated in dialog "A" to trigger dialog "B" but this doesn't work either.)
Thanks..
Check out the documentation: http://developer.yahoo.com/yui/container/dialog/#events. The following code should do the trick:
var firstDialog = new YAHOO.widget.Dialog('firstDialog', { postmethod: "manual" });
firstDialog.manualSubmitEvent.subscribe(function (type, args) {
var nextDialog = new YAHOO.widget.Dialog('nextDialog', { });
/* more configuration stuff... */
nextDialog.render();
nextDialog.show();
});
firstDialog.render();
firstDialog.show();
This handles when the form is to be submitted, which I think what you mean by selects a value, but if not let me know and I can give some help on that situation.

Resources