Hello, i am new in WTL, i dont understand how to reseive messages on CListViewCtrl

I create .rc file where put my DialogBar. In section of this DialogBar i create CListViewCtrl.And fill it. Then i need to receive messages on SelectedItem. Please, give me some code, or links to read about my problem. Thank you. Here is my code of DialogBar, where i calling the function to create CListViewCtrl

#include <thread>

#include "resource.h"
#include "resource2.h"
#include "MyListView.h"

class MyDialogBar:public CDialogImpl<MyDialogBar>
{
public:
    enum { IDD = IDD_MYDIALOGBAR };


    BEGIN_MSG_MAP(MyDialogBar)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_COMMAND,OnCommand)
        MESSAGE_HANDLER(WM_NOTIFY,OnLButtonDown)
        MESSAGE_HANDLER(WM_CLOSE,OnCloseCmd)
    END_MSG_MAP()

    LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        CString parameter = TEXT("C:\Users\Огурчик\Desktop\");
        switch (wParam)
        {
        case IDC_BUTTON_EXIT:
            OnCloseCmd(uMsg,wParam,lParam,bHandled);
            return 0;
        case IDC_BUTTON_APPLY:
            ListView_DeleteAllItems(this->myListView.m_hWnd);
            if (FindThread.joinable())
            {
                FindThread.detach();
                FindThread = std::thread((&MyListView::FindFile),this->myListView, parameter);
            }
            else
            {
                FindThread = std::thread((&MyListView::FindFile), this->myListView, parameter);
            }
            return 0;
        case IDC_SEARCH_TEXT_BAR :
            GetDlgItemText(IDC_SEARCH_TEXT_BAR, FileName);
            return 0;
        case IDC_EXTENTION_TEXT_BAR:
            GetDlgItemText(IDC_EXTENTION_TEXT_BAR, FileExtention);
            return 0;
        }
        return 0;
    }
    
    LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        
        switch (LOWORD(wParam))
        {
        case (int)LVN_ITEMCHANGED:
            MessageBox(TEXT("U am here"), TEXT("Here"), NULL);
        }
        return 0;
    }
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
        myListView.Create(m_hWnd);
        return 0;
    }

    LRESULT OnCloseCmd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
        if (FindThread.joinable())
        {
            FindThread.detach();
        }
        EndDialog(NULL);
        return 0;
    }

    
private:
    CString FileName;
    CString FileExtention;
    MyListView myListView;
    std::thread FindThread;
};

//code of CListViewCtrl
#pragma once
#include <atlbase.h>
#include <atlapp.h>
#include <atlmisc.h>
#include <atlwin.h>
#include <atlctrls.h>
#include <atlfile.h>
#include <atlstr.h>



class MyListView:public CListViewCtrl
{
private:
    LVITEM lvItem;
    CListViewCtrl myListView; 
    CString path;
    int i;
public:

    void Create(HWND m_hWnd);
    void FindFile(CString szPath);
    void View_List(CString buf, int i,CString path);
    BOOL InitListViewImage(int size, CString path);
};

Answer

    LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        
        switch (LOWORD(wParam))
        {
        case (int)LVN_ITEMCHANGED:
            MessageBox(TEXT("U am here"), TEXT("Here"), NULL);
        }
        return 0;
    }

This looks wrong.

WM_NOTIFY handler should use lParam and cast it to NMHDR structure, and shouldn’t use wParam. See docs:

wParam

The identifier of the common control sending the message. This identifier is not guaranteed to be unique. An application should use the hwndFrom or idFrom member of the NMHDR structure (passed as the lParam parameter) to identify the control.

lParam

A pointer to an NMHDR structure that contains the notification code and additional information. For some notification messages, this parameter points to a larger structure that has the NMHDR structure as its first member.

You’d better use NOTIFY_HANDLER macro instead of MESSAGE_HANDLER macro.

WTL has even better message crackers in <atlcrack.h> header, you need NOTIFY_HANDLER_EX from there.