I cannot prevent user from editing labels in ListView

旧时模样 提交于 2020-01-03 06:07:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!