改变通用控件的工作方式并不是一个好主意,因为用户希望它们像在所有其他应用程序中一样运行。
ListView (CListCtrl) 不支持此功能,但如果您不关心进行非拖动选择,您可以对控件进行子类化并排序使其工作:
WNDPROC g_OrgWndProc = 0;
static LRESULT CALLBACK LVSubClass(HWND hWnd, UINT Msg, WPARAM wp, LPARAM lp)
{
if (Msg == WM_LBUTTONDOWN)
{
UINT oldexstyle = (UINT) ListView_SetExtendedListViewStyleEx(hWnd, LVS_EX_FULLROWSELECT, 0);
LRESULT oldcolw = ListView_GetColumnWidth(hWnd, 0);
ListView_SetColumnWidth(hWnd, 0, 0);
PostMessage(hWnd, WM_APP, oldexstyle, oldcolw); // Restore delay
return CallWindowProc(g_OrgWndProc, hWnd, Msg, wp, lp);
}
if (Msg == WM_APP)
{
ListView_SetExtendedListViewStyleEx(hWnd, LVS_EX_FULLROWSELECT, (UINT) wp);
ListView_SetColumnWidth(hWnd, 0, (UINT) lp);
}
return CallWindowProc(g_OrgWndProc, hWnd, Msg, wp, lp);
}
...
g_OrgWndProc = (WNDPROC) SetWindowLongPtr(listviewhandle, GWLP_WNDPROC, (LONG_PTR) LVSubClass);
This code removes the full-row-select style and makes the first column "invisible" when the listview handles the initial mouse down message so that the internal listview hit-testing returns LVHT_NOWHERE and marquee-selection can start. You should consider this to be a ugly hack and I would recommend that you only intercept WM_LBUTTONDOWN
when Control or Shift is down...