In the following code, all works well. But the width of the text obtained by GetTextExtent seems to be more that the actual text width.

Any reason for this?


BOOL CWarnListDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
CClientDC dc(this);
int n, nTextWidth, nMaxTextWidth = 0;

for(n = 0; n < m_ErrorList.GetSize(); n++)
{
m_WarnList.AddString(m_ErrorList[n]);
nTextWidth = dc.GetTextExtent(m_ErrorList[n]).cx;

if(nTextWidth > nMaxTextWidth)
nMaxTextWidth = nTextWidth;
}

// set horizontal bar extent
m_WarnList.SetHorizontalExtent(nMaxTextWidth);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}




Hope you can help.