Menu With Icons.

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2Valentino
Thanks you very much for this information. These are really great news. I never thought Iit would be possible to increase the width and height this way. I will update my demo program.
Last edited by Lefteous on 2006-11-10, 14:07 UTC, edited 1 time in total.
User avatar
StickyNomad
Power Member
Power Member
Posts: 1933
Joined: 2004-01-10, 00:15 UTC
Location: Germany

Post by *StickyNomad »

2Lefteous
Whoa, nice to hear! I'm already drooling to see it in action :)
User avatar
majkinetor !
Power Member
Power Member
Posts: 1580
Joined: 2006-01-18, 07:56 UTC
Contact:

Post by *majkinetor ! »

Some notes to all interested:

1. Menu with icons is OVERDRAWN menu. Not the BITMAP menu or STRING menu

2. For overdrawn menu, Windows calls 2 times your application - first time to return width and height of the item rectangle and second time to draw it in it.

3. You can draw anything that you like in it - large icons, small icons, per item text colors, named separators etc.

4. It is very easy to do, I even managed to make it in AHK.

5. Forget about 13 pixel bitmpas. Its for checkboxes only, not important for this.

Screenshots:

www.r-moth.com/_/menu/_clip1.png (with new hot menu break feature)
www.r-moth.com/_/menu/_clip2.png (with new hot only icons menu)


For those who want to see the code, it will be available as open source AHK soon on its forum. I am creating this as general command to be used instead AHK menu command.

This is interface I created for the new menu command

Code: Select all

#SingleInstance force
    ;set the constants
    INIT_Menu()


    ;create submenus
    ships := Menu_Create()
    Menu_Set( ships, "s64, RFF00FF, ,L20, HFF, FArial:s14", "icons\ode.ico")
    Menu_Add( ships, "Infiltrator","icons\sw\Infiltrator.ico"       )
    Menu_Add( ships, "Starfighter",             "icons\sw\naboo.ico", "s128"    )
    Menu_Add( ships, "X100 - Recomended by Obi","icons\sw\obi.ico"      )
    Menu_Add( ships, "Imperial shuttle","icons\sw\Imperial_shuttle.ico", "B"    )
    Menu_Add( ships, "X-Wing",                  "icons\sw\xwing.ico"    )
    Menu_Add( ships, "Slave i-b",               "icons\sw\slave.ico"    )


    mercs := Menu_Create()
    Menu_Set( mercs, "s128, L40", "")
    Menu_Add( mercs, "",    "icons\sw\DarthVader.ico")
    Menu_Add( mercs, "",    "icons\sw\r2-d2.ico"     )
    Menu_Add( mercs, "",    "icons\sw\BobaFett.ico"  )


    swords := Menu_Create()
    Menu_Set( swords, "s92, h0FF0FF", "icons\back.ico")
    Menu_Add( swords, "s1", "icons\sw\Qui-Gon.ico"  )
    Menu_Add( swords, "s2", "icons\sw\Obisaber.ico" )
    Menu_Add( swords, "s3", "icons\sw\Maul2.ico"    )


    ;create main menu -----------
    SWshop := Menu_Create() 
    Menu_Set( swshop, "h0F11FF, cA7A7A7, m20, FVerdana:s12 bold")
    Menu_Add( swshop, "Find hotel room",    "icons\home.ico",   "s92, i101"  )
    Menu_Add( swshop, "Send an e-mail",     "icons\pen_red.ico" ,"S32, F :s12 italic underline" )
    Menu_Add( swshop, "Enter chat",         "icons\chat.ico"    ,"s48, F :s12 italic underline" )
    Menu_Add( swshop, "By gear",            "icons\gear.ico"    ,"s92" )

    ;Add submenu
    Menu_Add( swshop, "Choose service", ""                       ,"D, cFFFFFF, FXirod:s12", 1 )
    Menu_Add( swshop, "Buy a Ship",     "icons\sw\xwing.ico"     ,"FCourier New:s12 bold, s128, M" ships, 2 )
    Menu_Add( swshop, "Hire a Mercenary","icons\sw\BobaFett.ico" ,"FCourier New:s12 bold, s92,  M" mercs, 3 )
    Menu_Add( swshop, "Buy a Sword",    "icons\sw\maul.ico"      ,"FCourier New:s12 bold, s92,  M" swords,4 )
    Menu_Add( swshop, "Other",          ""                       ,"D, cFFFFFF, FXirod:s12", 5 )

;   Menu_Delete(swshop, 5)
;   Menu_Delete(swshop, 1)

return

!m::
    Menu_Show( swshop, 50, 50, "MyMenuHandler")
return  

MyMenuHandler:
;   MsgBox Title:`t%M_Title% `nID:`t%M_ID%`nMenu:`t%M_Menu%
return 


#include Menu.ahk   
Habemus majkam!
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

I just updated my little demo program:
http://www.lefteous.de/tc/archives/iconmenu_demo/iconmenu_demo_winapi.sqx

There is no logic behind the checkmarks. There are placed morer less randomly.

Menus can be loaded with right click on the window.

Some technical remarks.
This version doesn't use VCL just directly Windows API calls and it uses standard menus (_not_ owner-drawn menus) as Valentino suggested. There are some minor drawing glitches which shouldn't be difficult to solve in a real world application. I'm not that experienced in bitmap handling. Maybe someone has a tip? Anyway it's just a demo app.

Some important things I discovered:
- A submenu needs a dummy bitmap in the same size as the other menu items. Otherwise the menu item is not resized and submenu arrow might be drawn into the text.
- The bitmap size in this example is 20x16. This is done because the distance between bitmaps and menu caption is too small by when using larger bitmaps then 13².
An alternative solution is to prepend a space character to the menu captions.
- AFAIK it won't work on Windows 95 but on all newer Windows versions.
Last edited by Lefteous on 2006-11-11, 11:13 UTC, edited 1 time in total.
morte01
Junior Member
Junior Member
Posts: 25
Joined: 2004-02-08, 09:13 UTC

Post by *morte01 »

The checkmarks look very good, but i dont like that the icons become inverted if they are selected.

Anyway: menus like these would be great in tc!

Thanks
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2morte01
i dont like that the icons become inverted if they are selected.
Well I don't know if this can be avoided. The whole line is inverted which also includes the bitmap. Maybe there is a flag which controls this but I don't think so.
User avatar
majkinetor !
Power Member
Power Member
Posts: 1580
Joined: 2006-01-18, 07:56 UTC
Contact:

Post by *majkinetor ! »

Icons can be only done in overdrawn menus. Anything else is a wrong topic.

Inform yourself better Leftious.
Standard menus can not have icons, only checkmarks that you can change (like Favmenu has currently) at it works ok but you can have only 13x13 icons at most... stupid. The menu api is not designed to use icons in this part at all...

You can ofcoruse do some strange things like the one u are doing here...

BTW, your demo eats 100% CPU here, and I don't see any icons.
Habemus majkam!
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2majkinetor !
There is a function SetMenuItemBitmaps where you can two bitmaps for checked and unchecked states. This is also the function Ghisler referred to the msdn documentation of this function as he wrote that monochrome bitmaps should be used.

This is not the function which I'm using in my demo application.


As Valentino suggested I'm using SetMenuitemInfo instead. In the MSDN documentation you can find 3 bitmap members in the associated structure MENUITEMINFO.

Code: Select all

HBITMAP hbmpChecked; 
HBITMAP hbmpUnchecked;
These two members seem to be the same as in SetMenuItemBitmaps although there is nothing mentioned here about color depth limitations. Anyway I'm not using these members in my demo app. I just set MFS_CHECKED. In other words I'm not using custom checkmarks.
BTW: I'm not using radio checkmarks but that's of course no problem to add.

Code: Select all

HBITMAP hbmpItem;
This is the bitmap which can be used for displaying an icon. This is not really something new (introduced in Windows 98 ) but I didn't know that the menu automatically resizes to fit its content when assigned a bitmap larger than 13² pixels. Thanks to Valentino for providing this information.

Conclusion:
The only difference in my menu to the current implementation in TC is that I'm assigned a bitmap to the hbmpItem member.
Last edited by Lefteous on 2006-11-11, 13:53 UTC, edited 1 time in total.
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

your demo eats 100% CPU here
Sorry for that :oops: Please redownload.
http://www.lefteous.de/tc/archives/iconmenu_demo/iconmenu_demo_winapi.sqx
BTW: It wasn't related to the menu at all.
I don't see any icons.
Please make sure you are starting the demo app from within TC 7.
I'm using %COMMANDER_PATH% and %COMMANDER_INI% intensively.
User avatar
m^2
Power Member
Power Member
Posts: 1413
Joined: 2006-07-12, 10:02 UTC
Location: Poland
Contact:

Post by *m^2 »

Lefteous wrote:
I don't see any icons.
Please make sure you are starting the demo app from within TC 7.
I'm using %COMMANDER_PATH% and %COMMANDER_INI% intensively.
Now I know what was the problem!
You use it too intensively, I believe ;)
I was running it from within TC7, but I have unusual TC folder organisation.
Solved by running it from clean TC7 installation.
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2m^2
You use it too intensively, I believe
I don't really know what you mean :-)
If there is no file called Wcmicons.dll in the TC root directory no icons are displayed though.
User avatar
m^2
Power Member
Power Member
Posts: 1413
Joined: 2006-07-12, 10:02 UTC
Location: Poland
Contact:

Post by *m^2 »

Lefteous wrote:2m^2
You use it too intensively, I believe
I don't really know what you mean. If there is no file called Wcmicons.dll in the TC root directory no icons are displayed though.
So that's it. I have no Wcmicons.dll
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2m^2
So that's it. I have no Wcmicons.dll
You expect my demo app to display icons although there are no icons. Well I cannot conjure the command icons :-D

Why did you delete the icon library? Are there any other files that you deleted? Maybe Totalcmd.exe :mrgreen:
User avatar
m^2
Power Member
Power Member
Posts: 1413
Joined: 2006-07-12, 10:02 UTC
Location: Poland
Contact:

Post by *m^2 »

Lefteous wrote:2m^2
So that's it. I have no Wcmicons.dll
You expect my demo app to display icons although there are no icons. Well I cannot conjure the command icons :-D

Why did you delete the icon library? Are there any other files that you deleted? Maybe Totalcmd.exe :mrgreen:
I thought they're built into your app.
Why shuldn't I detete wcmicons? I use 2 of them and don't need the rest.
User avatar
majkinetor !
Power Member
Power Member
Posts: 1580
Joined: 2006-01-18, 07:56 UTC
Contact:

Post by *majkinetor ! »

Hm...

I guess you used this:
fType
Unsigned integer that contains the menu type. This can be one of the following values.
IMFT_RADIOCHECK
Displays checked menu items using a radio button mark instead of a check mark if the hbmpChecked member is NULL.
ITs similar solution like with checkboxes, with possible little variations.... How large bitmaps can you set using this ?

I uploaded AHK code for you so you can check out the AHK source if you are interested and see how things work in real life.

Here
Run MenuTest.ahk and use ALT M shortcut. Take a look at "For Chris" folder and about.txt for some notes about the code.
Habemus majkam!
Post Reply