Author Topic: Get all items and select some of them  (Read 32594 times)

ice-man

  • Active Member
  • ***
  • Posts: 56
  • The Little Extra
    • View Profile
Get all items and select some of them
« on: July 21, 2013, 13:33:36 »
I been playing around a bit with the SDK.

In one of the sample plugins you have an example on how to get all selected items.

But if I want to get all items and then set some of them as selected. How do I do that ?


Intel i7-6700K - Running on latest Windows 10 64bit Insider Preview

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4449
    • View Profile
    • Multi Commander
Re: Get all items and select some of them
« Reply #1 on: July 21, 2013, 13:54:25 »
Use the AM_GETFILESITEMS and AM_SELECTFILEITEMS message

This code will get all items in the current source view and then select every second item.

Quote
IFileItemCollection* pFileItems = m_pAppInterface->CreateFileItemCollection();
IFileItemCollection* pFileItemsSelected = m_pAppInterface->CreateFileItemCollection();
m_pAppInterface->SendMessageToSource( AM_GETFILEITEMS, (WPARAM)pFileItems, MF_ALL);
 
 DWORD nCount = pFileItems->Count();
 for(DWORD n = 0; n < nCount; ++n)
 {
   IFileItem* pItem = pFileItems->GetAt(n);
   if(pItem && n % 2)
  {
     pFileItemsSelected->Add(pItem);
   }
 }

 m_pAppInterface->SendMessageToSource( AM_SELECTFILEITEMS, (WPARAM)pFileItemsSelected, 1); // 0 for Unselect, 1 for Select
 pFileItemsSelected->Release();
 pFileItems->Release();
(Will add this to the SDK Sample project)