MFC对话框冻结 [英] MFC dialog form freezes

查看:111
本文介绍了MFC对话框冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的MFC对话框类型窗口,该窗口调用外部dll函数,参数之一是回调函数.如果未创建回调函数,则会创建另一个对话框窗口,并使用来自函数参数的信息更新标签:

I have simple MFC dialog type window that calls external dll function and one of parameters is callback function. Callback function creates another dialog window if it is not created and updates label with information from function parameter:

int userNotify ( int iNotificationType, char* pcNotificationText )
{

if(statusDlg)
    {
        if ( !(statusDlg->IsWindowVisible()) ) 
        {
            statusDlg->ShowWindow(SW_SHOW);
        }
        statusDlg->showNotification(iNotificationType,pcNotificationText);
    } else
    {

        statusDlg = new StatusDlg(NULL);
        statusDlg->Create(StatusDlg::IDD,CWnd::GetDesktopWindow());
        statusDlg->ShowWindow(SW_SHOW);
        statusDlg->showNotification(iNotificationType,pcNotificationText);
    }


 return 0;
}

statusDlg是全局变量,是带有一个静态标签的非常简单的MFC对话框形式.它具有一项功能-位于最上方.

statusDlg is global variable and is very simple MFC dialog form with one static label. And it has one feature - it is placed on topmost.

    BOOL StatusDlg::OnInitDialog()
    {
        staticStatus = (CStatic*)GetDlgItem(IDC_STATIC_TRN_STATUS_DIALOG);

...    
        SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);


        return TRUE;  // return TRUE  unless you set the focus to a control
    }

在回调过程中会显示对话框形式,标签会显示必需的信息.但是,如果我尝试用鼠标移动表格,它将变得冻结,如下图所示,并且标签上的信息不再更新.为什么会这样?如何解决这个问题?

Dialog form is shown during callback and label shows required information. But if I try to move form with mouse it becomes like frozen like in picture below and information on label is not updated anymore. Why this happens? How to solve this problem?

推荐答案

创建StatusDlg时,将其赋予桌面的父级.这很可能是错误的,并导致您以后出现问题.第二个对话框的父级应该是调用它的主对话框.

When you create StatusDlg you give it a parent of the Desktop. That is very likely wrong and leads to your later issues. The parent of your second dialog should be the main dialog that invokes it.

int userNotify ( CWnd *pParentWnd, int iNotificationType, char* pcNotificationText )
{
...
statusDlg->Create(StatusDlg::IDD, pParentWnd);
...
}

当您调用userNotify时,父窗口指针将只是this指针.

The parent window pointer will simply be the this pointer when you call userNotify.

这篇关于MFC对话框冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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