Solved

Windows Shell Programming or something else?

Posted on 2001-08-21
10
260 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

706 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

19 Experts available now in Live!

Get 1:1 Help Now