将 CTaskDialog 的宽度设置为屏幕宽度的 50%

Setting width of CTaskDialog to 50% of screen width

我在设置宽度时遇到问题。这是我的代码:

void CWin32FileError::DisplayExceptionMessage()
{
    CString strContent = _T(""); // Default shouldn't happen

    if (!m_strErrorFile1.IsEmpty() && !m_strErrorFile2.IsEmpty())
    {
        strContent.Format(_T("Source file: %s\nTarget file: %s"),
            (LPCTSTR)m_strErrorFile1, (LPCTSTR)m_strErrorFile2);

    }
    else
    {
        strContent.Format(_T("File: %s"), (LPCTSTR)m_strErrorFile1);
    }

    CTaskDialog dlgTaskError(strContent, Description(), _T("Exception"), TDCBF_OK_BUTTON);
    dlgTaskError.SetWindowTitle(_T("Exception"));
    dlgTaskError.SetMainIcon(TD_ERROR_ICON);
    dlgTaskError.SetFooterIcon(TD_INFORMATION_ICON);
    dlgTaskError.SetFooterText(m_strActionDescription);

    //dlgTaskError.SetDialogWidth(::GetSystemMetrics(SM_CXSCREEN) / 2);
    dlgTaskError.SetDialogWidth(300);

    dlgTaskError.DoModal();
}

消息框是这样的:

上面的屏幕显示使用值 300。最初我试图使用:

dlgTaskError.SetDialogWidth(::GetSystemMetrics(SM_CXSCREEN) / 2);

不喜欢,几乎和屏幕一样宽。如果我使用 500,那么它看起来几乎占了屏幕的 50%。然而我的屏幕只有不到 2000 像素宽。

帮助文档指出该参数是像素,那么为什么我的代码现在在屏幕宽度的 50% 处显示消息框(如果我启用我的代码)?

看起来 MFC 文档有误。这就是 Win32 documentation 关于 TASKDIALOGCONFIG::cxWidth 的说法:

The width of the task dialog's client area, in dialog units. If 0, the task dialog manager will calculate the ideal width.

适用 Win32 文档,因为 CTaskDialog::SetDialogWidth() 实际上只是设置了 TASKDIALOGCONFIG::cxWidth 成员。