首页 > REDM基础教程 > REDM基础教程15-增加托盘功能
2016十一月29

REDM基础教程15-增加托盘功能

[隐藏]

 MyRes资源包和MyTest+qq.ico下载–>(方便起见,继续使用以前的工程和资源演示,不使用单exe工程)

MyTest1.zip

qqico.zip

  修改后的MyTest下载–>

MyTest.zip

 

  

   这一节我们来为我们的QQ登陆框增加一个托盘功能,下一节我们来为托盘增加一个菜单弹出框

   

1.托盘功能

   

托盘功能其实和UI是没有什么关系的,但DM还是在QQDemo中加了个简单的封装类TrayIconWndMgr,把

Samples\QQDemo\inc\TrayIconWndMgr.h
Samples\QQDemo\src\TrayIconWndMgr.cpp

分别放在Test\incTest\src中,运行编译

1>TrayIconWndMgr.cpp
1>..\..\MyTest\Test\src\TrayIconWndMgr.cpp(1) : warning C4627: '#include "QQDemoAfx.h"': skipped when looking for precompiled header use

还是老规则,把QQDemoAfx.h替换成StdAfx.h,编译通过! 

    

我们先给它增加一个ICO图标吧:

1.把qq.ico放在Test\inc目录下

  

2.在VS工程中的资源中加入qq.ico文件,名字就叫IDI_ICON1

  

3.把自动生成的Build2008\Test\resource.h以及Build2008\Test\Test.rc转移到MyTest\Test\inc\中

  

4.修改MyTest\Test\CMakeLists.txt,把

FILE(GLOB ROOT_HEADER 		${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h)

更改为(自动在VS工程的inc这个filter中加载rc后缀的文件)

FILE(GLOB ROOT_HEADER 		${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h;${CMAKE_CURRENT_SOURCE_DIR}/inc/*.rc)

  

5.重新生成一次CMAKE,这时应该显示成这样:

7.png

  

6.在\MyTest\Test\inc\MainWnd.h中增加构造函数和析构函数:

CMainWnd();
~CMainWnd();

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

#include "resource.h"
#include "TrayIconWndMgr.h"

在构造函数和析构函数中增加托盘消息类对象的new和delete,在OnInitDialog增加托盘提示和汽泡提示

CMainWnd::CMainWnd()
{
	new CTrayIconWndMgr;
}

CMainWnd::~CMainWnd()
{
	CTrayIconWndMgr::getSingletonPtr()->SetBalloonDetails(L"DM托盘提示",L"MyTest已退出");
	delete CTrayIconWndMgr::getSingletonPtr();
}

BOOL CMainWnd::OnInitDialog(HWND wndFocus, LPARAM lInitParam)
{
	// todo
	// 增加一个托盘图标
	HICON hIcon = ::LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1));
	CTrayIconWndMgr::getSingleton().InstallTrayIcon(L"托盘提示:MyTest",m_hWnd,hIcon,IDI_ICON1);
	// 增加一个汽泡提示
	CTrayIconWndMgr::getSingletonPtr()->SetBalloonDetails(L"汽泡提示",L"MyTest");

	return TRUE;
}

这时,运行,我们看到的效果应该如下:

21.gif

  

7.最后介绍下接收消息的地方:CTrayIconWndMgr::OnTrayIcon

LRESULT CTrayIconWndMgr::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	UINT Msg = (UINT)LOWORD(lParam);
	switch (Msg)
	{
	case WM_RBUTTONUP:
		{
			::PostMessage(m_hParentWnd, WM_SHOWTRAYMENU, 0 ,NULL);
		}
		break;

比如我们的右键弹出菜单消息,我们是在这里Post了WM_SHOWTRAYMENU这个消息到窗口m_hParentWnd中,m_hParentWnd就是前面代码中InstallTrayIcon传入的m_hWnd

  

   

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

     

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

13 Responses to “REDM基础教程15-增加托盘功能”

  1. #1 minecraft 回复 | 引用 Post:2018-10-03 20:42

    I read this article fully regarding the difference of newest
    and previous technologies, it’s awesome article.

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

    Hi, There’s no doubt that your website could possibly be having internet browser compatibility issues.
    When I take a look at your site in Safari, it looks fine however, if
    opening in IE, it has some overlapping issues. I merely wanted to provide you with a quick heads up!
    Aside from that, wonderful site!

  3. #3 minecraft 回复 | 引用 Post:2018-10-06 19:56

    It’s hard to come by knowledgeable people about this subject,
    however, you seem like you know what you’re talking about!

    Thanks

  4. Wow, that’s what I was searching for, what a stuff! present here at this website,
    thanks admin of this site.

  5. It’s remarkable in favor of me to have a website, which is useful in favor of my know-how.
    thanks admin

  6. Valuable info. Lucky me I found your site by chance,
    and I am surprised why this accident did not came about in advance!
    I bookmarked it.

  7. I am genuinely glad to glance at this weblog posts which carries lots of valuable facts, thanks for providing these kinds of data.

  8. #8 Benefits of Coconut Oil 回复 | 引用 Post:2018-10-19 13:15

    Helpful information. Lucky me I found your web site by accident, and I am
    stunned why this accident didn’t came about in advance! I bookmarked it.

  9. #9 Benefits of Coconut Oil 回复 | 引用 Post:2018-10-27 02:48

    Every weekend i used to pay a quick visit this website, for the
    reason that i wish for enjoyment, as this this web
    page conations genuinely good funny material too.

  10. I have read so many articles or reviews on the topic of the blogger
    lovers however this post is truly a fastidious article,
    keep it up.

  11. Hey I know this is off topic but I was wondering if you knew of any widgets I could
    add to my blog that automatically tweet my newest twitter updates.

    I’ve been looking for a plug-in like this for quite some time
    and was hoping maybe you would have some experience with something like this.

    Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  12. #12 Sling TV 回复 | 引用 Post:2018-11-11 12:31

    This post is priceless. When can I find out more?

  13. #13 Sling TV 回复 | 引用 Post:2018-11-11 21:35

    Fantastic blog you have here but I was curious if you knew of any discussion boards that cover the same topics talked about here?
    I’d really love to be a part of community where I can get feed-back from other knowledgeable people that share
    the same interest. If you have any recommendations, please let
    me know. Cheers!

发表评论