Ejemplo n.º 1
0
        private void SetFileNameToSelectedItem(IntPtr hListView, IntPtr hFNCombo, int selectedIndex)
        {
            if (selectedIndex >= 0)
            {
                var lvitem = new InteropUtil.LVITEM();
                lvitem.mask = InteropUtil.LVIF_TEXT;
                var nativeBuffer = Marshal.AllocCoTaskMem(InteropUtil.NumberOfFileChars * 2);
                for (int i = 0; i < InteropUtil.NumberOfFileChars; ++i)
                {
                    Marshal.WriteInt16(nativeBuffer, i * 2, '\0');
                }
                string name;

                try
                {
                    Marshal.WriteInt16(nativeBuffer, 0);
                    lvitem.pszText    = nativeBuffer;
                    lvitem.cchTextMax = InteropUtil.NumberOfFileChars;
                    var length = hListView.SendListViewMessage(InteropUtil.LVM_GETITEMTEXT, (uint)selectedIndex, ref lvitem);
                    name = Marshal.PtrToStringUni(lvitem.pszText, (int)length);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(nativeBuffer);
                }

                if (name != null && m_currentFolder != null)
                {
                    try
                    {
                        var path = System.IO.Path.Combine(m_currentFolder, name);
                        if (Directory.Exists(path))
                        {
                            hFNCombo.SetWindowTextW(name);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
    private void SetFileNameToSelectedItem(IntPtr hListView, IntPtr hFNCombo, int selectedIndex)
    {
      if (selectedIndex >= 0)
      {
        var lvitem = new InteropUtil.LVITEM();
        lvitem.mask = InteropUtil.LVIF_TEXT;
        var nativeBuffer = Marshal.AllocCoTaskMem(InteropUtil.NumberOfFileChars * 2);
        for (int i = 0; i < InteropUtil.NumberOfFileChars; ++i)
        {
          Marshal.WriteInt16(nativeBuffer, i * 2, '\0');
        }
        string name;

        try
        {
          Marshal.WriteInt16(nativeBuffer, 0);
          lvitem.pszText = nativeBuffer;
          lvitem.cchTextMax = InteropUtil.NumberOfFileChars;
          var length = hListView.SendListViewMessage(InteropUtil.LVM_GETITEMTEXT, (uint)selectedIndex, ref lvitem);
          name = Marshal.PtrToStringUni(lvitem.pszText, (int)length);
        }
        finally
        {
          Marshal.FreeCoTaskMem(nativeBuffer);
        }

        if (name != null && m_currentFolder != null)
        {
          try
          {
            var path = System.IO.Path.Combine(m_currentFolder, name);
            if (Directory.Exists(path))
            {
              hFNCombo.SetWindowTextW(name);
            }
          }
          catch (Exception)
          {
          }

        }
      }
    }