Add a menu resource to a dialog box - c++

I was wondering if it is possible to add a menu resource to a dialog box. It would be easier to "design" my applications layout in multiple dialog boxes rather than the standard window, however, I will need to be able to add a menu. I would preferably be able to do this through a resource defined menu, however, I have no objections to doing it programmatically.
Right now my application is just starting like this:
DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG_UPDATE),NULL,(DLGPROC)updateTitle);
in the main function.
Thanks for your help!
Dennis M.

Call SetMenu(hDlg, hMenu) during WM_INITDIALOG.

As Krishty commented on the accepted answer, it is easier and safer to just specify the menu ID in the designer. In the dialog resource properties, scroll down and there is a Menu option. Choose your already created menu from there. You won't see it in the designer, but when you run your app it will be there.

Related

How to add elements to the application menu in OSX?

Is it possible to change the Application Menu on OSX?
The default application menu looks like the following:
But most applications provide things like the about window in the application menu to not clutter the help menu:
How can this be done in Qt? A solution in QML would be great, but there isn't even a general solution in the project examples.
To force action into the application menu, set a menu role on it:
action->setMenuRole(QAction::ApplicationSpecificRole);

Embedding dialogs in main dialog and switching them with button click in MFC

I have a design like below:
So basically, I want to embed three dialogs in the application main dialog and switch between them, for each button click i.e., button 1 will show dialog one , button 2 will hide dialog 1 and show dialog 2 .. and so on.
Each dialog will be having a different design and functions.
I tried using CPropertySheet class to Add pages but its GUI is different. It has either option for navigating the dialogs using next / back button , or from a tab control.
None of which is as per my requirement.
So I want to know is it possible to have a design like this in MFC ? If yes how? Which Class/ control should I use.
Any help will be appreciated.
What you can do is use a normal CDialog class, add your buttons to it and also create a frame/rect as a placeholder for where your embedded dialogs are to appear. The following piece of code will create and position your embedded dialog.
CRect rect;
CWnd *pHost = GetDlgItem(ID_OF_YOUR_FRAME_RECT);
pHost->GetWindowRect(&rect);
ScreenToClient(&rect);
pDialog->Create(ID_OF_YOUR_DIALOG, this);
pDialog->MoveWindow(&rect);
pDialog->ShowWindow(SW_SHOW);
On button clicks, you hide the previously shown dialog (SW_HIDE) and show your selected dialog(SW_SHOW) with ShowWindow(...).
If you create your embedded dialogs with IDD_FORMVIEW style in the add resource editor it'll have the proper styles for embedding.
Another option is probably to use an embedded PropertySheet and hide the tab row and programatically change the tabs on the button clicks. I just find it to be too much fuzz with borders, positioning, validation and such for my liking.
If you have the MFC Feature Pack, that first came with VS2008 SP1 and is in all later versions, you might like to consider CMFCPropertySheet. There are a number of examples on the linked page, that are very similar to your design.
For example, this:
What worked for me just using dialog based application is SetParent() method. Dont know why nobody mentioned it. It seems to work fine.
I am doing like below:
VERIFY(pDlg1.Create(PanelDlg::IDD, this));
VERIFY(pDlg2.Create(PanelDlg2::IDD, this));
VERIFY(pDlg3.Create(PanelDlg2::IDD, this));
::SetParent(pDlg1.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg2.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg3.GetSafeHwnd(), this->m_hWnd);
Now I can show or hide a child dialog at will (button clicks) as below:
pDlg1.ShowWindow(SW_SHOW);
pDlg2.ShowWindow(SW_HIDE);
pDlg3.ShowWindow(SW_HIDE);

MFC VSListBox change icons

Does anyone know if it is possible to change the icons on the MFC VSListBox Dialog Control?
Specifically I'm trying to change the folder icon to a '+' icon instead:
I haven't tried it myself, but CVSListBoxBase::AddButton() seems to be what you need.
CVSListBox derives from CVSListBoxBase, and when you call CVSListBoxBase::SetStandardButtons to set the buttons, it calls AddButton() for each button.
The documentation for CVSListBoxBase is unfinished, so you'll have to "play" with it, but you can read the code in afxvslistbox.cpp/.h

Embedding file open dialog

Office 2010 has a new type of ribbon, the backstage view. This has been implemented in MFC using Codejock Xtreme Toolkit Pro V15.0.1.
The thing is that I feel that the File>Open and File>SaveAs act very strange in Office. They open a modal file open dialog instead of opening an embedded file open dialog in the backstage, which would (IMHO) feel much more natural.
I cannot find a way of doing this in C++ using MFC or Win32. The only thing I found was this question, but that was for Delphi.
So, is it possible to embed the standard Windows File Open dialog as a control in another dialog? Or do I need to implement the entire thing myself?
To the best of my knowledge, The standard Open/Save dialog functionality is exposed through the modal dialog only (through the GetOpenFilename Win32 API).
There is a standard mechanisme to customise the dialog (See Skizz answer) but it remains a modal dialog. One case of advanced customisation was the VB6 Open Project dialog:
The Existing tab contains a file dialog. How did they do it? I mean, how did they manage to put a standard dialog into a page of their 3-tabs property sheet?
It appears that they simply used the standard customization dialog and added a tab control above the standard dir/file controls and listview for other 'tabs' above dir/file controls. These dir/file controls were then hidden by the custom code when a tab other than Existing was clicked. You get it: no real tabs! Just a good old file dialog where the main controls may be hidden in favor of other ones.
So my short answer is: You're pretty much out of luck using the dialog as a child control.
Now, to come back to Office: I believe it's better to keep a modal dialog. It would otherwise be confusing to user: Is the path that I started to type the real path of did I just clicked 'Home' and let the save command unfinished?
I don't know if you can embed a file open dialog into another dialog, but you can certainly extend the existing dialogs:-
Here's one implementation.
And another.
And an MSDN version.
Thanks to David for pointing out the above are a bit out of date, so, after a quick Google, here's a more modern take on extending the file dialogs (and lots of other stuff as well).

How do I change properties of buttons within button boxes in Qt Designer?

I have been searching online to no avail. Does anyone know how to access a button in a button box (created using the "Dialog with Buttons Right" template)?
In Designer, select the OK or Cancel button. Then open the property editor and scroll down to the QDialogButtonBox section. You can then expand the standardButtons item to see the various buttons that are available. Other properties, such as the centerButtons property, are also available.
However, designer gives you very little control over the button box.
In code, you can do many other things, such as change the text that appears on the "standard buttons." From the documentation:
findButton = new QPushButton(tr("&Find"));
findButton->setDefault(true);
moreButton = new QPushButton(tr("&More"));
moreButton->setCheckable(true);
moreButton->setAutoDefault(false);
buttonBox = new QDialogButtonBox(Qt::Vertical);
buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);
As long as you give the button box a name in designer, you can set these properties in code.
I am writing this answer for the Python community. I am using PySide and faced a similar problem. I have a QDialogButtonBox and I would like to have my own buttons instead of the default ones.
I am using PySide which is more or less the exact replica of the c++ code, so I believe other c++ developers can also get something from it.
Here how I would do that:
my_ok_button = QtGui.QPushButton("My Ok Button")
my_cancel_button = QtGui.QPushButton("My Cancel Button")
ok_cancel_button = QtGui.QDialogButtonBox(QtCore.Qt.Horizontal)
ok_cancel_button.addButton(my_ok_button, QtGui.QDialogButtonBox.ButtonRole.AcceptRole)
ok_cancel_button.addButton(my_cancel_button, QtGui.QDialogButtonBox.ButtonRole.RejectRole)
I would then insert my button box to my layout like ususal:
layout.addWidget(ok_cancel_button, 1, 1)
Now later in my code I can do anything with my button. Lets change its name:
my_ok_button.setText("Some Other Name")
So then things to note here is that:
you must set the role of the buttons in the addButton() method if you
want to use functionalities given by standard buttons. E.g. if you
wish to do something like below, you need to have the button roles
set.
ok_cancel_button.accepted.connect(self.ok_method_handler)
ok_cancel_button.rejected.connect(self.close)
More information can be found here.