xplorer2 HACK : Convert any menu item to a toolbar button !!

A collection of especially useful xplorer² topics and ideas. New users may find it helpful to look here before searching the other forums for information. >>>>>> Please post new material in the relevant forum. (New stuff posted here will be removed.) Thanks. -fg-

Moderators: fgagnon, nikos

Post Reply
User avatar
snakebyte
Gold Member
Gold Member
Posts: 430
Joined: 2003 May 07, 07:14
Location: Seattle
Contact:

xplorer2 HACK : Convert any menu item to a toolbar button !!

Post by snakebyte »

A favorite of folks who want to add functions to their toolbar(s) as buttons.
This topic thread was originally posted in the xplorer² Professional forum.        Moved here 19-May-2010 =fg=
============================================================

UPDATED:  Simplified usage instructions.
MenuHack.exe will let you add any Xplorer2 menu item or Xplorer2 Hotkey to your toolbar.  This example shows how to add list and detail pane style options to your toolbar.

1. Download  MenuHack.exeto some folder (say C:\My Downloads)

2. Create two new user command in Xplorer2 (Go to Customize->User commands ->Add new). Fill out Name and Description as shown below.

Code: Select all

Name: List 
Description: >"C:\My Downloads\MenuHack.exe" 32782  

Code: Select all

Name: Detail 
Description: >"C:\My Downloads\MenuHack.exe" 32783  
Note: Don't skip ">" symbol at start of your description.

3. Add these two commands to your toolbar (Right click on your toolbar and choose customize. Add "List" and "Detail" commands that you created earlier from left list box to the right one).

4. Now you can use these two toolbar buttons to switch between list and detail views.

Download following menu id and hotkey list to add any other command to your toolbar
http://hacks.anunay.com/xplorer2/downlo ... mmands.txt
http://hacks.anunay.com/xplorer2/downloads/Hotkeys.txt

Update v1.2
Kilmatead cleaned up and updated the original menuhack code to work with x2 v2.0. You can download the updated version here.

Thanks Kilmatead :)

Update v1.1
Menuhack can now simulate Ctrl, Alt or Shift key down during any X2 command execution.

Here are few examples
Copy with confirmation dialog
>"C:\Tools\MenuHack.exe" 32793

Copy without confirmation
>"C:\Tools\MenuHack.exe" 32793  CTRL

Open new Tab in Current pane
>"C:\Tools\MenuHack.exe" 33036

Open new Tab in Opposite pane
>"C:\Tools\MenuHackv1.1.exe" 33036 ALT


Original Post
I think some of the cool xplorer2 functionality is hidden in deep menus and is not being used to its full extent due to following reasons:

a) Only menu entry exists. No toolbar icon or hotkey is available. Multiple clicks are required to get the desired result. (E.g. Duplicate, list, detail, thumbnail etc).
b) Hotkey is available, but there is no equivalent toolbar button. It's often difficult to remember hot keys for all your favorite actions. I often get confused with these ones: Alt+H, Ctrl+H, Alt+J, Ctrl+Alt+M, Ctrl+Alt+J. Also when you are holding mouse, its bit inconvenient to leave it and press something on keyboard especially when it requires both hands.

   I believe there is a limitation in xplorer2 where you can only create toolbar items for items having icons. Lately, I have been seeing lot of requests in Xplorer2 forum to add extra tool bar buttons and I decided to share this hack which I've been using for over a year now.

   This hack will let you map *any* menu item to a toolbar button. First let me explain how it works. When user selects an item from menu, WM_COMMAND message is sent to the OS. This message is passed with two parameters wParam and lParam. These parameters contain numeric code that tells OS which menu item was selected. Each menu item is associated with a unique code. It is possible to simulate a menu click by passing a WM_COMMAND message with appropriate menu code.

   So how can you find out these codes? Well there are two ways to do it. 1) Use tools like Spy++ or Winspector to spy the windows messages from Xplorer2, or 2) The most easiest way is to use resource hacker to extract complete menu dump in one go.

Following AutoIt3 script accepts menu code as parameter and simulates a menu click

Code: Select all

if $CmdLine[0] > 0 then 

  $param = $CmdLine[1];
  $WM_COMMAND = 0x0111
  $WindowTitle = "xplorer"
  DllCall("user32.dll", "int", "SendMessage", _
		"hwnd",  WinGetHandle( $WindowTitle ), _
		"int",   $WM_COMMAND, _
		"long",  $param, _
		"long", 0)

else
  MsgBox(4096,"Missing Parameter","Usage: MenuHack.exe <Menu ID>")
endif 
Usage Instructions

If you don't want to install AutoIt3 you can download the compiled version of this script from this link here and execute it as

Code: Select all

>"D:\My Scripts\MenuHack.exe" 32783
The last parameter passed to script is the menuid to switch the current pane to detail view. You can download the complete menu ids list from here.

Some of my favorite commands are: (Note: Create top two ones first and add them to your toolbar. It will speed up your subsequent command creation)

Code: Select all

#Add New Command
>"D:\My Scripts\MenuHack.exe" 33001

#Organize Command
>"D:\My Scripts\MenuHack.exe" 33002

#List View
>"D:\My Scripts\MenuHack.exe" 32782

#Detail View
>"D:\My Scripts\MenuHack.exe" 32783
Once xplorer2 gets the ability of customizing individual user command icons, you'll be able to change icon of any existing toolbar button by creating its user command equivalent and giving it a custom icon.


[ A favorite topic: moved from x² Pro forum  -fg- ]
Last edited by snakebyte on 2011 Dec 10, 01:44, edited 9 times in total.
Help! I'm an AI running around in someone's universe simulator.
Gandolf
Gold Member
Gold Member
Posts: 466
Joined: 2004 Jun 12, 10:47

Post by Gandolf »

Looks excellent, I'll have to see if it needs modifying for AutoHotkey.
User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

Quick switching between pane views & Hackmenu.exe

Post by JamieG »

I've just gotten around to trying the 'Hackmenu.exe' solution and it's just perfect!

I've gotten the little hammer icons for my new "List", "Detail" & "Thumbnail" view commands and have assigned sortcut keys to them... just what I wanted.  Thanks so much to Snakebyte and to Demetris for their time and their help!  :turn:

PS: I'm replying here so that Snakebyte's nifty instructions will be brought back to life.
User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

Convert menu items to toolbar icons... not for scrap windows

Post by JamieG »

Well, nearly perfect.

It doesn't work on scrap panes, which are actually where I most often do things like changing views.

Resolving to be less of a wimp, here amongst the various Masters of the Universe, I thought I'd have a try at finding the solution myself!  Hah hah!  So, imagining that there were hitherto-undisclosed menu IDs to be discovered, I downloaded Wininspector, figured out enough of its interface to locate the scrap window & the magic menu number and... aargghhh!  It's the same value as for the main xplorer2 window!  (I suppose that shouldn't be a surprise :cry: )

So I guess I'll just have to way for a rainy day, or two, or forty for a solution.  Thanks again nonetheless, Snakebyte!
User avatar
nikos
Site Admin
Site Admin
Posts: 15759
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos »

narayan don't you think this patch is worthy of mentioning in the manual? many people seem to find it useful

snakebyte i guess you search for the window by class/title and send messages, so a slight modification should work for scraps too (with an optional command line switch). Of course the problem is that there may be many scraps open -- this also holds for the main window but for scraps it is even more likely
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

Sure! Next version of User Manual will have it!
User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

Great idea

Post by JamieG »

Fine idea, incorporating the Snake Byte Patch into the manual.

It'd also be nice if someone could find the time to figure out how, and then modify MenuHack.exe, so that it would work on the top-most xplorer2 window... that way I think it would work for panes too!  (Would one ever want to issue a command to an inactive window?)
User avatar
snakebyte
Gold Member
Gold Member
Posts: 430
Joined: 2003 May 07, 07:14
Location: Seattle
Contact:

Post by snakebyte »

I never tested menuhack on the scrap panes. Here is the updated script. Menuhack now works on the topmost Xplorer2 or topmost scrap pane window.

Code: Select all

if $CmdLine[0] > 0 then 
    $param = $CmdLine[1];
    $WM_COMMAND = 0x0111
    $handle = FindTopmostXplorer2Window()
    DllCall("user32.dll", "int", "SendMessage", _
            "hwnd",  $handle, _
            "int",   $WM_COMMAND, _
            "long",  $param, _
            "long", 0)
else
    MsgBox(4096,"Missing Parameter","Usage: MenuHack.exe <Menu ID>")
endif 

Func FindTopmostXplorer2Window()
    ;Get list of all the windows 
    $var = WinList()
    
    ;Return topmost xplorer2 or scrap window handle
    For $i = 1 to $var[0][0]
        If StringInStr($var[$i][0],"xplorer")>0 Or _
           StringInStr($var[$i][0],"scrap")>0 Then
                Return $var[$i][1]
        EndIf
    Next

    ;default return value
    Return WinGetHandle( "xplorer" )
EndFunc
You can download the compiled version of above script from here. The usage instruction stays the same.
Last edited by snakebyte on 2008 Apr 27, 04:10, edited 1 time in total.
Help! I'm an AI running around in someone's universe simulator.
User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

Link to wrong version of MenuHack.exe

Post by JamieG »

Hi Snakebyte.  Thanks for the update.  You are wonderful!  The link to the compiled program, however, points at the previous version, not the new one  :cry:
User avatar
snakebyte
Gold Member
Gold Member
Posts: 430
Joined: 2003 May 07, 07:14
Location: Seattle
Contact:

Post by snakebyte »

Hi Jamie,

    Its the new version. I think your browser is reading this file from your cache. Try clearing your cache or try some other browser. If it still doesn't works, I'll upload it to a different location.
Help! I'm an AI running around in someone's universe simulator.
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

I didn't have any problems getting the new version.
User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

Ooops

Post by JamieG »

Thanks, Snakebyte, you were right... ah, the little embarrassments :oops:, I should have thought of that.  :roll:

I cleared my cache, downloaded the new version, and it works beautifully on whichever x2 window I want... scraps & main dual-pane windows.  I couldn't be happier, thanks to you! :bigsmile:
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

snakebyte, I have sent you a PM. Please reply offline (PM or email).

Thanks!
User avatar
snakebyte
Gold Member
Gold Member
Posts: 430
Joined: 2003 May 07, 07:14
Location: Seattle
Contact:

Post by snakebyte »

I found that apart from menus, MenuHack also supports xplorer2 keyboard hotkeys which are not available on xplorer2 menus. eg Ctrl+E, Ctrl+Alt+Left/Right, Ctrl+Shift+Up/Down etc.

Now you can add your favorite hotkey to toolbar as well. Download complete list of hotkey and command id mapping from here.
Help! I'm an AI running around in someone's universe simulator.
User avatar
WimdeLange
Gold Member
Gold Member
Posts: 416
Joined: 2004 Aug 16, 08:41
Location: NL

Post by WimdeLange »

snakebyte wrote:Now you can add your favorite hotkey to toolbar as well. Download complete list of hotkey and command id mapping from here.
The link is not working. Can you place the list in ascii in the forum? (or is that not allowed? Nah , should be no problem. Debug info is placed often and never seen any complains).
Groetjes,
  Wim de Lange
Post Reply