Solved

Windows Shell Programming or something else?

Posted on 2001-08-21
10
271 Views
Last Modified: 2006-11-17
Hi,

I have a windows application which displays a list of files (available on shared resources on the network) in a list view.The application has a context menu enabled on the list view. I need to accomplish 2 tasks:
1. On clicking on a menu named "Properties", i need to show the property page for the file selected (as in Windows Explorer).
2. In the list view control, in a parallel column, i need to show the file type. For example, if the file is a zip file, the type would be displayed as WinZip files (as in Windows Explorer).

I've tried some shell programming using IShellFolder, but I'm unable to proceed. For displaying the properties page, I tried using ShellExecute with the "properties" verb but that is not working.
Are there any other ways?

Thanks.
0
Comment
Question by:smnaha
  • 5
  • 3
  • 2
10 Comments
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 100 total points
ID: 6412261
For the "file type" part, look into the "SHGetFileInfo" function.  That function can get you the icon, type name, and other stuff.

For the "Properties" part, I recently experienced a similar problem (on Win2K): ShellExecute no longer brought up the Windows Explorer Properties Sheet for files(!).

However, the following code works for me (spacing and indenting will get trashed...):

     SHELLEXECUTEINFO     sei;
     TCHAR               caFilePath[ _MAX_PATH + 1 ];

     //
     // Get FileName Into caFilePath...
     //
     ::memset( &sei, 0, sizeof( SHELLEXECUTEINFO ) );
     sei.cbSize = sizeof( SHELLEXECUTEINFO );
     sei.lpFile = caFilePath;
     sei.lpVerb = "properties";
     sei.fMask  = SEE_MASK_INVOKEIDLIST;

     ::ShellExecuteEx( &sei );

   Hope that helps you out...

-=- James.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6413011
By the way, there is an excellent book on this subject that you may want to consider buying.  It's called Windows Shell Programming by Dino Esposito and publiched by WROX.
0
 
LVL 1

Author Comment

by:smnaha
ID: 6413185
Hi James,

Thanks for the ShellExecuteEx information. It works!
Regarding SHGetFileInfo(), the function works only for .txt documents. Is it possible to get the same context menu that windows explorer provides?
Perhaps I need to get that WROX book :-).

-smnaha
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6413437
!!!

SHGetFileInfo(...) should work for all registered file types on your system!  If it is not working for you, please post a snippet on how you are trying to use it, and what error code you are getting back.

As far as the context menu goes, I cannot help you there.  

I have the book that jhance mentions,strange looking guy, that Dino! :), but just retyping what is in a book is not the mark of an "expert".  I would suggest getting the book, however, it will be $39.99(USD) well spent!

-=- James.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6413484
>> but just retyping what is in a book is not the mark of an "expert"

I hope you're weren't implying that this was my comment...

The book is an excellent resource because it explains how this entire area of SHELL programming works.  So rather than just get the book to copy a few lines of code, the book has the WHYs and HOWs of this to provide a basic understanding of this poorly documented (by Microsoft anyway) area.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:jtwine100697
ID: 6413582
Hope is all we have sometimes... :)  

But worry not.  (My history on this site should make that clear.)

I just meant that my providing an "answer" by retyping half of a page from the book would be inappropriate.  That is why I suggested obtaining an copy of the book directly.

-=- James.
0
 
LVL 1

Author Comment

by:smnaha
ID: 6416890
Earlier I didn't pass the SHGFI_USEFILEATTRIBUTES flag.
So I was getting the type name only for .txt files. Now I'm getting the type name for most of the files but not all the files (.HTM, .ASP files return "")

WIN32_FIND_DATA FindFileData;
SHFILEINFO sfi;
//FindFileData gets populated here

SHGetFileInfo(FindFileData.cFileName, FindFileData.dwFileAttributes,
&sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES |SHGFI_TYPENAME|SHGFI_ICON  );
                   
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6417492
Just for S&G, try this:

     ::SHGetFileInfo( FindFileData.cFileName, 0, &sfi, sizeof( sfi ), SHGFI_TYPENAME );

-=- James.
0
 
LVL 1

Author Comment

by:smnaha
ID: 6450485
Thanks, now things work fine.
Sorry for the delayed reply.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6450960
NP..  Feel free to contact me if you need any further assitance.

-=- James.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 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

12 Experts available now in Live!

Get 1:1 Help Now