Pelles C forum

Pelles C => General discussions => Topic started by: Grincheux on February 11, 2016, 02:54:28 PM

Title: NMCLICK for LISTVIEW in 64 bits
Post by: Grincheux on February 11, 2016, 02:54:28 PM
When a user clicks on a image in a listview icon the program receives through a WM_NOTIFY the message NM_CLICK.
When it arrives the lParam contains a pointer on a NMITEMACTIVATE structure.
Normally The iItem meber of this structure has a value to use with GetItem to retrieve info about clicked item.
In 64 bits (or in pc) the iItem member always is -1.
To resolve this I must send send a LVM_HITTEST. See the code
Quote
LRESULT Left_OnNotify(HWND __hWnd,WPARAM __wParam,LPARAM __lParam)
{
   LVITEM            _Lvi ;
   char            _szTmp[MAX_PATH] ;
   char            _szImg[MAX_PATH] ;
   LPNMITEMACTIVATE   _lpItem ;
   LVHITTESTINFO      _Hit ;

   _lpItem = (LPNMITEMACTIVATE) __lParam ;

   if(_lpItem->hdr.code == NM_CLICK)
   {
      if(_lpItem->hdr.idFrom == 0x2001)
      {
         memset(&_Lvi,0,sizeof(LVITEM)) ;
         memset(_szTmp,0,MAX_PATH) ;

         _Hit.pt.x = _lpItem->ptAction.x ;
         _Hit.pt.y = _lpItem->ptAction.y ;
         _Hit.flags = LVHT_ONITEMICON ;
         _Hit.iItem = 0 ;
         _Lvi.iItem = SendMessage(hListView,LVM_HITTEST,0,(LPARAM) &_Hit) ;
         _Lvi.mask = LVIF_PARAM | LVIF_TEXT ;
         _Lvi.cchTextMax = MAX_PATH ;
         _Lvi.pszText = _szTmp ;

         SendMessage(hListView,LVM_GETITEM,0,(LPARAM) &_Lvi) ;
         if(_Lvi.iItem != -1)
         {
            _Lvi.mask = LVIF_PARAM|LVIF_TEXT ;
            _Lvi.pszText = _szTmp ;
            _Lvi.cchTextMax = MAX_PATH ;

            if(lstrlen(_szTmp))
            {
               wsprintf(_szImg,"%s\\%s",szCurrentPath,_szTmp) ;

               if(PathFileExists(_szImg))
               {
                  lstrcpy(szCurrentFile,_szImg) ;
               }
            }
         }
      }
   }

Is there an other solution. This one works very well but I am suprised about -1.
Title: Re: NMCLICK for LISTVIEW in 64 bits
Post by: Grincheux on February 21, 2016, 04:59:02 AM
Thanks for your answers. They help me a lot.