Solved

Filter file types in CMFCShellListCtrl

Posted on 2011-02-19
11
1,747 Views
Last Modified: 2013-11-20

I'm working with the new MFC control CMFCShellListCtrl and I'm trying to add filters to the view. I want to filter by file type or string. Since it's new, the documentation and examples are limited.

So how to I set up filters?

Thanks

0
Comment
Question by:apostrophe27
  • 5
  • 5
11 Comments
 
LVL 11

Assisted Solution

by:DeepuAbrahamK
DeepuAbrahamK earned 200 total points
ID: 34952815
I haven't tried this myself but this should work.

virtual HRESULT CMFCShellListCtrl::EnumObjects(LPSHELLFOLDER pParentFolder, LPITEMIDLIST pidlParent)

Sample code to get the pidl.

LPITEMIDLIST pidl = NULL;
hr = SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidl);

if (SUCCEEDED(hr))                    
{
    SHFILEINFOW sfi = {0};
    hr = SHGetFileInfo((LPCTSTR)pidl,
                        -1,
                        &sfi,
                        sizeof(sfi),
                        SHGFI_PIDL | SHGFI_DISPLAYNAME)
            
    if (SUCCEEDED(hr))
    {
        // The display name is now held in sfi.szDisplayName.
    }
}

ILFree(pidl);

Open in new window

0
 

Author Comment

by:apostrophe27
ID: 34963254

I don't fully understand your code, but it looks like it retrieves the information on a file. Is that correct?

What I want to do is have the explorer window in the list control display only a certain type of file, .txt for example, or a string.  How do I use your example to do that?

Thanks.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 35035287
This question really is hanging about isn't it!  

I have had a good look around and come up with next to nothing for this one...the only thing I can suggest is taking a look at

http://www.codeproject.com/Messages/3206089/How-to-use-the-CMFCShellListCtrl-Class.aspx

Here, the author here claims to have found a "callback" function that will be called every time an item is added: if this is the case, you need to override that to filter out the file types you don't want to show.  However, he claims it does not work, but he might be doing something slightly wrong; maybe your eyes can see what is incorrect with it.  I don't have VS 2010 installed so I cannot try this.

Sorry if this is of no use: if you still can find no answers I might have to install VS 2010 and nail this myself :)
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 35035296
PS, I take it you have looked at the MFC 10 "Explorer" sample: http://msdn.microsoft.com/en-us/library/bb982182.aspx ?
0
 

Author Comment

by:apostrophe27
ID: 35098234

Sorry it's been awhile. I got stuck working on other things.

I saw the code project post, and I didn't understand what he was doing. Since it didn't work for him I didn't pursue it.

I saw the Explorer sample too, but it doesn't show any filtering.

I just saw a post at:
http://social.msdn.microsoft.com/Forums/en-GB/windowssdk/thread/794521ed-66e2-494f-ab28-75100fdf58d1

They're talking about creating and open file dialog box

" You can create a dialog and add a CMFCShellListCtrl-derived control to it. There is an undocumented EnumObjects function you can override to filter the results. "

I'm not sure if that's useful or not

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 19

Expert Comment

by:mrwad99
ID: 35107214
Yeah, EnumObjects() was mentioned in the first post by DeepuAbrahamK: did you not try his code??
0
 

Author Comment

by:apostrophe27
ID: 35108416
Right, he did mention EnumObjects(). Sorry, I didn't catch that when I reread the thread.

I didn't try his code because I didn't understand how to use it. I did him how to use it, but I got no response.

0
 
LVL 19

Assisted Solution

by:mrwad99
mrwad99 earned 300 total points
ID: 35108595
OK.

1).  You need a class derived from CMFCShellListCtrl in your application.  In this class's header file, add

virtual HRESULT EnumObjects(LPSHELLFOLDER pParentFolder, LPITEMIDLIST pidlParent);

Open in new window


2) In your class's .cpp file, add

<CREDIT FOR CODE GOES TO DeepuAbrahamK>
virtual HRESULT <YOUR DERIVED CLASS NAME>::EnumObjects(LPSHELLFOLDER pParentFolder, LPITEMIDLIST pidlParent)
{
LPITEMIDLIST pidl = NULL;
hr = SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidl);

if (SUCCEEDED(hr))                    
{
    SHFILEINFOW sfi = {0};
    hr = SHGetFileInfo((LPCTSTR)pidl,
                        -1,
                        &sfi,
                        sizeof(sfi),
                        SHGFI_PIDL | SHGFI_DISPLAYNAME)
            
    if (SUCCEEDED(hr))
    {
        // The display name is now held in sfi.szDisplayName.
        TRACE ( _T("Got file %s\n"),  sfi.szDisplayName);
    }
}

ILFree(pidl);
return S_OK;
}

Open in new window


3) Now.  I am not sure what needs to be returned from the function in order to prevent the add of an item.  Add the code above, add see what output you get in the output window when debugging.  If you do get a list of all the files in the current folder, it means that all we need to do is figure out the required return value to filter out file types we don't want to display.  At a guess, we could return S_FAIL to *not* add the file, although I don't honestly know.

I don't have MFC 10 on my machine, but one of the first things I would do is check out the MFC source code for CMFCShellListCtrl::EnumObjects().  You can do this easily by calling it from your overridden version.  See if the above code works ok for now, if it does not, replace all of it with a call to the base class version, i.e.

virtual HRESULT <YOUR DERIVED CLASS NAME>::EnumObjects(LPSHELLFOLDER pParentFolder, LPITEMIDLIST pidlParent)
{
return CMFCShellListCtrl::EnumObjects(pParentFolder,pidlParent);
}

Open in new window


and see what the base class version does, posting the code here please.
0
 

Accepted Solution

by:
apostrophe27 earned 0 total points
ID: 35319048
I haven't gotten this to work, and I've moved on to other things now.

Thanks for the help.

0
 
LVL 19

Expert Comment

by:mrwad99
ID: 35322179
No problem.  Thanks for splitting the points.

At some point I will install VS 2010 and see if I can figure this out; when I do (note the confidence - *when*, not *if* :) ) I will let you know.
0
 

Author Closing Comment

by:apostrophe27
ID: 35357026
I haven't gotten this to work, and I've moved on to other things.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now