Solved

Windows Shell Programming or something else?

Posted on 2001-08-21
10
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

734 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