Blocking action of CDialog's maximize/minimize button - visual-c++

I am using mfc CDialog. I need to show the close and minimize/maximize button, but they should not close or maximize the dialog. I have overriden OnClose method and kept the dialog open even if close button is clicked. But I am unable to block maximize and minimize of the dialog as there doesn't seem to be a OnMaximize method. Is there an alternative way?

You need to handle the WM_SYSCOMMAND message, watching for wParam == SC_MAXIMIZE.
If you catch the SC_MINIMIZE, you can do what you want and not pass it on to Windows.
msdn
Found this snippet here.
const int WM_SYSCOMMAND= 0x0112;
const int SC_MAXIMIZE= 0xF030;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if((int)m.WParam==SC_MAXIMIZE)
{
MessageBox.Show("Maximized!!");
return; // swallow the message
}
}
base.WndProc (ref m);
}

You can not show at all the minimise/maximise icons i your dialog. You can do that by going to Dialog properties (right vlick on your Dialog Contorol --> Properties), Select Styles pain and unselect 'Minimise Box', 'Maximise Box'.

Related

Codename One set action event from different class for button in dialog

I have an Android application with a dialog and a few buttons inside.
I want to reuse the dialog for different purposes and looking for a way to call the button from a separate class and define an action event for it.
Creating a test class, I managed to define an action event for a button inside a form, but the same code does not work for a button inside a dialog, and I can't get my head around why it is not working for the dialog.
Below is what I already have. Any suggestions would be appreciated.
public Class One {
Test test = new Test();
test.testOne(); // this is working : button prints
test.testTwo(); // this is not working : button does not print
buttonTest = test.getTestButton();
buttonTest.setText("Hello World"); // not working for a button in a dialog
buttonTest.addActionListener(l-> { // prints when the button in a Form
System.out.println("try"); // does not print when the button is in a dialog
});
}
public class Test {
Dialog dialog = new Dialog();
Form form = new Form();
Button button;
public void testOne() {
button = new Button("Test");
form.add(button);
form.show();
}
public void testTwo() {
button = new Button("Testing");
dialog.add(button);
dialog.show();
}
public Button getTestButton () {
return button;
}
}
You add the action listener after showing the form and dialog. This isn't a problem for the form since the forms show method will continue. But a dialogs show() method will block.
Two solutions:
Move the listener binding higher in the code (before the show) that would be a problem since the button doesn't exist yet so you will need some refactoring.
Change the show() call on the dialog to showModless()

Disable Dialog closing after ENTER button pressed in ControlsFX

I have extended org.controlsfx.dialog.Dialog and added some TextField to it, which is supposed to act when ENTER button is pressed (if TextField has focus). However when I press ENTER, my dialog takes over of steering, and act like on OK button was pressed.
Is there any method which I can override in order to change this behavior (to intercept Enter action)?
Thanks in advance
I have received some workaround to this problem at ControlsFX mailing list which is good for me. To disable Dialog closing after Enter button is pressed in TextField we must consume event in EventHandler attached to this TextField
textField.addEventFilter(new EventHandler() {
public void handle(KeyEvent evt) {
.......
evt.consume();
}
});
For me works this:
dialog.getDialogPane().addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.ENTER) {
event.consume();
}
});

Focus on Modal Dialog (MFC)

I create modal dialog like this :
CDialog dlg;
dlg.DoModal();
but when window opens I can access background windows of my program (move them and close them) but I need focus only on my curent window. (I think modal dialog shouldn't behave like this)
How can I do this?
EDIT:
It seems I found the reason of this behavior: before open my dialog,I open another modal dialog in CMyDlg::OnInitDialog() function, when I comment this,my dialog again became modal. But how to solve this problem?
Some code describing problem:
void CMyView::OnSomeButtonPress()
{
CMyDlg dlg;
dlg.DoModal();
}
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//some init here...
//new modal dialog here (if comment this CMyDlg works as modal)
CSettingsDlg dlg;
dlg.DoModal();
//...
}
you can solve your problem by specifying parent window for the dialog, you can do by passing this pointer in constructor of each dialog class as shown in code .
void CMyView::OnSomeButtonPress()
{
CMyDlg dlg(this);
dlg.DoModal();
}
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//some init here...
CSettingsDlg dlg(this);
dlg.DoModal();
//...
}
You cannot use a dialog from within the OnInitDialog method or from any function called from the OnInitDialog method. You have to use the DoModal() of CSettingsDlg from else where.
Something like this:
void CMyView::OnSomeButtonPress()
{
//new modal dialog here (if comment this CMyDlg works as modal)
CSettingsDlg dlgSettings;
dlgSettings.DoModal();
...
CMyDlg dlg;
dlg.DoModal();
}
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//some init here...
//...
}

Using MonoDroid, how can I open a dialog when an EditText field gains focus?

I made the EditText clickable but you have to "double-click" to bring the dialog box up, which isn't really desired behaviour. How can I bring the dialog box up when the EditText is clicked / gains focus?
Bonus points for including a way to stop the keyboard popping up :)
_createProfileDobEdtTxt.Clickable = true;
_createProfileDobEdtTxt.Click += (sender, e) =>
{
ShowDialog(DATE_OF_BIRTH_DIALOG);
};
I found it - use the .Touch event handler:
_createProfileDobEdtTxt.Touch += (sender, e) =>
{
ShowDialog(DATE_OF_BIRTH_DIALOG);
};

How can identify Mouse Click event in PreTranslateMessage?

I want identify all mouse click event in PreTranslateMessage, but when I use WM_LBUTTONDOWN than WM_LBUTTONDBLCLK portion never called. Please tell me how can I identify all events separately.
This code will get the mouse click events in PreTranslateMessage
BOOL CSampleDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_LBUTTONDOWN)
{
//add ur customized code here...
return false;
}
return CDHtmlDialog::preTranslateMessage(pMsg);
}

Resources