Menu Icons

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Afraid my code does a lot more than that one. Hence the difference in size! :)

Yours will set the standard menuitem bitmaps which are very inflexible and I don't think can be resized.

The code I posted will allow icons of any size, will colour menu items and so on! Slight adjustments and different menu items can be coloured differently and have different heights etc.
I may look like a mule, but I'm not a complete ass.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

srod wrote:Afraid my code does a lot more than that one. Hence the difference in size! :)

Yours will set the standard menuitem bitmaps which are very inflexible and I don't think can be resized.

The code I posted will allow icons of any size, will colour menu items and so on! Slight adjustments and different menu items can be coloured differently and have different heights etc.
Okay, that's cool! :D
I like logic, hence I dislike humans but love computers.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

Very nice code srod!

Like to see more if this type of work.

- np
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Just messing with menu's and tried this out but for some reason LoadImage_() is always returning a null, anyone know why, I'm assuming that the code is loading a system icon but I don't know from where?

Using xp home sp2, but I doubt if that is the problem.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Derek, the two load image commands in the example code are loading two external icons; 'open.ico' and 'save.ico'.

If you're going to use this particular example, then you need to switch these icons for two of your own, i.e. two lying around your hard drive! Just replace my two icons with the full path/name of your own.

In proper applications I shove all icons in the resource section of the exe etc.
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Ah, I see. I went looking for the ico files but couldn't find them and assumed they were in another file and that the system had access to them.

Thanks for clearing that up.

I really should read more about api calls. :)
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Wonderful code there :)

I've a question: how do you draw the separation lines?, because they are not owner-drawn in your example, right?. I'd like to draw them as well so I can make them match my menu color but I don't really know where to look at to begin with.

In fact I'm getting a headache :P

:lol: should I bash the keyboard and give up?
:?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I haven't looked at the code for a while but I seemed to recall only drawing the command items rather than all aspects of the menus etc. This is something which I should rectify, but the truth is that I no longer use this code etc. I use an external menu library instead.

If you wish to ownerdraw the separators then you'll need to change the line :

Code: Select all

ModifyMenu_(GetMenu_(hWnd),item,#MF_BYCOMMAND|#MF_OWNERDRAW,item,icon) 
to

Code: Select all

ModifyMenu_(GetMenu_(hWnd),item,#MF_BYREFERENCE|#MF_OWNERDRAW,item,icon) 
and then make sure that for each menu item, the 'item' value passed to the AddMenuIcon() function is the positional index and the command index etc. (See the api guide for an explanation of this).

Once this is done you will receive #WM_MEASUREITEM and #WM_DRAWITEM messages for separators as well as comand items etc.
I may look like a mule, but I'm not a complete ass.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Menu Icons

Post by skywalk »

Hi,
Any way to right justify the last main menu item?
Most often, this is the Help menu.
I am trying to preserve the look and feel of my VB6 apps which followed this convention.
The VB6 code manipulates the menu at form load event by calling API functions "Get and SetMenuItemInfo".
I am too new a user to verify even where to begin doing this.
Post Reply