问题
According to msdn, http://msdn.microsoft.com/en-us/library/bb774798%28VS.85%29.aspx, returning TRUE prevents user from editing labels.
So I wrote the code below: Main:
WinMain(...)
{
DialogBox(..., DlgProc)
}
DlgProc:
DlgProc(...)
{
switch(message) {
case WM_NOTIFY:
if((NMHDR *)lParam->code == LVN_BEGINLABELEDIT) {
return TRUE;
return FALSE;
...
}
Still, the labels can be edited. I dont want to cancel the style LVS_EDITLABELS, because sometimes I would like to allow the users edit labels.
Does anyone know the problem? Thank you.
回答1:
Returning TRUE from a DialogProc() doesn't mean what you think it does. Quoting from the MSDN library article:
Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.
If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result in the DWL_MSGRESULT value being overwritten by a nested dialog box message.
来源:https://stackoverflow.com/questions/6909056/i-cannot-prevent-user-from-editing-labels-in-listview