LVM_?????
系列消息。
应该可以得到。

解决方案 »

  1.   

    使用消息LVM_????,下面例子是一个Mouse Hook,用来得到用户在资源管理中实时选中的文件,不过是C++Builder代码的:----------------------------------------------LRESULT CALLBACK MouseHook(int nCode,WPARAM wParam,LPARAM lParam)
    {
      if(nCode<0) return CallNextHookEx(MouseHookID,nCode,wParam,lParam);  if(HookWindowHandle==NULL)
      {
        HookWindowHandle=FindWindow(HookClassName.c_str(),NULL);
        AppWindow=GetWindow(HookWindowHandle,GW_OWNER);
      }  if((int)wParam != WM_LBUTTONUP) return 0;  MOUSEHOOKSTRUCT *mst=(MOUSEHOOKSTRUCT*)lParam;  //*/
      HWND hLV;
      TPoint P;
      char Buf[64];  P.x = mst->pt.x;
      P.y = mst->pt.y;  hLV = WindowFromPoint(P);  ZeroMemory(Buf,64);
      GetClassName(hLV,Buf,64);
      
      if(AnsiString(Buf) == "SysListView32")
      {
        LV_ITEM Item;
        int ItemCount;
    //    char *SelFileNameBuf=new char[64];
        char SelFileNameBuf[64];    ItemCount = ListView_GetItemCount(hLV);    if(ItemCount > 0)
        {
          AnsiString S;      bool IsSuc = false;      for(int i=0; i < ItemCount; i++)
          {
            ZeroMemory(SelFileNameBuf,64);        Item.iItem=i;
            Item.iSubItem=0;
            Item.mask = LVIF_TEXT | LVIF_STATE;
            Item.stateMask = LVIS_FOCUSED;
            //Item.state = -1;
            Item.pszText = SelFileNameBuf;
            Item.cchTextMax = 64;        if(ListView_GetItemState(hLV,i,LVIS_FOCUSED) != LVIS_FOCUSED)
            {
              //SendMessage(HookWindowHandle,WM_SETTEXT,0,(LPARAM)AnsiString("Error Query State="+IntToStr(i)).c_str());
              continue;
            }        if(ListView_GetItem(hLV,&Item))
    //        ListView_GetItemText(hLV,i,0,SelFileNameBuf,64);
            {
              if(Item.state & LVIS_FOCUSED == LVIS_FOCUSED)
              {
                // Get Folder first
                HWND hTemp;
                AnsiString CurrentFolder;            //*/
                hTemp = FindWindow("ExploreWClass",NULL);
                hTemp = FindWindowEx(hTemp,0,"WorkerW",NULL);
                hTemp = FindWindowEx(hTemp,0,"ReBarWindow32",NULL);
                hTemp = FindWindowEx(hTemp,0,"ComboBoxEx32",NULL);
                hTemp = FindWindowEx(hTemp,0,"ComboBox",NULL);
                hTemp = FindWindowEx(hTemp,0,"Edit",NULL);            if(hTemp != NULL)
                {
                  char ClassBuf[32];              ZeroMemory(ClassBuf,sizeof(ClassBuf));
                  GetClassName(hTemp,ClassBuf,sizeof(ClassBuf));              if(AnsiString(ClassBuf) == "Edit")
                  {
                    char FolderBuf[128];                ZeroMemory(FolderBuf,sizeof(FolderBuf));
                    GetWindowText(hTemp,FolderBuf,sizeof(FolderBuf));
                    CurrentFolder = AnsiString(FolderBuf);                if(CurrentFolder[CurrentFolder.Length()] != '\\')
                      CurrentFolder += "\\";
                  }
                }
                //*/            IsSuc = true;
                SendMessage(HookWindowHandle,WM_SETTEXT,0,(LPARAM)AnsiString("Index="+IntToStr(i)+" Select Filename="+AnsiString(CurrentFolder + SelFileNameBuf)).c_str());
                break;
              }
              else S=S + ",Index=" + IntToStr(i) + " State="+IntToStr(Item.state) + " FN=" + AnsiString(SelFileNameBuf);
            }
            //else S=S + "," + IntToStr(i) +" Err="+SysErrorMessage(GetLastError());//SendMessage(HookWindowHandle,WM_SETTEXT,0,(LPARAM)AnsiString("Error GetItem="+IntToStr(i)).c_str());
          }
          if(!IsSuc)
            SendMessage(HookWindowHandle,WM_SETTEXT,0,(LPARAM)AnsiString("Error GetItem="+S).c_str());
        }
      }  return 0;
    }