Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2005, 02:39 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default Images in menus

Is it possible to add images to my existing vb6 menus like you can find in most of microsoft's programs?

 
Old April 21st, 2005, 02:52 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Yes. It requires the use of APIs to do so though. (The means to do this is not contained in VB, but VB will link to the Windows libraries which can.)
 
Old April 22nd, 2005, 02:53 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default

Thanx Brian, I found three functions that can do what I want. Three public functions called SetMenuBitmapImage, GetMenu, GetSubMenu.

 
Old April 22nd, 2005, 07:10 AM
Authorized User
 
Join Date: Jan 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JelfMaria
Default

can u send me that public functions so that i can also include images in my menu based applications

 
Old April 22nd, 2005, 07:25 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default

Sure ...

The code is as follows. I simplified it abit to only work on a single menu-submenu set but you can easily modify it to work on more than one.

Open a new project and add a single menu to you project using the Menu Editor. In the Caption of the initial menu type in "Menu" and call it "mnuOne", then add a submenu to "Menu" and call it "mnuTwo". Then go into code view and type the follow:

Option Explicit

    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 (single line)
    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long (single line)

    ' Constant for SetMenuItemBitmaps
    Private Const MF_BYPOSITION = &H400&

    ' Constant for LoadImage
    Private Const IMAGE_BITMAP = &O0
    Private Const LR_LOADFROMFILE = 16
    Private Const LR_CREATEDIBSECTION = 8192

Private Sub Form_Load()

    Dim hMenu As Long
    Dim hSubMenu As Long
    Dim hMenuImg As Long
    Dim sFileName As String

    ' Get the bitmap
    sFileName = App.Path & "\Icons\program.bmp"
    hMenuImg = LoadImage(0, sFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
    ' Get the menu item handle
    hMenu = GetMenu(Me.hwnd)
    hSubMenu = GetSubMenu(hMenu, 0)
    ' Set the "mnuTwo" bitmap to the one that is loaded in memory
    Call SetMenuItemBitmaps(hSubMenu, 3, MF_BYPOSITION, hMenuImg, 0)

End Sub

This article was originally posted on vbrun - microsoft

 
Old April 22nd, 2005, 11:07 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Were there specifics on the properties of the bitmaps that are usable?
32 × 32 only?
16 × 16 only?
Color resolution limits?
 
Old April 23rd, 2005, 03:09 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default

Ah, sorry Brian! The image size should be 10x10 bitmap, color depth does not matter although I use grayscale for better quality. This has been updated in Visual Basic 8 / .Net which allows you to use 24-bit true color images.

Hope the script helps

 
Old April 25th, 2005, 06:27 AM
Authorized User
 
Join Date: Jan 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JelfMaria
Default

The code is not displaying the menu image for me.
I am getting the menu but no image.
The menu icon I used is the floppyicon .
Why is it not working for me?



 
Old April 25th, 2005, 09:04 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default

Hi JelfMaria ... it might be because I'm referring to a folder called \icons\ on my c-drive. Make sure that you are referring to the exact path to where you are storing your image and not that you are using my path!

If it still does not work just post your script so I can see what might be going wrong.

 
Old April 26th, 2005, 12:40 AM
Authorized User
 
Join Date: Jan 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JelfMaria
Default

You are mentioning only app.path so i think it wont be a problem and i stored Icons folder in app.path.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Load Images from and Save Images to a Database cyndie VB.NET 2 August 17th, 2008 06:42 AM
sub menus matshediso HTML Code Clinic 2 January 31st, 2005 05:15 AM
Javascript menus alancdude Javascript 5 November 26th, 2003 11:58 AM
sliding menus Adam H-W Javascript 3 November 18th, 2003 09:38 AM
Menus Frank Schmuck BOOK: Beginning ASP.NET 1.0 1 June 6th, 2003 01:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.