System Tray Menu error MFC - c++

I am Making an Application which will make a dialog as system tray icon after some button press. it is working fine but also i need to open the menu same as dialog contains on Right Click and have written following Code:
CMenu pMenu;
pMenu.LoadMenu(IDR_MENU1);
POINT pointCursor;
::GetCursorPos( &pointCursor );
pMenu.TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pointCursor.x, pointCursor.y, this);
It is Creating the menu but the width of the menu is very thin as shown following:(Yellow highlighted area is menu)
if I add only first submenu of main menu then it works well as following code:
CMenu *pMenu = GetMenu();
POINT pointCursor;
CMenu *pMenu = GetMenu();
::GetCursorPos( &pointCursor );
pMenu->GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pointCursor.x,pointCursor.y,this);
On applying this code i get following output
Actually I need the Following menu:
Kindly Suggest Where i am doing it wrong

TrackPopupMenu cannot display the menu bar as part of it's work. The menu bar itself is not displayed because TrackPopupMenu requires a handle to a menu, submenu, or shortcut menu. So, given that, if you really want the same menu structure including the menu bar you've shown, you'll need to create that structure dynamically using CMenu methods. Or, simply create a new menu resource with a different name that includes the menu bar items as submenus.

Related

How to insert more dialogs in MFC Dialog application?

I am trying to build an MFC application Dialog based application. It runs ok. But I need to insert another Dialog. So how can I for example, pressing on a button from the first dialog to open the new added dialog?.
I am using Microsoft Visual Studio 2015.
I right clicked on the resources folder and insert a dialog.
It is inserted, but how to create it?.
Thank you.
The easiest way is: I consider you are creating a Dialog based application so you get a main Dialog box and an About Dialog box when Selecting menu->About.
To add Another Dialog to your application:
1- Right click on the solution explorer on the resources files and select Add->Resource->Dialog->New
You get a new Dialog right front of you. Right click on this Dialog and select Add Class. give it for example a name like "MyDlg2" and click ok.
You'll see two files added: MyDlg2.h and MyDlg2.cpp.
Now How to Popup this second dialog (MyDlg2)? Let's create a button on the main Dialog:
Drag a button onto Main Dialog.
Give it a caption "Gong to Dialog2..."
Double-click this button to add a handler for it.
In this handler enter:
MyDlg2 dlg;
dlg.DoModal();
Scroll to the top of this file and add:
#include "MyDlg2.h"
This is important so that main Dialog knows How to create dialog 2.
Build and run.
You need to derive a class from CDialog.
For more information check this MSDN example.

MFC menu item doesn't open dialog box

I am having a proglem with the MFC application and the DialogBox. I am quiet sure I've done everything well with this tutorial: https://msdn.microsoft.com/en-us/library/6wb9s9ah.aspx
but still it doesn't work...
1. I've created new project with simple menu commands.
2. I've created new menu item (+ID) and new resource DialogBox (+ID).
3. Then I've added a new class named CParameters with the Class Wizard. For the BaseClass I've typed in CDialog.
4. I've created new handler on the menu item and added the code
CParameters dlg;
dlg.DoModal();
I think this is it, and this should work... But it doesnt... What is missing??
Here is my project, you can access it freely:
https://www.dropbox.com/sh/e6ajoxqk76hkuvn/AACRMY8bgcuyXguFwP240QB9a?dl=0
Additionally I want to insert TextEditors and to change parameters in my program from the dialog box.
A scan of your source code reveals that you are trying to handle the menu item event within the class that is going to display the dialog.
void CParameters::OnParam()
{
// TODO: Add your command handler code here
CParameters dlg;
dlg.DoModal();
}
I don't see anywhere else that you actually instantiate the dialog class (I may have missed it). What you are trying is incorrect. You cannot handle the menu item event within the same class that displays the dialog because that class (CParameters) has not been instantiated, so, it cannot respond to the menu event. Typically, the menu event would be handled in the mainframe class.
If you are doing this by adding a new menu item from a simple SDI application, then trying adding that part of code in
CMainFrame::OnEdit
OnEdit method used here is obtained from the Event Handler for the new menu item and Message type being COMMAND.

How to minimize the page in the property sheet?

I have used property sheet concept and display 3 dialog box on the property sheet.
Now to access the each dialog i have to clicked on the tab of each dialog.
But my need is that i want to minimize the first dialog and show the second dialog without using tab. for that i have added one button using that button i minimized the first dialog but when i tried to call the second dialog i get assertion failed error. i have done like this...
In the 1st dialog (.cpp) file :
void ClstdemoDlg::OnBnClickedMinimize()
{
ClstdemoDlg_1 dlg; // created 2nd dialog variable.
this->ShowWindow(SW_MINIMIZE); // minimize the 1st dialog
dlg.ShowWindow(SW_SHOW); //Tried to show 2nd dialog but get Assertion failed Error
}
Please let me know how to do this?

How to add a menu item dynamically with an image in MFC featurepack

In MFC featurepack i create a standard menu and set the ID of sub menu to the same command of toolbar button to take that button's image that toolbar is the one sent to this method
CMFCToolBar::AddToolBarForImageCollection
and also I use the
GetContextMenuManager()->AddMenu(L"Mymenu", IDR_ContextMenu1);
in the application and
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_ContextMenu1,rect.left,rect.top,button);
in the show menu event
I need to know how to add a menu item with a specified icon at the run-time dynamically
See the documentation about OnInitMenuPopup of your CMainFrame.

Adding Menu and Submenu options to Window Menu in MAC using wXwidget C++

Hi I am new to Mac using wxWidget.
I need to add a sub menu and some menu items under the Window Menu on MAC.
I am able to do same for Window menu on PC but not on MAC.
Also, I am not getting event for click on Window Menu to the function attached with EVT_MENU_OPEN event.
Please help.
I don't really understand the question clearly. However you may have to do something like this for a menu on mac.
m_menuBar = new wxMenuBar();
#if defined(__WXMAC__)
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macAboutMenuItemId, wxT("About"));
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macWindowMenuItemId, wxT("Window"));
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macExitMenuItemId, wxT("Quit"));
#endif
where s_macAboutMenuItemId, s_macWindowMenuItemId, s_macExitMenuItemId are your respective menu ids defined.
and regarding not getting event for click on Window Menu to the function attached with EVT_MENU_OPEN event, check if you have correct entries(Menu id, corresponding function name) in the declared event table.