0

概述:
我有 2 个实用程序,它们都有相同的通用界面,即打开一个对话框来“请求用户名”。
“请求用户名”的代码写在不同的库中,这两个实用程序都调用该库。

问题:

在 1 个实用程序中它工作正常,我得到了这个对话框,它请求用户名,但在其他实用程序中它没有出现。

我的调查: 在更深入的调查中,我发现这两个实用程序都调用 CDialog::DoModal() ,而后者又调用 onCreate() 。在我的其他实用程序断点中,永远不会命中 onCreate 函数。知道为什么吗?

示例代码

// IN actual Utility
//somewhere in code 

Dialog_for_common_interface dlg( message.c_str(), "Please enter username:" );

        CString username;

        bool is_correct = ( dlg.DoModal(username) == IDOK )

// IN Dialog_for_common_interface

int  Dialog_for_common_interface::DoModal ( CString &_reply_c )
{
    int result_i = CDialog::DoModal(); // break point hits this but value of result_i = -1;

    if ( result_i == IDOK )
    {
        _reply_c = reply_c;
    }

    return result_i;
}

// Breakpoint nver hits the below function

int Dialog_for_common_interface::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

    SetWindowText( title_c );

    return 0;
}
4

1 回答 1

0

将对话框资源复制到两个 exe 项目中。并确保它们都对对话资源使用相同的 ID 值。

于 2014-07-11T15:07:09.887 回答