问题
I'm trying to create ListView with fixed width columns in winapi C++ project.
I try use a trick with handling a HDN_BEGINTRACK notification in Dialog Box Procedure just by returning TRUE in it. As I understood from different articles it might work.
Point is, that I catch it, but returning TRUE does not prevent from resizing.
Also tried returning TRUE just after getting WM_NOTIFY - the same effect.
Help me please. Here are some parts of code:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance;
----
hDlg = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG),
hWnd,(DLGPROC)DlgProc);
INITCOMMONCONTROLSEX icex;
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
HWND hWndListView = CreateWindow(
WC_LISTVIEW,
L"",
WS_CHILD | LVS_REPORT |WS_VISIBLE,
0, 0,
382,
200,
hDlg,
(HMENU)IDC_LIST,
hInst,
NULL);
----
//adding columns and items
----
DWORD exStyle = LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
ListView_SetExtendedListViewStyle(hWndListView,exStyle);
SetWindowTheme(hWndListView, L"Explorer", NULL);
----
return TRUE;
}
BOOL CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
----
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->code)
{
case HDN_BEGINTRACK:
OutputDebugString(L"HDN_BEGINTRACK\n");
return TRUE;
default:
break;
}
----
}
return FALSE;
}
Thanks in advance!
回答1:
Returning TRUE from WM_NOTIFY in a dialog procedure only shows you've processed the message. To actually return a result value, you must also set the dialog's DWL_MSGRESULT
:
case HDN_BEGINTRACK:
OutputDebugString(L"HDN_BEGINTRACK\n");
SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); // prevent resizing
return TRUE; // message processed; check DWL_MSGRESULT for real result
来源:https://stackoverflow.com/questions/13325887/winapi-listview-cant-prevent-columns-from-resizing