首页 > REDM基础教程 > REDM基础教程7-DUI子控件消息分发
2016十月31

REDM基础教程7-DUI子控件消息分发

[隐藏]

根据上一节,我们知道了主窗口消息宏实际为ProcessWindowMessage函数的封装,而DUI控件是主窗口模拟出来的(实际不存在),这一节我们讨DUI控件的消息分发

  

我们能猜到DUI控件的消息是由主窗口转发过来的,比如主窗口在接收到鼠标消息后,通过查找鼠标当前停留在哪个DUI子控件上,模拟分发消息

从DMHWnd的

	MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent)

转发到DUI子控件

	LRESULT DMHWnd::OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
                ....
		OnFrameEvent(uMsg,wParam,lParam);    //将鼠标消息转发到DUI子控件处理

针对鼠标消息处理

	else if(uMsg>=WM_MOUSEFIRST&&uMsg<= WM_MOUSELAST)// 鼠标点击相关
	{
		OnFrameMouseEvent(uMsg,wParam,lParam);
	}

OnFrameKeyEvent的代码逻辑如下:

blob.png

发送消息代码如下:

void DMContainerImpl::OnFrameMouseEvent(UINT uMsg,WPARAM wParam,LPARAM lParam)
{        ......
	pCaptureWnd->DM_SendMessage(uMsg,wParam,lParam,&bMsgHandled);// 转发消息

可以看出,DUI子控件的发送消息函数为:DM_SendMessage

LRESULT DUIWindow::DM_SendMessage(UINT uMsg, WPARAM wp /*= 0*/, LPARAM lp /*= 0*/,BOOL *pbMsgHandled/*=NULL*/)
	{
	...
	ProcessDuiMessage(uMsg, wp, lp, lResult);//触发消息宏DUIMsgCrack

而DUI子控件分发消息函数为ProcessDuiMessage,DUI子控件的消息宏即是对ProcessDuiMessage函数的封装

   

  

1.使用MacroTool小工具

宏是提供了易用性,但难于调试,因为VS在转换宏时,会把所有宏转换成一行!,所以提供了个小工具方便转换宏,打开Tools\MacroTool\已编译的bin\DMMacro.exe,把DMMsgCrack.h、DMXmlCrack.h、DUIMsgCrack.h、DMEventCrack.h拷贝到同目录下

把要转换的宏粘贴到小工具里,如DMMain的DUIButton.h中的

	DM_BEGIN_MSG_MAP()
			DM_MSG_WM_PAINT(DM_OnPaint)
			DM_MSG_WM_NCPAINT(DM_OnNcPaint)
			DM_MSG_WM_ERASEBKGND(DM_OnEraseBkgnd)
			MSG_WM_LBUTTONDBLCLK(OnLButtonDown) //将双击消息处理为单击
			MSG_WM_DESTROY(OnDestroy)
		DM_END_MSG_MAP()

点击Convert,即转换成功(注释去掉) 

18.gif

转换后的代码如下:(已去掉注释)

virtual BOOL ProcessDuiMessage( 
			UINT uMsg, WPARAM wParam, 
			LPARAM lParam, LRESULT& lResult) 
		{ 
			if (uMsg == WM_PAINT) 
			{ 
				SetMsgHandled(TRUE); 
				DM_OnPaint((IDMCanvas *)wParam); 
				lResult = 0; 
				if (IsMsgHandled()) 
					return TRUE; 
			}
			if (uMsg == WM_NCPAINT) 
			{ 
				SetMsgHandled(TRUE); 
				DM_OnNcPaint((IDMCanvas *)wParam); 
				lResult = 0; 
				if (IsMsgHandled()) 
					return TRUE; 
			}
			if (uMsg == WM_ERASEBKGND) 
			{ 
				SetMsgHandled(TRUE); 
				lResult = (LRESULT)DM_OnEraseBkgnd((IDMCanvas *)wParam); 
				if(IsMsgHandled()) 
					return TRUE; 
			}
			if (uMsg == WM_LBUTTONDBLCLK) 
			{ 
				SetMsgHandled(TRUE); 
				OnLButtonDown((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); 
				lResult = 0; 
				if(IsMsgHandled()) 
					return TRUE; 
			}
			if (uMsg == WM_DESTROY) 
			{ 
				SetMsgHandled(TRUE); 
				OnDestroy(); 
				lResult = 0; 
				if(IsMsgHandled()) 
					return TRUE; 
			}
			if (!IsMsgHandled()) 
			{ 
				return __super::ProcessDuiMessage(uMsg, wParam, lParam, lResult); 
			} 
			return TRUE; 
		}

从转换后的代码我们可以看出,DUI子控件消息分发和主窗口消息分发代码是完全相同,所以可以和主窗口消息分发宏混用

所以如果我们想处理完某个消息后,又想让父类来接着处理

和处理主窗口消息一样,可以使用

SetMsgHandled(FALSE);

   

2.增加DUI控件消息函数

  经过前面的介绍,增加DUI子控件的消息函数是非常简单的

以DUIButton为例:以下面代码做为宏的开头

DM_BEGIN_MSG_MAP()// ProcessDuiMessage函数声明
	DM_MSG_WM_PAINT(DM_OnPaint)// 处理DUI的绘制前景消息
	DM_MSG_WM_NCPAINT(DM_OnNcPaint)// 处理DUI的绘制非客户区消息
	
	DM_MSG_WM_ERASEBKGND(DM_OnEraseBkgnd)// 处理DUI的绘制背景消息
	MSG_WM_LBUTTONDBLCLK(OnLButtonDown) // 将接收到的双击消息处理为单击
	MSG_WM_DESTROY(OnDestroy)// DUI接收到WM_DESTROY消息
DM_END_MSG_MAP()

 

有些消息需要自己处理完后交由父窗口处理,使用

SetMsgHandled(FALSE);

   

        下一节教程:REDM基础教程8-DUI子控件事件消息分发

   

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

29 Responses to “REDM基础教程7-DUI子控件消息分发”

  1. #1 minecraft 回复 | 引用 Post:2018-10-04 08:23

    This is a topic that’s close to my heart… Many thanks!
    Exactly where are your contact details though?

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

    What a stuff of un-ambiguity and preserveness of precious knowledge regarding unexpected
    emotions.

  3. #3 minecraft 回复 | 引用 Post:2018-10-06 08:51

    I love looking through a post that will make people think.
    Also, many thanks for allowing for me to comment!

  4. I just like the helpful information you provide for your articles.
    I’ll bookmark your blog and test once more right here regularly.
    I’m moderately sure I’ll be told many new stuff proper here!
    Best of luck for the following!

  5. If you wish for to improve your know-how only keep visiting this website and be updated with the most recent news posted here.

  6. #6 Benefits of Coconut Oil 回复 | 引用 Post:2018-10-21 11:56

    Way cool! Some extremely valid points! I appreciate you writing
    this post and also the rest of the site is very good.

  7. #7 quest bars cheap 回复 | 引用 Post:2018-11-03 01:30

    Heya i’m for the first time here. I found this board and I find It really useful & it helped me out
    much. I hope to give something back and aid others like you aided
    me.

  8. #8 Quest Bars Cheap 回复 | 引用 Post:2018-11-06 20:19

    Whats up this is kind of of off topic but I was
    wondering if blogs use WYSIWYG editors or if you
    have to manually code with HTML. I’m starting a blog soon but
    have no coding expertise so I wanted to get guidance from someone with experience.
    Any help would be enormously appreciated!

  9. I like the valuable info you supply to your articles. I’ll bookmark your
    weblog and check again right here regularly. I am moderately certain I will be informed lots of new
    stuff proper right here! Best of luck for the next!

  10. #10 Sling TV 回复 | 引用 Post:2018-11-11 04:29

    I always emailed this web site post page to all my associates, for the reason that if like to read it then my links will too.

  11. #11 descargar facebook 回复 | 引用 Post:2018-11-21 03:43

    Howdy! I know this is kinda off topic however , I’d figured I’d ask.

    Would you be interested in exchanging links or maybe guest
    writing a blog post or vice-versa? My website addresses a lot of the same topics
    as yours and I believe we could greatly benefit from
    each other. If you’re interested feel free to send me an email.
    I look forward to hearing from you! Great blog by the
    way!

  12. #12 descargar facebook 回复 | 引用 Post:2018-12-06 08:16

    Thanks for finally writing about >blog topic <Liked it!

  13. #13 descargar facebook 回复 | 引用 Post:2018-12-06 14:08

    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.

  14. #14 Stacey 回复 | 引用 Post:2020-05-14 14:56

    You can certainly see your enthusiasm within the
    work you write. The world hopes for more passionate writers such as you who aren’t afraid to mention how they believe.
    Always follow your heart.

  15. #15 Aja 回复 | 引用 Post:2020-05-22 10:18

    Very good blog post. I absolutely love this website. Continue the good work!

  16. #16 Sidney 回复 | 引用 Post:2020-05-28 11:52

    What’s up to all, since I am truly keen of reading
    this weblog’s post to be updated regularly. It carries fastidious information.

  17. #17 xbox live free codes 回复 | 引用 Post:2020-06-07 05:03

    This post presents clear idea in favor of the new people of blogging, that
    actually how to do blogging and site-building.

  18. It’s really a nice and helpful piece of info. I’m glad that you just shared this
    helpful info with us. Please keep us up to date like this.
    Thank you for sharing.

  19. #19 google play gift card 回复 | 引用 Post:2020-06-07 07:45

    Thank you for the good writeup. It in fact was a amusement account
    it. Look advanced to more added agreeable from you! However,
    how could we communicate?

  20. #20 township hack 回复 | 引用 Post:2020-06-08 19:26

    Thanks for every other magnificent post. The place else could anyone get that type of information in such an ideal
    way of writing? I’ve a presentation next week, and I am at the search for such information.

  21. #21 king of avalon cheats 回复 | 引用 Post:2020-06-08 20:51

    If some one wishes expert view regarding blogging afterward i recommend him/her to visit
    this web site, Keep up the pleasant work.

  22. #22 star trek command hack 回复 | 引用 Post:2020-06-08 21:04

    Remarkable! Its in fact awesome piece of writing, I have got much
    clear idea concerning from this article.

  23. #23 pubg mobile hack 回复 | 引用 Post:2020-06-08 22:58

    Howdy! Do you know if they make any plugins to help with Search Engine
    Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Thanks!

  24. #24 because g 回复 | 引用 Post:2020-06-10 16:32

    I constantly emailed this web site post page to all my contacts, for the
    reason that if like to read it afterward my contacts will too.

  25. #25 g even 回复 | 引用 Post:2020-06-11 16:40

    This piece of writing is genuinely a nice one it helps new net visitors, who are wishing for
    blogging.

  26. #26 afk arena hack 回复 | 引用 Post:2020-06-14 08:09

    Its such as you read my thoughts! You seem to grasp so much approximately this,
    like you wrote the guide in it or something.
    I believe that you could do with some p.c. to force
    the message home a bit, but other than that, that is
    wonderful blog. An excellent read. I will certainly be
    back.

  27. Because the admin of this web page is working, no question very soon it will be famous,
    due to its feature contents.

  28. #28 http://tinyurl.com/ 回复 | 引用 Post:2020-06-14 10:39

    I’ve been browsing online more than 2 hours today,
    yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all webmasters and bloggers made good content as you did, the internet will
    be much more useful than ever before.

  29. #29 g 回复 | 引用 Post:2020-06-15 23:13

    Appreciation to my father who told me on the topic of this website,
    this website is in fact remarkable.

发表评论