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

标签 mfc taskdialog

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

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();
}

消息框如下所示:

Task Dialog

上面的屏幕显示使用值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 成员。

关于mfc - 将 CTaskDialog 的宽度设置为屏幕宽度的 50%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55784718/

相关文章:

c++ - MFC中创建子窗口的正确方法是什么?

winapi - 是否可以为 win32 控制台和 MFC GUI 创建 DLL

visual-c++ - 将 CTaskDialog 的主图标设置为问题?

c++ - 没有按钮的任务对话框

wpf - TaskDialog 需要在版本 6 中触发异常 : comctl32. dll

c++ - 让程序每小时在 MFC C++ 中运行某些函数

c++ - 如何将 std::regex_match 与 CString 一起使用?

c++ - 如何将 ATL/MFC CString 转换为 QString?

visual-c++ - 使用 DoMessageBox 将 AfxMessageBox 转换为 CTaskDialog

c# - 在任务对话框中使用隐藏的安全图标