首页 > DUI > DUI-模态对话框的实现
2014八月6

DUI-模态对话框的实现

模态对话框要求自己实现自己的消息循环,当然,建议它还是处于主线程中,所以最好是由它再调用主线程的消息循环函数,此时主线程自身的消息循环函数被阻塞,等待模板对话框的消息循环函数退出

blob.png

参考代码如下:

	INT_PTR XX::DoModal(LPCWSTR lpszXmlId, HWND hParent/*=NULL*/, bool bShadow/*=false*/, DM::CRect rect/* = NULL*/)
	{
		BOOL bEnableParent = FALSE;
		if(NULL == hParent)
		{
			hParent = GetActiveWnd();
		}
		
		if (hParent && hParent != ::GetDesktopWindow() && ::IsWindowEnabled(hParent))
		{
			::EnableWindow(hParent, FALSE);
			bEnableParent = TRUE;
		}

		if(!DM_CreateWindow(lpszXmlId, rect.left,rect.top,rect.Width(),rect.Height(), hParent, bShadow))
		{
			::EnableWindow(hParent, TRUE);
			return 0; // 此处失败了
		}

		GetClientRect(rect);
		if (!rect.IsRectEmpty())
		{
			CenterWindow();
		}

		SendMessage(WM_INITDIALOG);//发送init消息

		if(GetExStyle()&WS_EX_TOOLWINDOW)
		{
			::ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
		}
		else
		{
			::ShowWindow(m_hWnd,SW_SHOWNORMAL);
		}

		
		::SetWindowPos(m_hWnd, /*HWND_TOP*/HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
	         Run(m_hWnd,true);// 消息循环

		if (bEnableParent)
		{
			::EnableWindow(hParent, TRUE);
		}

		return m_nRetCode;
	}

	void  XX::EndDialog( INT_PTR nResult )
	{
		m_nRetCode = nResult;
		PostMessage(WM_QUIT);
	}

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

24 Responses to “DUI-模态对话框的实现”

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

    It’s not my first time to go to see this web site, i am visiting this web page
    dailly and get fastidious data from here daily.

  2. #2 minecraft 回复 | 引用 Post:2018-10-06 13:00

    Appreciate this post. Let me try it out.

  3. #3 minecraft 回复 | 引用 Post:2018-10-07 03:49

    you’re truly a good webmaster. The web site loading
    speed is amazing. It sort of feels that you are doing any unique
    trick. In addition, The contents are masterpiece.
    you’ve done a great activity in this matter!

  4. I know this if off topic but I’m looking into starting my own blog
    and was wondering what all is needed to get setup? I’m assuming having
    a blog like yours would cost a pretty penny? I’m not very web savvy
    so I’m not 100% sure. Any recommendations or advice would be greatly appreciated.
    Appreciate it

  5. Does your website have a contact page? I’m having trouble locating it but,
    I’d like to shoot you an e-mail. I’ve got some suggestions for your blog you might be interested in hearing.
    Either way, great site and I look forward to seeing it grow over time.

  6. #6 tinder dating site 回复 | 引用 Post:2018-10-17 11:21

    Hey! This post could not be written any better!

    Reading this post reminds me of my previous room mate!

    He always kept chatting about this. I will forward this article to him.
    Pretty sure he will have a good read. Many thanks for sharing!

  7. Hey there! Quick question that’s totally off topic.
    Do you know how to make your site mobile friendly? My website looks weird when browsing from my apple iphone.
    I’m trying to find a template or plugin that might be able to correct this problem.

    If you have any recommendations, please share.

    Cheers!

  8. It’s amazing designed for me to have a site, which is beneficial for
    my experience. thanks admin

  9. #9 Coconut Oil 回复 | 引用 Post:2018-10-24 11:38

    I was able to find good information from your blog posts.

  10. #10 descargar facebook 回复 | 引用 Post:2018-11-02 13:16

    I do not even know how I ended up here, however I believed
    this publish was great. I don’t know who you might be but definitely you are going to a
    well-known blogger in case you are not already.

    Cheers!

  11. #11 quest bars cheap 回复 | 引用 Post:2018-11-03 10:53

    Hey there just wanted to give you a quick heads up. The words in your content seem
    to be running off the screen in Opera. I’m not sure if this is a format issue or something
    to do with web browser compatibility but I figured I’d post to let
    you know. The design and style look great though!
    Hope you get the problem solved soon. Cheers

  12. #12 quest bars 回复 | 引用 Post:2018-11-06 07:29

    Thanks for the marvelous posting! I seriously enjoyed reading it, you could be a great author.I will make certain to bookmark your blog and may
    come back sometime soon. I want to encourage yourself to continue your great writing, have a nice evening!

  13. #13 Quest Bars 回复 | 引用 Post:2018-11-09 04:24

    I don’t even understand how I stopped up here, however
    I believed this publish was great. I don’t know who you
    might be however definitely you are going to a
    well-known blogger if you happen to are not already.
    Cheers!

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

    Right now it sounds like BlogEngine is the preferred blogging platform out there right now.
    (from what I’ve read) Is that what you’re using
    on your blog?

  15. #15 Sling TV 回复 | 引用 Post:2018-11-14 03:12

    Hey there! I could have sworn I’ve been to this blog before but after reading through some of the post
    I realized it’s new to me. Anyhow, I’m definitely delighted I found
    it and I’ll be book-marking and checking back frequently!

  16. Sling tv coupons and promo codes for november 2018
    Somebody essentially help to make significantly articles I’d state.
    This is the very first time I frequented your website page and up
    to now? I surprised with the analysis you made to
    create this actual submit extraordinary. Great activity!
    Sling tv coupons and promo codes for november 2018

  17. Hello, i feel that i noticed you visited my site so
    i got here to return the want?.I am attempting
    to in finding issues to enhance my site!I assume its adequate to use a few of your concepts!!

  18. It’s a shame you don’t have a donate button! I’d certainly
    donate to this brilliant blog! I guess for now
    i’ll settle for book-marking and adding your RSS feed to my Google
    account. I look forward to fresh updates and will share this website with my Facebook
    group. Talk soon!

  19. Today, I went to the beachfront with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

  20. I like the valuable information you provide on your articles.

    I’ll bookmark your weblog and check again here regularly.

    I am slightly certain I will be informed plenty of new stuff right right
    here! Best of luck for the following!

  21. #21 read me 回复 | 引用 Post:2019-02-19 23:58

    I’m impressed, I must say. Seldom do I come across
    a blog that’s both educative and interesting, and let me tell you, you’ve hit the nail on the head.
    The problem is something that not enough men and women are speaking intelligently about.
    Now i’m very happy I came across this during my hunt for something regarding this.

  22. #22 read me 回复 | 引用 Post:2019-02-23 11:02

    whoah this blog is fantastic i really like reading your articles.
    Keep up the great work! You realize, a lot of individuals are looking round for this information, you could aid them greatly.

  23. #23 g 回复 | 引用 Post:2020-06-15 14:59

    Hi everybody, here every person is sharing such know-how, so it’s good to read this blog, and I used to go to see this webpage all the time.

  24. #24 g 回复 | 引用 Post:2020-06-15 22:36

    Hi there, I discovered your website by means of Google whilst looking for a comparable
    topic, your site came up, it appears to be like good. I’ve bookmarked it in my
    google bookmarks.
    Hello there, simply was alert to your blog through Google, and located that it’s truly informative.
    I am going to watch out for brussels. I will be grateful should you continue this
    in future. Lots of folks will likely be benefited out of your writing.
    Cheers!

发表评论