Using MFC in Visual Studio 2012
I want to use a CMFCColorButton in a dialog in my application.
I added the CMFCColorButton button to my dialog in the resource editor (test it, works OK); click on the button and the underlying CMFCColorPopupMenu is display and stay displayed until manually dismissed (choosing a color or clicking somewhere else).
When I build my application and try the button in the dialog, it works differently, when I click the button, the underlying CMFCColorPopupMenu is displayed and immediately dismissed. If I want to select a color, I need to keep the mouse button down.
I tried in a different application (default MFC application) and I get the desired behavior (click and the CMFCColorPopupMenu stay visible).
I am not certain what could trigger the behavior difference.
I try toggling the CMFCColorButton::m_bAutoSetFocus value of the button and there is no change of behavior. ( I am not certain what is the purpose of this variable, but that is another subject)
Any ideas? hints/tips?
Thanks,
Max.
Related
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
I am coding a test application for a windows CE device. This is the first time I am programming for a handheld device. I use MFC VC++ on Visual Studio 2008. I have found that there are many restrictions in the controls and what I could do with them when running the program on a handy versus when I run a similar program on a desktop computer.
Now, the device I am currently deploying my test program to, does not have a touchscreen and has few extra keys other that the numberpad 0-9 keys. So, I have to do with a simple GUI that uses keydowns to call specific functions like add, edit, delete etc... It also forces me to use separate dialogs for each of these functions so as to avoid unnecessary mouse cursor usage.
This leads me to my current problem: The 'ADD' dialog of my test app adds some user data to a CListCtrl that is on the 'MAIN' dialog. The 'EDIT/DELETE' dialog is to allow the user to select the desired data from its own CListCtrl and press the "ENTER" key, which thereby deletes the selected data from the 'MAIN' dialog's CListCtrl. Thus, both the main dialog and the 'EDIT/DELETE' dialog have CListCtrl with the exact same data. So, instead of having to use 2 separate list controls and using loops to copy the data to and fro among them, is there a way in which i could use the exact same CListCtrl (one and only one instance of the CListCtrl exists), but display it on 2 separate dialogs? This would remove all the copying code, as well as halve the amount of data in memory.
I tried passing a pointer to the MAIN dialog's CListCtrl to the 'EDIT/DELETE' dialog in hopes that I could redraw the control there, but in vain. I could call the RedrawWindow, RedrawItems commands, but they seem to have no effect in the 'EDIT/DELETE' dialog (I think it is because the control itself is not present on the edit/delete dialog). Any other suggestions?
You could temporarily change the parent of the ListCtrl using CWnd::SetParent to the EDIT/DELETE dialog, and set the position with CWnd::SetWindowPos to where you want to have it. When the dialog gets closed, set the parent back to the MAIN dialog.
I'm seeing non-standard behavior (as compared to tools like Word and Visual Studio 2013) in my C++ Windows Forms application. We use Application::Run and then ShowDialog to show various modal dialogs. When one of the modal dialogs is up and I place another application window partially in front of the modal dialog, I can click on part of the modal dialog and it brings it back into the foreground as I expect.
However, if I instead click on part of the main window (shown with Application::Run) the modal dialog isn't brought to the foreground. This makes it hard to bring my application back so I can work on it. Ideas?
A simple MFC app created in VS2013 works as it should too. You can witness this with the About box which is shown with DoModal. I would have expected ShowDialog and DoModal to be equivalents. A simple C++/CLI or C# winforms application acts fine.
And this only happens in out application when our main window is maximized.
It turns out that is caused by our use of the Syncfusion UI libraries. They will be fixing the bug.
I have a C++ MFC MDI application. I have a tool bar with some buttons on it. I need to add some check boxes to this toolbar and i need them to have custom bitmaps just as my buttons do. Thanks
EDIT:
By bitmpas i refer to the pixel images that can be created using the tool bar editor in visual stuidos 2008. I would like a picture (of my creation) instead of the usual tick box.
You don't use checkboxes on toolbars.
You should rather use regular buttons in Check mode. That means that the button stays pressed when user releases it. Clicking it a second time releases the button. This is the same behaviour as a checkbox.
You can either set a toolbar button as checkable by code:
m_ToolBar.SetButtonStyle(nButtonId, TBBS_CHECKBOX);
Or by enabling the corresponding property in the resource editor.
If you want to modify the image displayed when the button is pressed, in your ON_UPDATE_COMMAND_UI handler, use m_ToolBar.GetButtonInfo() to check if the image matches the state. If not, change it using m_ToolBar.SetButtonInfo() and specify the index of an extra image added to the image list of the toolbar.
The following is a link which might help you
http://www.ucancode.net/Visual_C_Control/Place-Combo-Edit-Box-Progress-Control-On-ToolBar-CToolBar-VC-Example.htm
I currently have some toolbar buttons with a small arrow on the side (TBSTYLE_EX_DRAWDDARROWS) that, when clicked, result in a popup context menu being displayed under the button. This is done by constructing a custom popup menu and calling TrackPopupMenu.
The client now wants to be able to select multiple options from the menu before it closes, so that multiple options can be be modified without the need to re-open the menu and wait for an intermediate redraw between each change.
For example:
User clicks dropdown button
Dropdown menu appears (modal, waits indefinitely for user action)
User clicks some item (e.g., toggle a checkmark)
Timer (e.g., 500ms) starts
If timer expires, the menu is closed and all selected actions are executed.
User clicks another item before the timer expires, go back to 4.
The best I can come up with is to redisplay the menu by calling TrackPopupMenu multiple times. This makes the menu "flicker" when you select an item, and will probably require me to start a thread in order to do the timeouts, which I would rather avoid.
Rather than a menu, put up a dialog box with the options on it. A dialog can easily do all that is required.
A menu that doesn't close when you click it will just seem wrong. A dialog that closes by itself will seem wrong too, but it's probably the least of two evils.
Edit: If there's anything I've learned with Microsoft, it's don't try to fight the default behavior. You're asking for trouble if you do.
If you're building your menu dynamically I can see how automatic sizing can be handy, but it's not hard to do in a dialog either - make the dialog really big and before it becomes visible, enumerate the children and take a union of all their rectangles, then resize to that. Checking the boundaries to make sure they're on-screen is just a few if statements with OffsetRect. Checkboxes are trivial; icons less so, but still not bad.
One additional enhancement that would be easy to add is to dismiss the dialog immediately on a double-click.
Following #Mark Ransom's answer, you should put up a dialog box. But you can make the dialog modeless and make it close itself when you click outside of it (i.e., the dialog loses focus). That way it could behave more like a menu.
Notice that normal menus never go away by themselves, you always have to click somewhere outside the menu (or one of its options) to make it disappear.