首页 > REDM基础教程 > REDM基础教程16-为托盘消息增加弹出菜单
2016十二月1

REDM基础教程16-为托盘消息增加弹出菜单

[隐藏]

  MyTest下载–>

MyTest.zip

 

 修改后的MyTest下载–>

MyTest.zip


上一节我们为QQ登陆框加了个托盘,这一节我们来为托盘的右键事件增加一个菜单
 

1.菜单构成

 

菜单有以下属性:

1.以<menu>为根结点  

2.属性位于DmMain\inc\Widgets\DUIMenuHelper.h中DUIMenuAttr,有详细介绍

3.为真实的菜单,DM库只是对菜单进行了hook,所以使用者可通过DUIMenuItem的m_hMenu来实际操作菜单

4.菜单支持扩展,可扩展所有消息和所有绘制,扩展示例可参考TGPMenu.h/.cpp

 

下面给个简单的菜单XML,名字就叫dui_exitmenu.xml,注意xml使用utf8编码

<menu clrbg="pbgra(f8,fc,e9,ff)" clrselbg="pbgra(33,99,ff,ff)" 
	  clrText="pbgra(00,00,00,ff)" clrTextSel="pbgra(fe,fe,fe,ff)" 
	  alpha="0x80" bshadow="1"  itemhei="24" textoffset="13" font="face:微软雅黑,size:13"><!--id必须不为0,,在1到65535之间,0在菜单TrackPopupMenu中表示fail-->
	<item text="官方支持(禁用态)" bdisable="1" />
	<item text="多语言切换"><!--三个子项-->
		<item id="100" text="英语"/>
		<item id="101" text="俄语"/>
		<item id="102" text="中文"/>
	</item>
	<sep/>
	<item text="自定高度" height="40"/>
	<item id="200" text="退出"/>
</menu>

xml项可自行参考DmMain\inc\Widgets\DUIMenuHelper.h中DUIMenuAttr,有详细介绍

每个item代表一项菜单:第一项为禁用状态,第二项有三个子项,第三项是一个分隔栏,第四项显示了自定义菜单项的高度

如果大家觉得麻烦,也可以使用简单模式的菜单,先把菜单的主外框隐藏掉(bhideframe="1"),每一项对应一个皮肤(皮肤可以自带文字,三态图)即可:

<menu  bhideframe="1">
    <item id="7000"  skin="btncustom"/>
    <item id="7001"  skin="dui_frame"/>
</menu>

  

我们把dui_exitmenu.xml保存到MyRes资源中,如前面几节的操作:

1.把dui_exitmenu.xml保存MyRes\layout\xml\目录下

  

2.打开MyRes\layout\dmindex.xml:增加dui_exitmenu.xml的路径

<?xml version="1.0"?>
<resource>
	<global>
		<file name="global" path="layout\xml\global.xml" />
	</global>
	<layout>
		<file name="main" path="layout\xml\main.xml" />
		<file name="exitmenu" path="layout\xml\dui_exitmenu.xml" />
	</layout>
</resource>

或者直接把MyRes加载到设计器中

25.gif  

  

2.托盘事件

  

前面一节提到了,右键弹出菜单消息,我们是在这里Post了WM_SHOWTRAYMENU这个消息到窗口m_hParentWnd

1.在MyTest\Test\inc\MainWnd.h增加

LRESULT OnShowTrayMenu(UINT uMsg, WPARAM wParam, LPARAM lParam);

 

2.在MyTest\Test\src\MainWnd.cpp的头上增加

#include "DUIMenu.h"

  

3.在MyTest\Test\src\MainWnd.cpp的消息处理中增加

BEGIN_MSG_MAP(CMainWnd)
	....
	MESSAGE_HANDLER_EX(WM_SHOWTRAYMENU, OnShowTrayMenu)
	CHAIN_MSG_MAP(DMHWnd)// 将未处理的消息交由DMHWnd处理
END_MSG_MAP()

  

4.增加弹出菜单函数

LRESULT CMainWnd::OnShowTrayMenu(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	DUIMenu Menu;
	Menu.LoadMenu(L"LayOut",L"exitmenu");
	POINT pt;
	GetCursorPos(&pt);
	Menu.TrackPopupMenu(0,pt.x,pt.y,m_hWnd);
	return TRUE;
} 

dui_exitmenu.xml是位于layout下的,名字叫exitmenu

  

运行效果如下:注意观察,前面配置里设置了alpha="0x80"(半透明效果),textoffset="13"(文字左移13)

 26.gif

 

3.菜单消息

菜单消息通过WM_COMMAND来处理

1.在\MyTest\Test\inc\MainWnd.h中加入

void OnCommand(UINT uNotifyCode, int nID, HWND wndCtl);

2.在MyTest\Test\src\MainWnd.cpp加入

MSG_WM_COMMAND(OnCommand)
....
void CMainWnd::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl)
{
	if (200 == nID)// dui_exitmenu.xml配置的id="200",响应退出菜单
	{
		OnClose();
	}
}

   

注意,菜单的ID为真实的菜单ID,所以限制在1到65535之间

   下一节教程:REDM基础教程17-多国语言配置      

 

文章作者:hgy413
本文地址:http://hgy413.com/3861.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

13 Responses to “REDM基础教程16-为托盘消息增加弹出菜单”

  1. #1 minecraft 回复 | 引用 Post:2018-10-05 13:25

    I’m not that much of a online reader to be honest but your blogs really nice, keep it up!
    I’ll go ahead and bookmark your site to come back later. Cheers

  2. #2 minecraft 回复 | 引用 Post:2018-10-05 20:08

    What’s up to every one, since I am actually eager of
    reading this blog’s post to be updated on a regular basis.
    It contains pleasant material.

  3. #3 minecraft 回复 | 引用 Post:2018-10-06 13:52

    hi!,I like your writing very much! proportion we keep up a correspondence extra approximately your post
    on AOL? I require an expert on this space to resolve my problem.

    May be that is you! Taking a look forward to peer you.

  4. #4 minecraft 回复 | 引用 Post:2018-10-07 17:07

    You’ve made some really good points there. I checked on the web for additional information about the issue and found most individuals will go
    along with your views on this web site.

  5. Hi colleagues, how is the whole thing, and what you want to say on the
    topic of this article, in my view its genuinely amazing in favor of me.

  6. #6 tinder dating site 回复 | 引用 Post:2018-10-16 12:02

    I am regular visitor, how are you everybody? This paragraph posted at this website is actually fastidious.

  7. Hello, i think that i saw you visited my weblog thus i came
    to “return the favor”.I’m attempting to find things to improve my
    site!I suppose its ok to use some of your ideas!!

  8. #8 quest bars cheap 回复 | 引用 Post:2018-11-04 22:35

    Quest bars cheap fitnesstipsnew1 quest bars cheap
    516999410492780544 quest bars cheap
    Normally I do not learn post on blogs, however
    I wish to say that this write-up very forced me to take a
    look at and do it! Your writing style has been amazed me.
    Thanks, very nice post. Quest bars cheap fitnesstipsnew1 quest bars cheap 516999410492780544 quest bars cheap

  9. #9 Sling TV 回复 | 引用 Post:2018-11-11 21:23

    This paragraph gives clear idea in favor of the new visitors of blogging, that truly how to do blogging.

  10. Everything is very open with a very clear clarification of the issues.
    It was truly informative. Your website is useful.
    Thank you for sharing!

  11. #11 Sling TV 回复 | 引用 Post:2018-11-14 13:04

    Nice blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make my blog shine.
    Please let me know where you got your theme. Bless you

  12. Since the admin of this website is working, no doubt very soon it will be well-known, due to
    its feature contents.

  13. I’m not sure exactly why but this blog is loading incredibly slow for me.
    Is anyone else having this problem or is it a
    problem on my end? I’ll check back later and see if the problem still exists.

发表评论