MFC class CTreeView is not receiving selection change event when clicking in navigation pane

semicode 40 Reputation points
2024-10-24T02:44:35.8966667+00:00

The new project wizard can create an MFC project that behaves like the Windows File Explorer. The navigation pane that allows the user to navigate through the file system is based on an MFC class called CTreeView which hosts a CTreeCtrl. The class wizard allows the user to create a message handler for the TVN_SELCHANGED message. When the user changes the selection in the navigation pane, the handler is not being called.

I have duplicated the issue in VS2015, VS2017, and VS2019. Is this a bug or am I not understanding how to use the CTreeView class?

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2024-10-24T03:21:41.82+00:00

    Hi, @semicode

    navigation pane is CMFCShellTreeCtrl.

    Generated by project wizard: VS 2022

    User's image

    You need to create MFC class that inherits from CMFCShellTreeCtrl.
    And add TVN_SELCHANGED from class wizard.

    Then replace the CMFCShellTreeCtrl m_wndTree (MainFrm.h) with Your class m_wndTree;

    User's image

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2024-10-24T02:44:35.9+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The issue you're experiencing with the CTreeView class not receiving the TVN_SELCHANGED message when clicking in the navigation pane could be due to how the selection change notifications are handled. The CTreeCtrl sends TVN_SELCHANGING and TVN_SELCHANGED notifications when the selection changes, but if the selection is not being detected, it may be related to the way the message handlers are set up or how the tree control is configured.

    Ensure that your message handler for TVN_SELCHANGED is correctly implemented and that the control is properly set to receive these notifications. If the handler is not being called, double-check that the control is correctly associated with the message map and that the notifications are not being filtered out or overridden by other handlers.

    If you've confirmed that everything is set up correctly and the issue persists across multiple versions of Visual Studio, it may be worth investigating if there are any known issues or bugs related to CTreeView in those specific versions.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.