如何显示无模式对话框并立即显示信息? [英] How can I show a modeless dialog and display information in it immediately?

查看:229
本文介绍了如何显示无模式对话框并立即显示信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在屏幕上显示一个无模式对话框,并显示其中的一些信息。

I want to show a modeless dialog on the screen and display some information in it.

但是,如果以下方式使用它,它有一些问题: / p>

However if I use it the following way, it has some problems:

function()
{
showdialog(XXX).
//heavy work.
update the dialog..
//heavy work.
update the dialog...
}

似乎对话框显示,但它并没有提供任何信息。

It seems the dialog displayed, but it does not draw any information in it. It only draw all information when the function is over.

如何修改无模式对话框,以便立即显示信息?

How can I modify the modeless dialog so it will display the information immediately?

推荐答案

有一些事情可以做。

(1)您可以从 CDialog :: OnInitDialog 方法中的发布对话框中的消息,然后处理该发布消息的消息处理程序中的long函数。这样对话框将首先被显示,然后长功能将被运行。

(1) You could post the dialog a message from inside the CDialog::OnInitDialog method and then handle the long function in the message handler of that posted message. That way the dialog will first be displayed and then later the long function will get run.

(2)第二个选项是确保消息循环获得一些处理时间。因此,如果您的长期功能是某种循环,只需添加偶然的呼叫到 ProcessMessages ,以确保消息队列保持为空:

(2) The second option is to make sure the message loop gets some processing time. So if your long function is some sort of loop just add the occasional call to the ProcessMessages to make sure the message queue is kept empty:

void ProcessMessages()
{
    MSG msg;
    CWinApp* pApp = AfxGetApp();
    while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
    {
        pApp->PumpMessage();
    }
}

编辑:可能使用线程是这样的情况,但是这样做并不总是没有风险和复杂性。

It certainly is possible to use threads is such a situation, but doing so is not always without risk and complexity.

使用带有 GUI 的线程意味着必须处理多个消息队列,这意味着使用API​​,如 PostThreadMessage 和引入一组新的问题要警惕。

Using threads with a GUI means having to deal with multiple message queues which then means using API's like PostThreadMessage and that introduces a new set of issues to be wary of.

对于一个这样的问题的例子,请参阅此链接:

For an example of one such issue refer to this link:

http://msdn.microsoft.com /en-us/library/ms644946(VS.85).aspx

哪里说:


PostThreadMessage发送的消息是
与窗口无关。作为
一般规则,与窗口关联的不是
的邮件不能由DispatchMessage
函数调度
。因此,如果收件人
线程处于模态循环(由
MessageBox或DialogBox使用),则
消息将丢失。要在模式
循环中拦截
线程消息,请使用线程特定的钩子。

Messages sent by PostThreadMessage are not associated with a window. As a general rule, messages that are not associated with a window cannot be dispatched by the DispatchMessage function. Therefore, if the recipient thread is in a modal loop (as used by MessageBox or DialogBox), the messages will be lost. To intercept thread messages while in a modal loop, use a thread-specific hook.

我使用 Zeus IDE 中的流程消息方法,它可以很好地保证GUI对用户的响应。它还具有非常容易实现的优点。

I use the process message approach in the Zeus IDE and it works very well at making sure the GUI remains responsive to the user. It is also has the advantage of being very easy to implement.

这篇关于如何显示无模式对话框并立即显示信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆