Menu

Using LVS_EDITLABELS aborts dialog immediately

Help
2017-01-03
2017-01-06
  • TorstenEschner

    TorstenEschner - 2017-01-03

    Hi David,

    I've a problem again, this time with a listview and style LVS_EDITLABELS. If I use a listview inside a dialog with the LVS_EDITLABELS Flag, the edit appear, but if I put one char inside the edit control, the dialog aborts immediately with the OnOK handler. If I add handlers for LVN_BEGINLABELEDIT and LVNENDLABELEDIT, the BEGIN is called, all is fine, after putting one (or here sometimes two chars) into the edit, the END is called also immediately and contains a null pointer to the text in the DISPINFO.

    To reproduce my problem I have changed your "Dialog" sample in the following way:

    Replace inside the Resource.rc:

    //LISTBOX         IDC_LIST1,120,23,84,35,LBS_SORT | LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_TABSTOP,WS_EX_STATICEDGE
    

    with

    CONTROL         "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_EDITLABELS | WS_BORDER | WS_TABSTOP,120,23,84,45
    

    Add to class in MyDialog.h:

    CListView m_listview;
    

    Changes in MyDialog.cpp in OnInitDialog:

    // Put some text in the list box
    //for (int i = 0 ; i < 8 ; i++)
    //  SendDlgItemMessage(IDC_LIST1, LB_ADDSTRING, 0, (LPARAM) _T("List Box"));
    
    
    AttachItem(IDC_LIST1, m_listview);
    
    LV_COLUMN lvColumn = { 0 };
    lvColumn.mask    = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
    lvColumn.fmt     = LVCFMT_LEFT;
    lvColumn.cx      = 100;
    lvColumn.pszText = _T("Column");
    
    m_listview.InsertColumn (0, lvColumn);
    
    LVITEM lvi  = {0};
    lvi.mask    = LVIF_TEXT;
    lvi.iItem   = 0;
    lvi.pszText = _T("HELLO");
    
    m_listview.InsertItem(lvi);
    
    • Compile and press left mouse twice (no doubleclick) on HELLO to change to edit mode.
    • Put a char into the edit.
    • OnOK appears

    For me, this seems not ok, in a greater application this is the reason for aborting the dialog. If I do it in the same way in a simple real MFC app, this app works fine.

     
  • TorstenEschner

    TorstenEschner - 2017-01-03

    Further analysis say, that the problem is in wxx_dialog.h

    The standard EDIT inside the LISTVIEW has the id 1, same as IDOK, but in the HIWORD of wParam is EN_CHANGE and not BN_CLICKED like clicking on buttons. Masking this out, the problem disappears.

    case WM_COMMAND:
                switch (LOWORD (wParam))
                {
                case IDOK:
                    OnOK();
                    return TRUE;
    
     
  • TorstenEschner

    TorstenEschner - 2017-01-03

    I played a little bit with the workaround and found no further problems, here my proposal

      case WM_COMMAND:
        if (HIWORD (wParam) == BN_CLICKED)
        {
          switch (LOWORD (wParam))
          {
            case IDOK:
              OnOK();
              return TRUE;
            case IDCANCEL:
              OnCancel();
              return TRUE;
        }
      }
    
      {
        // Reflect this message if it's from a control
        CWnd* pWnd = GetCWndPtr(reinterpret_cast<HWND>(lParam));
        if (pWnd != NULL)
          lr = pWnd->OnCommand(wParam, lParam);
    
        // Handle user commands
        if (!lr)
          lr =  OnCommand(wParam, lParam);
    
        if (lr) return 0L;
      }
      break;  // Some commands require default processing
    
     
  • David

    David - 2017-01-06

    Hi Torsten,

    Thanks for identifying this issue and describing it so clearly.

    I've incorporated the fix you've suggested and posted the updated code to SourceForge. You can download the latest Win32++ code by going to the Code section and downloading the Snapshot.

    If you download the latest code, be sure to check the changes.txt file in the include directory.

    Best regards,
    David

     

Log in to post a comment.

MongoDB Logo MongoDB