La casilla de verificación eliminada vuelve a aparecer en el nodo de vista de árbol cuando se presiona la barra espaciadora

He usado la solución aceptadade esta pregunta para eliminarcaja a partir de unanodo de vista de árbol en miWM_INITDIALOG manipulador.

Al cargar,árbol Tiene un aspecto adecuado. Después de seleccionar el nodo y hacer clic en el lugar dondecaja sería, no pasa nadacaja no aparece) cuál es el comportamiento correcto.

Sin embargo, si selecciono el nodoy presione barra espaciadora elcaja se agrega automáticamente al nodo.

Aquí está elWM_INITDIALOG controlador que ilustra el problema:

case WM_INITDIALOG:
    {
        // get treeview handle

        HWND TreeView = GetDlgItem( hDlg, IDC_TREE1 );

        /************ enable checkboxes **************/

        DWORD dwStyle = GetWindowLong( TreeView , GWL_STYLE);
        dwStyle |= TVS_CHECKBOXES;
        SetWindowLongPtr( TreeView , GWL_STYLE, dwStyle );

        /************ add items and subitems **********/

        // add root item

        TVINSERTSTRUCT tvis = {0};

        tvis.item.mask = TVIF_TEXT;
        tvis.item.pszText = L"This is root item";
        tvis.hInsertAfter = TVI_LAST;
        tvis.hParent = TVI_ROOT;

        HTREEITEM hRootItem = reinterpret_cast<HTREEITEM>( SendMessage( TreeView ,
            TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );

        // and here is an example of removing a checkbox 

        TVITEM tvi;
        tvi.hItem = hRootItem ;
        tvi.mask = TVIF_STATE;
        tvi.stateMask = TVIS_STATEIMAGEMASK;
        tvi.state = 0;
        TreeView_SetItem( TreeView, &tvi );

        // add firts subitem for the hTreeItem

        memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );

        tvis.item.mask = TVIF_TEXT;
        tvis.item.pszText = L"This is first subitem";
        tvis.hInsertAfter = TVI_LAST;
        tvis.hParent = hRootItem;

        HTREEITEM hTreeSubItem1 = reinterpret_cast<HTREEITEM>( SendMessage( TreeView ,
            TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );

        // now we insert second subitem for hRootItem

        memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );

        tvis.item.mask = TVIF_TEXT | TVIF_STATE; // added extra flag
        tvis.item.pszText = L"This is second subitem";
        tvis.hInsertAfter = TVI_LAST;
        tvis.hParent = hRootItem;

        HTREEITEM hTreeSubItem2 = reinterpret_cast<HTREEITEM>( SendMessage( TreeView , 
            TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );
    }
    return (INT_PTR)TRUE;  

aquí Es una cita interesante de MSDN:

Versión 5.80. Muestra una casilla de verificaciónincluso si no hay imagen asociada con el elemento.

Tal vez esta es la causa de mi problema?

He intentado manejarTVN_KEYDOWN y establecer elementos estado o de nuevo eliminando elcaja Pero no tuvo éxito.

EDITAR # 2:

He subclasificado el árbol, como miembroJonathan Potter sugerido, y funcionó:

LRESULT CALLBACK TreeProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, 
    UINT_PTR uIdSubclass, DWORD_PTR dwRefData )
{
    switch (message)
    {
    case WM_KEYDOWN:
        {
            // reject spacebar if tree node doesn't have checkbox
            if( wParam == VK_SPACE ) 
            {
                HTREEITEM ht = TreeView_GetSelection( hwnd );

                TVITEM tvItem;

                // Prepare to receive the desired information.
                tvItem.mask = TVIF_HANDLE | TVIF_STATE;
                tvItem.hItem = (HTREEITEM)ht;
                tvItem.stateMask = TVIS_STATEIMAGEMASK;

                // Request the information.
                TreeView_GetItem( hwnd, &tvItem );

                // reject if it's not checked, or pass default value otherwise
                switch( tvItem.state >> 12 )
                {
                    case 0:
                        MessageBeep(0);
                        return FALSE;
                        break;
                    case 1:
                    case 2:
                    default:
                        return ::DefSubclassProc( hwnd, message, wParam, lParam );
                        break;
                }               
            }
        }
        break;
    case WM_NCDESTROY:
        ::RemoveWindowSubclass( hwnd, TreeProc, 0 );
        break;
    }
    return ::DefSubclassProc( hwnd, message, wParam, lParam);
}
FIN DE EDITARPREGUNTA:

¿Cómo puedo eliminar adecuadamentecaja a partir de unanodo de árbol para que nunca vuelva a aparecer ?

Gracias.

Atentamente.

Respuestas a la pregunta(1)

Su respuesta a la pregunta