首页 > 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
版权所有 © 转载时必须以链接形式注明作者和原始出处!

28 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.

  14. #14 http://goo.gl/8r1Yuu 回复 | 引用 Post:2019-03-31 08:40

    It’s awesome designed for me to have a web page, which is good designed for my know-how.
    thanks admin

  15. #15 minecraft 回复 | 引用 Post:2019-04-14 15:28

    Definitely consider that that you said. Your favorite justification seemed to be at
    the web the easiest factor to bear in mind of.

    I say to you, I definitely get irked at the same time as other folks consider
    concerns that they plainly do not understand about.

    You managed to hit the nail upon the top as well as defined out the
    whole thing with no need side effect , other people could take a
    signal. Will likely be back to get more. Thank
    you

  16. #16 minecraft 回复 | 引用 Post:2019-04-22 02:19

    Hey would you mind letting me know which web host you’re utilizing?

    I’ve loaded your blog in 3 different web browsers and I must say this
    blog loads a lot quicker then most. Can you suggest a good internet hosting provider at a reasonable price?
    Kudos, I appreciate it!

  17. #17 gamefly free trial 回复 | 引用 Post:2019-05-03 00:53

    Hi there just wanted to give you a quick heads up.

    The text in your content seem to be running off the screen in Safari.
    I’m not sure if this is a format issue or something to do with
    browser compatibility but I figured I’d post to let you know.
    The layout look great though! Hope you get the
    problem solved soon. Many thanks

  18. Thank you for any other fantastic post. Where else may anyone
    get that kind of information in such an ideal approach of writing?
    I have a presentation next week, and I am at the look for such info.

  19. #19 gamefly free trial 回复 | 引用 Post:2019-05-20 00:27

    Great blog here! Also your web site loads up very fast!
    What host are you using? Can I get your affiliate link to
    your host? I wish my site loaded up as fast as yours lol

  20. #20 gamefly free trial 回复 | 引用 Post:2019-05-31 02:51

    Very descriptive article, I loved that a lot. Will there be a part 2?

  21. #21 gamefly free trial 回复 | 引用 Post:2019-06-02 06:57

    Great site you have here but I was wanting to know if you knew of any community forums that
    cover the same topics discussed here? I’d really like to be a
    part of community where I can get responses from other experienced people that share the same
    interest. If you have any suggestions, please let me know.
    Cheers!

  22. #22 gamefly free trial 回复 | 引用 Post:2019-06-03 12:08

    Hmm it seems like your blog ate my first comment (it was super long) so I guess I’ll
    just sum it up what I had written and say, I’m thoroughly enjoying your blog.

    I as well am an aspiring blog writer but I’m still new
    to the whole thing. Do you have any helpful hints for novice blog writers?
    I’d certainly appreciate it.

  23. #23 gamefly free trial 回复 | 引用 Post:2019-06-04 17:09

    With havin so much content and articles do you ever run into
    any issues of plagorism or copyright infringement?
    My site has a lot of exclusive content I’ve either created myself or outsourced but it appears a lot of
    it is popping it up all over the internet without my agreement.
    Do you know any methods to help protect against content from being stolen? I’d
    truly appreciate it.

  24. #24 gamefly free trial 回复 | 引用 Post:2019-06-06 08:22

    We absolutely love your blog and find almost all of your post’s
    to be just what I’m looking for. can you offer guest writers
    to write content for yourself? I wouldn’t mind producing a post or
    elaborating on a number of the subjects you write related to here.
    Again, awesome site!

  25. #25 gamefly free trial 回复 | 引用 Post:2019-06-07 01:43

    For most up-to-date news you have to pay a quick visit web and on internet I found this web site as
    a finest web page for hottest updates.

  26. It’s genuinely very complicated in this active life to listen news on Television, thus I simply use world wide web for
    that reason, and take the most recent information.

  27. #27 quest bars cheap 回复 | 引用 Post:2019-06-14 06:36

    Wonderful blog! Do you have any tips for aspiring writers?
    I’m hoping to start my own site soon but I’m a little lost on everything.
    Would you suggest starting with a free platform like WordPress
    or go for a paid option? There are so many choices out there that I’m completely overwhelmed ..
    Any recommendations? Cheers!

  28. #28 quest bars cheap 回复 | 引用 Post:2019-06-14 07:29

    Simply want to say your article is as amazing.
    The clearness in your post is just nice and i can assume you are an expert
    on this subject. Well with your permission allow me to
    grab your feed to keep up to date with forthcoming post.
    Thanks a million and please keep up the gratifying work.

发表评论