Link to home
Start Free TrialLog in
Avatar of hasnpapa
hasnpapaFlag for Germany

asked on

How to use InvokeCommand with verb "COMPRESS"?

Hello, my friends!

I dealt around with Shell Context Menu and got all verbs easy to work except COMPRESS and UMCOMPRESS.

Does anyone know which aditional parameters to set in the CMINVOKECOMMANDINFO structure to get COMPRESS/UNCOMPRESS work too?


Best Regards
Robert
Avatar of jkr
jkr
Flag of Germany image

Take a look at http://bcbjournal.org/articles/vol4/0006/Using_the_shell_context_menu.htm - it should boil down to
  // Get an IShellFolder for the desktop.
  LPSHELLFOLDER DesktopFolder;
  SHGetDesktopFolder(&DesktopFolder);
  if (!DesktopFolder) {
    ShowMessage(
      "Failed to get Desktop folder.");
    return;
  }
 
  // Separate the file from the folder.
  String FilePath = ExtractFilePath(
    FileNameEdit->Text);
  String FileName = ExtractFileName(
    FileNameEdit->Text);
 
  // Get a pidl for the folder the file
  // is located in.
  wchar_t Path[MAX_PATH];
  LPITEMIDLIST ParentPidl;
  DWORD Eaten;
  StringToWideChar(FilePath, Path, MAX_PATH);
  DWORD Result =
    DesktopFolder->ParseDisplayName(
      Handle, 0, Path, &Eaten, &ParentPidl, 0);
  if (Result != NOERROR) {
    ShowMessage("Invalid file name.");
    return;
  }
 
  // Get an IShellFolder for the folder
  // the file is located in.
  LPSHELLFOLDER ParentFolder;
  Result = DesktopFolder->BindToObject(ParentPidl,
    0, IID_IShellFolder, (void**)&ParentFolder);
  if (!ParentFolder) {
    ShowMessage("Invalid file name.");
    return;
  }
 
  // Get a pidl for the file itself.
  LPITEMIDLIST Pidl;
  StringToWideChar(
    FileName, Path, MAX_PATH);
  ParentFolder->ParseDisplayName(
    Handle, 0, Path, &Eaten, &Pidl, 0);
 
  // Get the IContextMenu for the file.
  LPCONTEXTMENU CM;
  ParentFolder->GetUIObjectOf(
    Handle, 1, (LPCITEMIDLIST*)&Pidl,
    IID_IContextMenu, 0, (void**)&CM);
 
  if (!CM) {
    ShowMessage(
      "Unable to get context menu interface.");
    return;
  }
 
  // Set up a CMINVOKECOMMANDINFO structure.
  CMINVOKECOMMANDINFO CI;
  ZeroMemory(&CI, sizeof(CI));
  CI.cbSize = sizeof(CMINVOKECOMMANDINFO);
  CI.hwnd = Handle;
 
 
    CI.lpVerb = "COMPRESS";
    Result = CM->InvokeCommand(&CI);
    if (Result)
      ShowMessage(
        "Error compressing file.");
 
    // Clean up.
    CM->Release();
    ParentFolder->Release();
    DesktopFolder->Release();

Open in new window

Avatar of hasnpapa

ASKER

Thanks! I know this article.

But I wrote, "I got all verbs easy to work except COMPRESS and UMCOMPRESS". There must be some difference ...

;-)
What HRESULT codes do you get?
I got (HRESULT): "InvokeCommand: Wrong Parameter"

:)
Can you post how you are filling your CMINVOKECOMMANDINFO struct?
Yes. Ples have a look at my code - thank you!
Please keep in Mind, that is works with all other verbs :-)




if (lpVerb) {
		Memo1->Lines->Add(lpVerb);
		HRESULT 		hr;
		LPCONTEXTMENU    	CM;
		CMINVOKECOMMANDINFO CI;
		ZeroMemory(&CI, sizeof(CI));
		CI.cbSize	= sizeof(CMINVOKECOMMANDINFO);
		CI.nShow	= SW_SHOWNORMAL;
		CI.hwnd	= Form1->Handle;
		CI.lpVerb	= lpVerb;
		hr = ShellFolder_parent->GetUIObjectOf(Handle, 1, (LPCITEMIDLIST*)&NodeData->pidl, IID_IContextMenu , 0, (void**)&CM);
		if (hr) { SysError("ERROR: GetUIObjectOf ", hr); return; }
		hr = CM->InvokeCommand(&CI);
		if (hr) { SysError("ERROR: InvokeCommand ", hr); return; }
		if (CM) CM->Release();
	}

Open in new window

... return without "free" - i know ;-)
But this code is for testing purposes.
I know, it's hard.

Some one else any idea?


Best Regards
Robert
Isn't it possible that the verb is not available?  It certainly does not appear on my context menu when I right-click a folder in Windows Explorer, nor is it listed as a custom "action" in the registry for  "Folder" or "File Folder" file types.
Thanks for your response :-)

In MSDN I can't find a complete listing of all available verbs. Therefore I can not answer your question sure.

I found a list with available verbs at
http://bcbjournal.org/articles/vol4/0006/Using_the_shell_context_menu.htm 
and some other sites.

Sorry for my poor english ...

Regards
Robert
>>I can't find a complete listing of all available verbs.

That's because there is no such thing.  Anyone can add a new verb for any file type at any time.  For instance, see the article:

   'Command Prompt Here' on Explorer Context Menu
    http://www.experts-exchange.com/A_1052.html

That won't help with your problem, but it may provide some useful background information.
>>That's because there is no such thing.

Yes, there are predefined verbs since WIN2k and they are working :-)

Of course you are right and you can extend context menu, but anyway, there are still some predefined verbs like, openas, cut, copy, paste, link, delete, properties, Explore, find.

I've got all of that verbs to work (except "Explore" and "find" beacuse I don't need them this time, so they are untested by me).

I think/hope for COMPRESS there should be set (perhaps) some aditional parameters in the CMINVOKECOMMANDINFO structure like 'compression rate', 'target folder' ... or something like that what would make sense. I don't know ...
Don't forget the "runas" verb.
The "compress" verb will be available only if WinZIP or WinRAR or other compression utility has added a global (all file types) handler to the registry.
Sorry for my delay :-)
... other works in progress.

I'll check this next week when Winzip is installed.

Thank you, so far!
I have 7-Zip installed now. 7-Zip set a handler for the Zip-Files.

Still does not work.

I found at

http://www.codeguru.com/cpp/com-tech/shell/print.php/c1315

Cite: "... under NT, you'll get the additional commands 'Compress', 'Uncompress', and 'Open With...' ..."

Strange behavior all that!

Any idea?
Ah, of course, I've tested "COMPRESS", "Compress", "compress" as verbs ;-)
Here's what I'd do....
I'd use
    Explorer > Tools / Folder Options/ File Types
to add a New file association, for say, files of type "ZXQ"  and I'd Avanced edit it add a New verb for that file type: "compress" with the action being to run a batch file that just pops us and says "compressing... press any key"
Now you can test whther you can invoke the "compress" verb programmatically.
Thanks, Dan! :-)

By the way as described, you can add *any* verb you want.

This is not what I've found on several documentations, that there schould exist - under NT und up - predefined verbs called "COMPRESS" and "UNCOMPRESS".

Windows comes with ZIP function built in and there is allready a file assicioation. What I'm try to say is, I can' beleve that all informations are wrong that says, "under NT and up 'compress', 'uncompress' are predefinded verbs.

The most strange thing is, that I can not find any listing of all available verbs in MSN. If there was one, this would be the helpfull thing to avoid all specualtions.

Thank you, Dan!
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dan, thank you for this hard work!

I'm still in progress in working on little program. I think, it'l last for the few next months ...

If the actual part, learning to write a ShellChangeNotifier thread in conclusion with a TreeView, is finished, I'l check out your script - and hope to get it to work under Vista.

[cite]
I recently worked on a question here at EE where the asker wanted to know how to get a list of all shell "action verbs" that can be applied to to a particular file. The System.Shell object that is provided by the gadget runtime environment exposes a lot of functionality, but that's an example of something it can't do.
[/cite]

Again, thanks a lot!