I'm upgrading the VC++6.0 32bit MFC application project to VC++2015 to be deployed into windows 7. Following is the method for alignment of the text.
Columns method:
int CListCtrlEx::CreateColumns(LPCSTR fmt, ...)
{
ClearAll();
char* buffer = new char[strlen(fmt) + 256];
va_list args;
va_start (args,fmt);
vsprintf (buffer,fmt,args);
va_end (args);
CStringEx cols = buffer;
int col;
for( col = 0; col < cols.GetFieldCount("|"); col++ )
AddColumn(cols.GetField("|", col), col);
delete [] buffer;
delete [] m_arrayColumnClicks;
m_arrayColumnClicks = NULL;
m_arrayColumnClicks = new int[col];
int i;
for( i = 0; i < col; i++)
m_arrayColumnClicks[i] = 1;
AutoSizeColumns();
return i; }
int CListCtrlEx::AddColumn(LPCSTR desc, int col, LVCOLUMN* lvc)
{
if( lvc && lvc->pszText == NULL )
lvc->pszText = (char*)desc;
LV_COLUMN t_lvc;
t_lvc.mask = lvc ? lvc->mask : LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
t_lvc.fmt = lvc ? lvc->fmt : LVCFMT_LEFT;
t_lvc.cx = lvc ? lvc->cx : 75; t_lvc.pszText = lvc ? lvc->pszText : (char*)desc;
return InsertColumn(col, &t_lvc);
}
void CListCtrlEx::AutoSizeColumns(int col)
{
int mincol = col < 0 ? 0 : col;
int maxcol = GetColumnCount();
for( col = mincol; col < maxcol; col++)
{
SetColumnWidth(col, LVSCW_AUTOSIZE);
int wc1 = GetColumnWidth(col);
SetColumnWidth(col, LVSCW_AUTOSIZE_USEHEADER);
int wc2 = GetColumnWidth(col);
int wc = max(wc1, wc2);
SetColumnWidth(col,wc);
}
Invalidate();
}
The above code works fine with VC++ 6.0 target OS windows xp. But doesn't in VC++2015 target Windows 7.
The worst part is the Debug version and Release version shows different type of alignment errors in column and text.
What I have tried:
It doesn't seems to be an issue with the code.
Is there any CListCtrl associated dll's that doesn't match the recent versions. I have included "legacy_stdio_definitions.lib" as my project mandates ? OR
May be the buffer overflow due to bit size not concurrent with the earlier developed project in the current version ? OR
Any other prerequisites to be done in the settings ?