If I have a selection in an edit control and I open a standard dialogue to find or replace, my selection becomes hidden, but when I close the modeless dialog, I can see my selection again.
hwndF = FindText(&fr); // open standart find modeless dialog
Breakdown of the problem:
I select text in edit control.
I open find modeless dialog and cannot see the selection.
I close the find modeless dialog and I can see my selection.
After I open the modeless dialog I still want to see my selection.
To make sure the selected text is not hidden when the control loses focus, create the edit control with ES_NOHIDESEL style, for example ES_NOHIDESEL | WS_VISIBLE | WS_CHILD. If using resource dialog, set "No hide selection = true".
See also:Edit Control Styles
ES_NOHIDESEL Negates the default behavior for an edit control.
The default behavior hides the selection when the control loses the
input focus and inverts the selection when the control receives the
input focus. If you specify ES_NOHIDESEL, the selected text is
inverted, even if the control does not have the focus.
Related
I'm working on an Qt app. I should create a pop-up window that has only a close button with no toolbar, minimize and maximize buttons.
Any idea how to do this?
I don't know by "no toolbar" you mean "no title bar" or not, but this example can help you. Anyway, by using the following code you can have a window with just close button, and "title bar":
window->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
If you don't want the title bar too, try to remove it and design it by yourself.
you could change the window-flags. But your expected window calls for a QDialog: has no menu-bar and just a close-button (out of the box).
Else refer to this ( https://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html ) and set the flag for Qt::WindowCloseButtonHint.
If you use setWindowFlags(Qt::Window | Qt::FramelessWindowHint); you will get rid of the title bar, but with it all buttons that live on the titlebar, including the close button.
This will mean you will need to implement a way to move the window, as the title bar is used for this purpose. See this answer
Then implement your own titlebar class with a close button that you can put at the top of your dialog.
Unfortunately you don't have any control over the system titlebar appearance, so it's not possible to stylesheet your way out of this problem.
I have a dialog that is derived from our specific base class that is inturn derived from CDialog class
This dialog contains a combobox with combobox items in it (string)
There is a group box, labels, checkbox and a text box as well (I will call them grouped controls for this discussion)
If I select an item in index 0 from combo box, the Grouped controls are shown and if I select an item in index 1 from combo box, the group controls should be hidden
I have used the code to show or hide the controls as
void MyDerivedClass::HideMyControls(bool hide)
{
int param = (false == hide)? SW_SHOW : SW_HIDE;
GetDlgItem(IDC_ENABLE_TP_DIRECTORY)->ShowWindow(param);//This is Checkbox control
GetDlgItem(IDC_STATIC_NOTE)->ShowWindow(param);//This is label control
GetDlgItem(IDC_STATIC_DIR_NAME)->ShowWindow(param);//This is label control
GetDlgItem(IDC_EDIT_TP_DIRECTORY)->ShowWindow(param);//This is text control
GetDlgItem(IDC_STATIC_TP_GRPBOX)->ShowWindow(param);//This is label control
InvalidateRect(NULL); //NULL for testing
UpdateWindow();
}
The issue is the controls are still seen on the screen even after the above method is called with true parameter. If I move some other window on top of the (supposed to be) hidden controls, then it is actually disappears. So this seems to be a refresh issue. My assumption is that the InvalidateRect and UpdateWindow should have taken care of repainitng this. but is not happening.
Tried with InvalidateRect(NULL) to paint the whole screen, but still no use.
Could you please suggest how I can hide the controls? any clean way of doing this?
Note: when the controls are (supposed to be) hidden but are still seen on the screen, I will not be able to perform any action on those controls (like setting checkbox or typing in the text box).
So I believe that the controls are marked as hidden but not painted.
When using a MFC ribbon based application, by default we get options to add keyboard short cuts for all our commands. So for example, I might use 'p' to bring up the print preview dialog. When I'm in a dialog, these commands are not active as you would expect, even if that dialog is not modal. However, if I click into an edit control on the ribbon these commands remain active, so for the example given I could not type 'p' into my edit control. A work-around is to add a modifier such as Ctrl + P or Shift + P but this makes the shortcut more awkward for my users. Is it possible to change the message filter either for the ribbon as a whole, or for individual ribbon controls, such that they ignore keyboard shortcuts the same way a dialog does?
Edit Some feedback here from related thread on MSDN
The title isn't very explicit but here is my problem :
I have a MFC-based application with a dialog that has :
1 Text input;
1 Ok button;
1 cancel button;
1 button with an arrow to type in the next value
When the text box has the focus, pushing enter triggers the OK button. Why ? The text box has the focus, not the OK button so why would it do that ?
What i need ito to redirect the enter key to the arrow button instead of the ok button so that pushing enter doesn't close the dialog but goes to the next input.
Why can i do that please ? If i use SetFocus on the arrow button, the text box loses the focus, as expected, and this is not what i want.
You must set the Multiline and the Want Return properties of your edit control to True.
If an edit control does not have the style ES_WANTRETURN pressing ENTER has the same effect as pushing the dialog's default button. However, this style has no effect on single line controls, so you must also set the ES_MULTILINE style for the control.
I have a dialog box (CDialog) with owner-drawn CTabCtrl in it. Tabs content are child dialogs (one for each tab). There is an CEdit in each tab. When the user clicks a tab, I'm hiding all child dialogs using ShowWindow(SW_HIDE) and showing a selected one.
The problem is that when I have, for example, two tabs, click inside an edit box in the first tab and then switch to second, input focus stays on that (invisible) edit box in the first tab no matter what I do in my code (tried calling all methods that potentially can set focus, nothing changed).
Try this:
GetDlgItem(IDC_YOURCONTROL)->SetFocus();
Or the related variable linked with the control:
m_YOURCONTROLControl.SetFocus();