borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Print Resolution Problem - PLEASE HELP!)Next Topic (Line Control) New Topic New Poll Post Reply
AndreaVB Forum : VB General : icons in menus
Poster Message
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933

icon icons in menus  Archived to Disk

hello. is there anybody who can explain me the way to create menus like the MS Office ones, with icons at the left of the menu items?
I found some partial solutions, but I was not able to make at least one work. my best result was an icon only in the first menu, and the icon white color had a transparency that melted with the menu bar color.
my icons are stored in a .res file.
I can deepen my description of the ways I tried to who is interested in it.
thank you a lot.

____________________________
Real Programmer can count up to 1024 on his fingers

14-04-2002 at 05:05 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: icons in menus  Archived to Disk

I believe only bitmaps can be used in menus (you may have meant that). Icons either have strange results, crash, or just don't do anything.

14-04-2002 at 09:46 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: icons in menus  Archived to Disk

well, yesterday was sunday, and I finally succeed to make my bitmaps work. I stored them in a .res file (as .bmps), and found a single instruction to assign them to each menu item.
but still the color problem occurs: the menu background jumps up on the white fields of the icons (and anyway melts the other colors).
I am creating an euro-converter, and the bitmaps are the flags of the twelve countries that join it. the french, italian, irish, dutch, austrian flags would have a white field, but it is covered by the menu color, like the bitmap colors were transparent. now I needed to access to some background color property of the menu bar.
do you please have any hint on it?
thank you a lot again.

____________________________
Real Programmer can count up to 1024 on his fingers

15-04-2002 at 11:46 AM
View Profile Send Email to User Show All Posts | Quote Reply
cromo
Level: Guest

icon Re: Re: icons in menus  Archived to Disk

quote:
yronium wrote:
well, yesterday was sunday, and I finally succeed to make my bitmaps work. I stored them in a .res file (as .bmps), and found a single instruction to assign them to each menu item.
but still the color problem occurs: the menu background jumps up on the white fields of the icons (and anyway melts the other colors).
I am creating an euro-converter, and the bitmaps are the flags of the twelve countries that join it. the french, italian, irish, dutch, austrian flags would have a white field, but it is covered by the menu color, like the bitmap colors were transparent. now I needed to access to some background color property of the menu bar.
do you please have any hint on it?
thank you a lot again.

When I had to put a bitmap, in the toolbar, the transparent color was the one in the lower right corner... may be that can help.
Greetings!
15-04-2002 at 05:41 PM
| Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: icons in menus  Archived to Disk

thanks for the reply, cromo, but I didn't understand what you mean. Which toolbar do you mean? Could you be more clear (and pls excuse my dumbness)?
thanks

____________________________
Real Programmer can count up to 1024 on his fingers

16-04-2002 at 01:42 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: icons in menus  Archived to Disk

OK, I want to try a different way:
I have installed MS Office 2k and all its librairies. Which are the steps to create a menu bar as an Office CommandBars collection item (and later manage it), after made a reference to MS Office 9.0 Object Library in the Project menu?
If I do, I could create an Office menu within a VB project, but I don't know how. (In fact, I don't know how I can create any object from an exterior library, though I surfed a lot the MSDN without finding any complete step-by-step template). It seems to me that the VB Menu Editor is the only way to manage menus. Is there any way to create a menu bar OUT of the Menu Editor?
Is this interesting to anyone? Does this make sense?
ThanksALot.

____________________________
Real Programmer can count up to 1024 on his fingers

17-04-2002 at 12:47 PM
View Profile Send Email to User Show All Posts | Quote Reply
SteveG
Level: Sage


Registered: 15-04-2002
Posts: 56
icon Re: icons in menus  Archived to Disk

You could use the Windows API to do this.

See the article at the link below

www.vb-world.net/api/winapi2/index2.html

22-04-2002 at 08:48 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: icons in menus  Archived to Disk

it looks answer my question. I'll try to read and study it. God bless you anyway. For the moment I only find an ocx that does it, the DataDynamics ActiveBar, but I've only found a trial 30 days version (and the complete version is too expensive to me). Someone said me that I could write an ocx by myself, but I've not yet this strenght. We'll see...
For now, thank you a lot. I'll make you know.

____________________________
Real Programmer can count up to 1024 on his fingers

23-04-2002 at 12:01 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: icons in menus  Archived to Disk

ok, I followed that link, it explains in substance the system I used already. But that way brought me to have the bitmaps in my menu appearing transparent, and that is not good to me, as I must have flags in the menu, and I need exact flag colours, expecially the flags that contain the white colour.
In that tutorial there is a link to another tutorial (http://www.vbthunder.com/source/menu/ownmenu.htm).
I followed it completely, copied the code as explained there. When I run the form, I obtained a General Protection Fault "VB6 provoked an error C0000026H in the module KERNEL32.DLL..." I get this error in my home pc and in a laptop, both with VB6 and Win98, (I can give details on this error). So at the moment I don't know if the code works.
I tried to write to the owner of the site, to reach the author, but I get no answer. I think I won't, since on the site it's written "Copyright 1997-1999" (I guess the tutorial is very old).
Is there anybody who knows how to solve this?
Can anybody try to do the tutorial and tell me if it works (and if it does, what's wrong in my pc)?
Am I asking too much?
Thank you all.
P.S. Webmaster & JLRodgers, can you took an eye on my topic? I feel it very hard to many people, and I posted so many questions but still found no solution yet. Is it a solvable prob or is it reserved only to MS Lords?

____________________________
Real Programmer can count up to 1024 on his fingers

03-05-2002 at 09:15 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: icons in menus  Archived to Disk

I went to the site that you got the code from, entered it into VB.

It put the graphics next to the appropriate menus, however when the mouse was over an item, it wasn't highlighted, but it could be clicked.

You said that you got an error... Since I didn't get an error I can only assume that the code did as the person designed it.

As far as the error you're getting I'd suggest something: make sure you have Visual Basic SP5 (Service Pack 5). It may have corrected some problem that you're facing. Likewise, there may be a patch for Windows that may be the cause.


____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

04-05-2002 at 02:49 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: icons in menus  Archived to Disk

The following code would require 2picture boxes, and 1 imagelist to function, see the code for the names. It also requires 2 menus, any name (first menu with 3 items, second with 1):

Form:

Private Bitmaps As New CMenuBitmap

Option Explicit

Private Sub Form_Load()
    Dim tmp As String
    Dim ltmp As Long
    Set Bitmaps = New CMenuBitmap

' For an image list, first number is the menu number, ie file=0, edit=1
' second number is menu item 1=new, 2=spacer, 3=exit
    With Bitmaps
        .SetBitmap Me.hWnd, 0, 2, ImageList1.ListImages(2).Picture, ImageList1.ListImages(2).Picture
    End With

' For an ressource file you'll need an array of picture boxes 1 per picture
' then load the picture into the picturebox, then use the code above with modifications
    Picture1.Picture = LoadResPicture("1", 0)
    Picture2.Picture = LoadResPicture("Cut", 0)
    With Bitmaps
        .SetBitmap Me.hWnd, 0, 0, Picture1.Picture, Picture1.Picture
        .SetBitmap Me.hWnd, 1, 0, Picture2.Picture, Picture2.Picture
    End With
    
    Set Bitmaps = Nothing
End Sub

Private Sub menuFileEnvelope_Click()
' Only if you specify a different checked graphic will this make any difference
    menuFileEnvelope.Checked = Not menuFileEnvelope.Checked
End Sub


In a class named "CMenuBitmap":
Private Const MF_BYPOSITION = &H400&
Private Const MF_BYCOMMAND = &H0&

Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
Private Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long

Option Explicit

Public Function SetBitmap(ByVal hWnd As Long, ByVal TopMenuPos As Integer, ByVal OptionMenuPos As Integer, ByVal BitMapChecked As Long, ByVal BitMapUnChecked As Long) As String
    Dim lngMenuID As Long
    Dim lngSubMenuID As Long
    Dim tmp As String
    
    lngMenuID = GetMenu(hWnd)
    
    If lngMenuID > 0 Then
        lngSubMenuID = GetSubMenu(lngMenuID, TopMenuPos)
        If lngSubMenuID > 0 Then
            If SetMenuItemBitmaps(lngSubMenuID, OptionMenuPos, MF_BYPOSITION, BitMapChecked, BitMapUnChecked) <> 1 Then
                SetBitmap = "Unable to set bitmap"
            End If
        Else
            SetBitmap = "No Sub menus"
        End If
    Else
        SetBitmap = "No Menus"
    End If
' Create buffer
    tmp = Space( 128 )
    GetMenuString lngSubMenuID, OptionMenuPos, tmp, 127, MF_BYPOSITION

    SetBitmap = Trim(tmp)
End Function


____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

04-05-2002 at 03:00 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: icons in menus  Archived to Disk

Thank you JLRodgers, I'll go trying your code. I'll let you know. I'll go searching also the VB Service Pack 5.
You are as quick as usual. I guess what "guru" means.

____________________________
Real Programmer can count up to 1024 on his fingers

04-05-2002 at 03:04 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : icons in menus
Previous Topic (Print Resolution Problem - PLEASE HELP!)Next Topic (Line Control) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder