如何在MFC(VC ++)中区分文件夹类型(Windows/FTP)? [英] how to differentiate a Folder Type(Windows/FTP) in MFC(VC++)?

查看:115
本文介绍了如何在MFC(VC ++)中区分文件夹类型(Windows/FTP)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MFC(VC ++)中区分文件夹类型(Windows/FTP)? 在我的情况下,我有一个MFC Treeview,其中我要添加来自服务器的文件夹列表,这些文件夹是Windows和CIFS.现在我想在内部区分它们是什么类型的文件夹,因为我选择了一些文件夹并说"connect"(连接)然后带来了上登录页面,我需要在其中登录凭据详细信息,但是在此之前,我需要区分那是什么类型的文件夹?

how to differentiate a Folder Type(Windows/FTP) in MFC(VC++)? In my case I have a MFC Treeview in which i am adding list of folders coming from server , that folders are Windows and CIFS .Now i want to differentiate internally what type of folder are they because i select some folder and say connect then it brings up login page where i need to login credentials details , but before that i need to differentiate what type of folder is that ?

任何treeview属性,例如设置和geeting键或任何其他方法. 预先感谢.

Any treeview property like setting and geeting key or any other approach. Thanks in Advance.

我从服务器以以下格式获取文件夹列表:volume1/Folder1,volume2/Folder2 || Folder3,Folder4在这种以下方法中,我正在删除"||"并将它们保存在两个不同的变量中:strDataFolder包含-FTP文件夹和 strNASfolders包含CIFS文件夹,那么我正在使用UpdateFolder的另一种方法.如果是FTP,则直接添加,但是如果CIFS检查该文件夹是否存在重复,则不要再次将其添加到treeview.

I get folder list from server in this format volume1/Folder1,volume2/Folder2||Folder3,Folder4 in this below method i am removing "||" and maintaining them in two differnt variables: strDataFolder contains - FTP Folders and strNASfolders conatins CIFS folder , then one more method i am using UpdateFolder. If it is FTP then directly Add but if it CIFS check for duplication if that folder is already there dont add it again to treeview.

现在,我无法获取如何区分它们是哪种类型的文件夹?

Now iam not able to get it how to differentiate what type of folder are they ?

void CNDSClientDlg::UpdateSharedFolder(CString strNASfolders,HTREEITEM hChildItem)
{
    CString strDataFolder = "";
    CString strData = "";       

    int iPos = 0;
    int fPosition = 0;

    fPosition = strNASfolders.Find("||");           
    if(fPosition != -1)
    {
        strDataFolder = strNASfolders.Mid(0,fPosition);
        strNASfolders = strNASfolders.Right(strNASfolders.GetLength()-(fPosition+2));   

    }
    else
    {
       strDataFolder = strNASfolders;
    }

    if (strDataFolder != "" )
    {
         UpdateFolders(strDataFolder,hChildItem,false);

    }
    if (strNASfolders != "" )        //don't add if already exist
    {
        UpdateFolders(strNASfolders,hChildItem,true);
    }

}

void CNDSClientDlg::UpdateFolders(CString strFolderType,HTREEITEM hChildItem,bool bCheck)
{
        int iPos = 0 ;      
        CString strData = "";
        CString strCurrFolder ="";
        HTREEITEM HShareFolder = NULL;
        bool bFound = false ;
        while (iPos != -1)
        {
            iPos = strFolderType.Find(","); 



        if (iPos != -1)
        {               
             strData = strFolderType.Mid(0,iPos);//get the folder details
        }
        else
        {
            strData = strFolderType;//get the last folder details
        }

        strFolderType = strFolderType.Right(strFolderType.GetLength()-(iPos+1)); //get remaining data
        int fPos = strData.ReverseFind('/');
        if (fPos != -1)
        {
            strCurrFolder = strData.Mid(fPos+1,strData.GetLength());    // get required data                                

        }
        else
        {
            strCurrFolder = strData; //else assign all the data 
        }

         if(bCheck == true)
         {
            bFound = false ;
            HTREEITEM hTempItem = NULL;
            CString strItemText = "" ;
            hTempItem = m_pTreeview->GetChildItem(hChildItem);
            strItemText = m_pTreeview->GetItemText(hTempItem);
            while(hTempItem != NULL)
            {
                if(strItemText != strCurrFolder) 
                {
                    strItemText = m_pTreeview->GetItemText(hTempItem);
                    hTempItem = m_pTreeview->GetNextSiblingItem(hTempItem);
                }
                else
                {
                    bFound = true;
                    break;
                }
            }


         }
        if(bCheck == false || bFound == false)
         {

                HShareFolder = m_pTreeview->InsertItem(strCurrFolder,hChildItem);                   
                m_pTreeview->SetItemImage(HShareFolder,2,2);
                TTipItemData* pToolTipData ; 
                pToolTipData  = new TTipItemData; 
                pToolTipData->strTool = strData ;                                                                
                m_pTreeview->SetItemData(HShareFolder,DWORD(pToolTipData));

            }

         m_pTreeview->Expand(hParentItem,TVE_EXPAND);
         m_pTreeview->EnsureVisible(hParentItem);



    }

}

推荐答案

树视图中的项目可以具有与之关联的任意数据.检出:

Items in treeviews can have arbitrary data associated with them. Check out:

http://msdn.microsoft.com/en -us/library/ettyybhw(VS.80).aspx

此处显示的InsertItem方法具有一个LPARAM参数.这是供您使用的,可以将其设置为对您的应用程序有意义的值.

The InsertItem method shown here has an LPARAM parameter. This is for your use, and you can set this to some value that is meaningful to your application.

(或者,使用最小卷积的重载之一插入您的商品,并在随后返回的句柄上使用CTreeCtrl::SetItemData.)

( Alternatively, use one of the least convoluted overloads to insert your item and use CTreeCtrl::SetItemData on the handle that is returned afterwards).

要找出与您的商品相关的值,请使用CTreeCtrl::GetItemData.

To find out what value is associated with your item, use CTreeCtrl::GetItemData.

次要示例:

HTREEITEM hItem = m_ctrlTree.InsertItem("My Item", TVI_ROOT);
HTREEITEM hOther = m_ctrlTree.InsertItem("Child Item", hItem);
m_ctrlTree.SetItemData(hItem, static_cast<DWORD_PTR>(10)); // set LPARAM to 10

// note, you can also store pointers!  This assumes pObj is some kind of instance
// of a class.
m_ctrlTree.SetItemData(hOther, static_cast<DWORD_PTR>(pObj));


// at a later point:
int myVal = static_cast<int>(m_ctrlTree.GetItemData(hItem));
MyObject* pObj = static_cast<MyObject*>(m_ctrlTree.GetItemData(hOther));

这篇关于如何在MFC(VC ++)中区分文件夹类型(Windows/FTP)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆