I use the LVCFMT_FIXED_WIDTH style to prevent user columns sizing.
m_ListCtrl.InsertColumn(0, _gszColumnLabel[0], _gnColumnFmt[0], LVCFMT_FIXED_WIDTH, _gnColumnWidth[0], -1);
What I have discovered only by hasard, this works in Unicode, but not in NON Unicode applications. The user can still sizing the columns.
I think this has to do with the default Windows.Common-Controls manifest skeleton in stdafx.h
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
Unfortuntely there is no default settings for NON Unicode application.
If I use the same manifest for NON Unicode appliction too, it works again.
But I am out sure, if this is the right solution? Can we use the same Windows.Common-Controls mainifest for Unicode andn NON Unicode applications?
LVCFMT_FIXED_WIDTH
requires CommCtrl v6, which is most easily enabled via manifest. But CommCtrl v6 is not limited to just Unicode windows, as you discovered (I use CommCtrl v6 in several legacy apps using ANSI windows, and it works fine), so why Microsoft limits the #pragma
's to just Unicode builds, I do not know.
However, using CommCtrl v6 is not the only way to lock the columns from resizing. Another option is to subclass the ListView itself (not its parent window!) to handle the HDN_BEGINTRACK
notification, returning TRUE to block resizing.