I am having problems setting the width. This is my code:

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

This is what the message box looks like:

Task Dialog

The above screen show was using the value 300. Originally i was trying to use:

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

It did not like it and was nearly as wide as the screen. If I used 500 then it looked like it was nearly 50% of the screen. Yet my screen is just under 2000 pixels wide.

The help documentation states the parameter is pixels so why is my code now showing the message box at 50% of the screen width (if I enable my code)?

1 Answers

3
zett42 On Best Solutions

Looks like the MFC documentation is wrong. This is what the Win32 documentation says about 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.

The Win32 documentation applies, because CTaskDialog::SetDialogWidth() effectively just sets the TASKDIALOGCONFIG::cxWidth member.