2016-11-16 58 views
1

我有簡單的MFC對話框類型窗口調用外部DLL函數,其中一個參數是回調函數。回調函數創建了另一個對話框如果不創建它,並從功能參數信息更新標籤:MFC對話框窗體凍結

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對話框的形式與一個靜態的標籤。它有一個特點 - 它放在最上面。

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 
    } 

對話窗體在回調期間顯示,標籤顯示所需的信息。但是,如果我嘗試使用鼠標移動窗體,就會像下面的圖片一樣凍結,並且標籤上的信息不再更新。爲什麼會發生?如何解決這個問題呢?

enter image description here

回答

0

當您創建StatusDlg你給它的桌面的父母。這很可能是錯誤的,會導致你後來的問題。你的第二個對話框的父母應該是調用它的主對話框。

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

父窗口指針只會是this指針,當你調用userNotify