Add a custom main menu item with icon for an em_ command ?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
jonathanpoulin
Member
Member
Posts: 131
Joined: 2020-12-19, 12:09 UTC
Location: Saint-Marc-des-Carrières, QC Canada
Contact:

Add a custom main menu item with icon for an em_ command ?

Post by *jonathanpoulin »

Hi,

I know that I can have an icon when I put in my .MNU file a number starting from 10000. In that case, I have to count sequentially all distinct em_ commands, until I find the good one, using that logic:
  1. the ones that appear in the [User] section (i.e. Start menu) of wincmd.ini file, followed by
  2. the ones that appear in the button bar (like default.bar), followed by
  3. the ones that appear in the vertical button bar (like vertical.bar)
So, by example, if this is the 15th, I need to put 10014 in my .MNU file, for the menu item. The icon to display will be mapped in the .INC file using that number.

Now, the question! :)

Is there a way to add a custom main menu item (under the Commands menu by example) with an icon for an em_ command, BUT without having to add that em_ on a button bar beforehand?
Thanks,
Jonathan Poulin
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Custom main menu item with icon

Post by *beb »

jonathanpoulin wrote: 2024-07-11, 18:37 UTC ...Is there a way to add a custom main menu item (under the Commands menu by example) with an icon for an em_ command, BUT without having to add that em_ on a button bar beforehand?
Those are unrelated things. You don't need to add anything anywhere (including a button bar) beforehand. They are working independently.
Once you've asked a similar question, and I cannot add much to what I replied there then (see "user commands mappings"):
viewtopic.php?t=80896&p=448753#p448753
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Custom main menu item with icon

Post by *beb »

Here's a fragment of my [actual] current wciconex.inc file as an example:

Code: Select all

// * user icon library for the wciconex.inc
// # [Buttonbar]
// # IconLib=wciconex.dll
// #
// # user commands mappings
10000=1   // "%commander_path%", em_commander_path
10001=1   // "%plugins%", em_plugins_path
10002=1   // "%app%", em_app_path
10003=80  // "TotalUpdater", em_updater
10004=34  // "Plugman", em_plugman
10005=82  // "wdx Guide", em_wdxGuide
10006=46  // "ultra *.ini", em_utce
10007=28  // ".ini", em_ini_edit_xl
10008=28  // ".plugins", em_plugins_edit
10009=28  // "ini", em_ini_edit
10010=28  // "menu", em_mnu_edit
10011=28  // "commands", em_cmd_edit
10012=28  // "iconex", em_iconex_edit
10013=28  // "bars", em_bar_edit
10014=63  // "Dummy File",em_dummy_file
10015=109 // "TC 32/64 bit", em_bitness
10016=87  // "TC Restart", em_restart
10017=23  // "Vertical: 50/50%", em_Vertical50
10018=37  // "Panels: 70/30%", em_70percent
10019=37  // "Panels: 80/20%", em_80percent
10020=37  // "Panels: 100/0%", em_100percent
10021=120 // "wget", em_wget_tc
10022=120 // "wget idx", em_wget_idx
10023=120 // "wget clip", em_wget_clip
10024=35  // "Dirs: Synchronize Background...", em_syncDirs
10025=85  // "Delete Empty Folders", em_delemptydirs
Notes:
All the things behind the // are the comments
None of the listed em_(s) exists [beforehand] as the toolbar buttons, while the custom icons are being rendered in the menu as they should be.
A friendly piece of advice: don't modify the default Total Commander menu entries, instead prefer making your own entry(ies) [say named "Custom", etc] and put your custom command in there [keeping its backup somewhere in case of the future updates].
My example:
Image: https://i.imgur.com/8Y9lQHS.png
Last edited by beb on 2024-07-12, 03:57 UTC, edited 1 time in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
petermad
Power Member
Power Member
Posts: 16009
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Custom main menu item with icon

Post by *petermad »

2jonathanpoulin
Is there a way to add a custom main menu item (under the Commands menu by example) with an icon for an em_ command, BUT without having to add that em_ on a button bar beforehand?
You don't have to add the em_command to a button - in fact that has no effect. And the icons in the Start menu and button bars has no influence on the number of the command you have to assign an icon to in the .inc file for use in the Menu.

What you do is count the em_commands in your .mnu file - the first one will be assigned command no. 10000 and so forth. You can only assign icons from your current default icon library. If your default icon library is wcmicons.dll you assign the icons in the corresponding wcmicons.inc file, so if you for example want to use the 1st icon in wcmicons.dll (the green reloading arrows) for the first em_command in your .mnu file you assign 10000=0

If you use the same em_command more than one time in the .mnu file you must not assign it again - skip the duplicated em_command when you count.

it is unfortunately NOT possible to assign icons that are not in the default icon library to the menu, just by setting an external icon (from a .ico, .exe, .dll, or .icl file) for the em_command.

Icons set in the em_command are only used in the button bars, and only if you select the em_command via clicking the button with the magnifying glass, when you create the button (via the Choose Command dialog).

So if you want custom icons in your menu you have to add the icon to the icon library (for example wcmicons.dll).

If you want to make your own library file it is important that it has the correct Versioninfo embedded in the .dll file.

The minimum Versioninfo could look like:

Code: Select all

1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x40000
FILETYPE 0x1
{
BLOCK "StringFileInfo"
{
	BLOCK "040904E4"
	{
		VALUE "FileDescription", "My own Icons for TC"
		VALUE "FileVersion", "1.0.0.0"
	}
}

BLOCK "VarFileInfo"
{
	VALUE "Translation", 0x0409 0x04E4
}
}
otherwise it will not turn up in the list of libraries that you get when you click the button "Set default icon library" in the Icons configuration (or when you right click the button bar).

You can use a program like ResourceHacker to add the Versioninfo.

If you choose to make your own icon library, the file name has to start with wcmicon for example wcmiconmyicons.dll - if you make a corresponding wcmiconmyicons.inc file then that file will be used for mapping the icons, otherwise your wcmicons.inc file will be used.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Custom main menu item with icon

Post by *beb »

2petermad
As always, thank you very much for your additional detailed and important explanations.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Custom main menu item with icon

Post by *Stefan2 »

beb wrote: 2024-07-11, 22:33 UTC 2petermad
As always, thank you very much for your additional detailed and important explanations.

From me to you two too ;-)





 
User avatar
jonathanpoulin
Member
Member
Posts: 131
Joined: 2020-12-19, 12:09 UTC
Location: Saint-Marc-des-Carrières, QC Canada
Contact:

Re: Custom main menu item with icon

Post by *jonathanpoulin »

Thanks guys! It works!

I mixed things up... :( ...on my original post here and how I understood the beb's post here: viewtopic.php?t=80896&p=448753#p448753. Sorry for that guys! :roll:

In fact this is simple.

I think what confused me yesterday is that I needed to restart TC to apply modifications properly (I was not restarting TC). I was adding a new menu item in .MNU file, for an em_ command, and after I was adding an icon mapping in .INC file. To have the new menu item, I needed to call cm_ReloadBarIcons. The menu was appearing, but without its icon! So, I thought this was impossible to map an icon in that case. Like I said, I needed to restart TC to have the icon displayed. Maybe it can be an improvement to reload the menu item icons when cm_ReloadBarIcons is called.

One last thing I found about it. Back in January, I did not understand what to do exactly (even if it was working in the end). I was adding number values in my .MNU file as the example below:

Code: Select all

MENUITEM "&Menu Item 1", 10000
MENUITEM "&Menu Item 2", 10001
...
So, like that, I needed to have at least 2 different em_ commands on the Start menu and/or button bars. The first encountered was the command associated to "Menu Item 1", the second to "Menu Item 2".

I don't know if I am clear.

This sounds like an unwanted "side-effect".

I think this is another reason that made me struggle with my understanding of that.
Thanks,
Jonathan Poulin
User avatar
jonathanpoulin
Member
Member
Posts: 131
Joined: 2020-12-19, 12:09 UTC
Location: Saint-Marc-des-Carrières, QC Canada
Contact:

Re: Custom main menu item with icon

Post by *jonathanpoulin »

2petermad

By the way, thanks a lot for the explanation about Versioninfo. Very informative.
Thanks,
Jonathan Poulin
User avatar
petermad
Power Member
Power Member
Posts: 16009
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Custom main menu item with icon

Post by *petermad »

it can be an improvement to reload the menu item icons when cm_ReloadBarIcons is called.
According to the description cm_ReloadBarIcons should reload the icons both in the button bar AND the menu, but it is my experience that it does not always work - better restart (just use cm:Exit 9.).

So, like that, I needed to have at least 2 different em_ commands on the Start menu and/or button bars. The first encountered was the command associated to "Menu Item 1", the second to "Menu Item 2".
I looked into it - it is a little more complicated than that:

If you use MENUITEM "&Menu Item 1", 10000 then TC will look in different locations for an em_command to assign to the 10000 command.

TC will search for an em_command in this order:
  1. In the current Main menu file. TC will use the first em_command it finds in the file (even if "Menu Item 1" is listed before the first em_command).
  2. In the current Horizontal bar file. TC will use the first em_command it finds in the file.
  3. In the current Vertical bar file. TC will use the first em_command it finds in the file.
  4. In the [Shortcuts] section of the wincmd.ini file. TC will use the first em_command it finds in this section
  5. In the [ShortcutsWin] section of the wincmd.ini file. TC will use the first em_command it finds in this section
  6. In the [User] section of the wincmd.ini file (the Start menu). TC will use the first em_command it finds in this section

The only way the .bar file and the .mnu file is connected, is in the case where you don't have an .inc file (like wcmd_deu.inc). If you put a cm_command in a button, but don't write a Tooltip (menu=), then TC automatically uses the string for that command from the .inc file as the tooltip in the current language when you hover a button. If there is no .inc file, TC instead instead looks in the current .mnu file for the command, and uses the text string from that menu as the tooltip.

You can always use a cm_command number instead of the command name - for example 610 instead of cm_HelpIndex - in buttons, menus, shortcuts etc.

Likewise you can use 10000 as the command In a button - then that button will execute the first em_command found as described here above - and if the em_command if found in the .mnu file, the tooltip for the button will show the text from the .mnu file for that em_command.

TC looks for the definitions of the em_commands in two places in this order:
  1. In the usercmd.ini file - located in the same dir as the current wincmd.ini
  2. In the wcmd_XXX.ini file where XXX is the same as the for current .mnu file (for example dan when using wcmd_dan.mnu). The file must be located in the same place as the current .mnu file.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
jonathanpoulin
Member
Member
Posts: 131
Joined: 2020-12-19, 12:09 UTC
Location: Saint-Marc-des-Carrières, QC Canada
Contact:

Re: Custom main menu item with icon

Post by *jonathanpoulin »

petermad wrote: 2024-07-13, 12:41 UTC TC will search for an em_command in this order:
  1. In the current Main menu file. TC will use the first em_command it finds in the file (even if "Menu Item 1" is listed before the first em_command).
  2. In the current Horizontal bar file. TC will use the first em_command it finds in the file.
  3. In the current Vertical bar file. TC will use the first em_command it finds in the file.
  4. In the [Shortcuts] section of the wincmd.ini file. TC will use the first em_command it finds in this section
  5. In the [ShortcutsWin] section of the wincmd.ini file. TC will use the first em_command it finds in this section
  6. In the [User] section of the wincmd.ini file (the Start menu). TC will use the first em_command it finds in this section
Great stuff! Thanks a lot for that, Peter, really useful!
Thanks,
Jonathan Poulin
User avatar
jonathanpoulin
Member
Member
Posts: 131
Joined: 2020-12-19, 12:09 UTC
Location: Saint-Marc-des-Carrières, QC Canada
Contact:

Re: Custom main menu item with icon

Post by *jonathanpoulin »

petermad wrote: 2024-07-13, 12:41 UTC According to the description cm_ReloadBarIcons should reload the icons both in the button bar AND the menu, but it is my experience that it does not always work - better restart (just use cm:Exit 9.).
Indeed, according to the description "Force reload icons in button bars and main menu", it should. This is a little bug that I will maybe report.

By the way, question. For the cm_Exit command, it seems using parameter "1" and "9" does the same. Below here is from the help file. I don't get it, what means "Pass current left and right...".

cm_Exit 0 or no parameter: Just exit. Or sum of:
1: Exit and restart Total Commander
2: Exit and restart, and switch between 32-bit and 64-bit versions
4: Save directories, tabs and panels (brief, full etc.) even when disabled in settings
8: Pass current left and right directory and file under cursor to new instance
16: Restart as administrator
Thanks,
Jonathan Poulin
User avatar
petermad
Power Member
Power Member
Posts: 16009
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Custom main menu item with icon

Post by *petermad »

By the way, question. For the cm_Exit command, it seems using parameter "1" and "9" does the same
It does the same if you have "Configuration" -> "Options..." -> "Operation" -> "Save on exit" -> "Directories" enabled.
If saving directories is not enabled, TC always starts with the last saved folders in the two panels (which could be saved a long time ago with the "Configuration" -> "Options..." -> "Save Settings" option). With cm_Exit 9 - TC will restart with the last opened folders, even if these folder are not saved as default folders.

I like my TC to always start the same way, so I have disabled saving of Directrories and Panels (brief/full etc). But when I just want a retart of TC, I like to stay in the current folders - so then I use cm_Exit 9.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
jonathanpoulin
Member
Member
Posts: 131
Joined: 2020-12-19, 12:09 UTC
Location: Saint-Marc-des-Carrières, QC Canada
Contact:

Re: Custom main menu item with icon

Post by *jonathanpoulin »

petermad wrote: 2024-07-13, 15:24 UTC
By the way, question. For the cm_Exit command, it seems using parameter "1" and "9" does the same
It does the same if you have "Configuration" -> "Options..." -> "Operation" -> "Save on exit" -> "Directories" enabled.
If saving directories is not enabled, TC always starts with the last saved folders in the two panels (which could be saved a long time ago with the "Configuration" -> "Options..." -> "Save Settings" option). With cm_Exit 9 - TC will restart with the last opened folders, even if these folder are not saved as default folders.

I like my TC to always start the same way, so I have disabled saving of Directrories and Panels (brief/full etc). But when I just want a retart of TC, I like to stay in the current folders - so then I use cm_Exit 9.
Ok, I understand now! Thanks Peter!

Yes, my option "Operation" -> "Save on exit" -> "Directories" is enabled. The same for "Panels (brief/full, etc.)". Unlike you, I like it a lot when my TC reopen in the same state as it was before closing.
Thanks,
Jonathan Poulin
Post Reply