简体   繁体   English

系统托盘菜单错误MFC

[英]System Tray Menu error MFC

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. TrackPopupMenu无法在其工作中显示菜单栏 The menu bar itself is not displayed because TrackPopupMenu requires a handle to a menu, submenu, or shortcut menu. 由于TrackPopupMenu需要菜单,子菜单或快捷菜单的句柄,因此不会显示菜单栏本身。 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. 因此,鉴于此,如果您确实希望包含显示的菜单栏的菜单结构相同,则需要使用CMenu方法动态创建该结构。 Or, simply create a new menu resource with a different name that includes the menu bar items as submenus. 或者,只需使用其他名称创建一个新的菜单资源,其中包含菜单栏项作为子菜单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM