You are not subclassing the ListView correctly or processing its messages correctly. Try this instead.
Header file:
WNDPROC PrevPresLVWndProc;
BOOL WINAPI Present_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL Present_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
...
LRESULT CALLBACK PresListView_OnNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Source file:
BOOL WINAPI Present_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch( uMsg )
{
HANDLE_MSG(hwnd, WM_INITDIALOG, Present_OnInitDialog);
...
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
BOOL Present_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
...
hPresList = GetDlgItem(hwnd, IDC_LIST_PRESLIST); // Create ListView from resource
...
PrevPresLVWndProc = (WNDPROC) GetWindowLongPtr(hPresList, GWL_WNDPROC);
SetWindowLongPtr(hPresList, GWL_WNDPROC, (LONG_PTR)&PresListView_OnNotify);
...
return FALSE;
}
LRESULT CALLBACK PresListView_OnNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if( uMsg == WM_NOTIFY )
{
switch( ((NMHDR*)lParam)->code )
{
case HDN_BEGINTRACKA:
case HDN_BEGINTRACKW:
case HDN_DIVIDERDBLCLICKA:
case HDN_DIVIDERDBLCLICKW:
{
LPNMHEADER pNMHdr = (LPNMHEADER)lParam;
if( ListView_GetColumnWidth(hwnd, pNMHdr->iItem) == 0 )
return TRUE;
break;
}
}
}
return CallWindowProc(PrevPresLVWndProc, hwnd, uMsg, wParam, lParam);
}
With that said, you really should be using SetWindowSubClass()
instead:
Header file:
BOOL WINAPI Present_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL Present_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
...
LRESULT CALLBACK PresListView_OnNotify(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
Source file:
BOOL WINAPI Present_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch( uMsg )
{
HANDLE_MSG(hwnd, WM_INITDIALOG, Present_OnInitDialog);
...
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
BOOL Present_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
...
hPresList = GetDlgItem(hwnd, IDC_LIST_PRESLIST); // Create ListView from resource
...
SetWindowSubclass(hPresList, &PresListView_OnNotify, 1, 0);
...
return FALSE;
}
LRESULT CALLBACK PresListView_OnNotify(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
if( uMsg == WM_NOTIFY )
{
switch( ((NMHDR*)lParam)->code )
{
case HDN_BEGINTRACKA:
case HDN_BEGINTRACKW:
case HDN_DIVIDERDBLCLICKA:
case HDN_DIVIDERDBLCLICKW:
{
LPNMHEADER pNMHdr = (LPNMHEADER)lParam;
if( ListView_GetColumnWidth(hwnd, pNMHdr->iItem) == 0 )
return TRUE;
break;
}
}
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
If you really need to support Windows 2000 and/or earlier, you should dynamically load SetWindowSubClass()
via GetProcAddress()
so you can use it when available, and fallback to SetWindowLong()
when not available.