Solved

Is it possible to change menu runtime using API?

Posted on 2004-10-05
4
252 Views
Last Modified: 2010-05-02
Hi EveryOne,
Otherday I had a interview. They asked me few questions, some question needs extensive knowledge. Which i don't have being a newbie...

I would like to get remarks from experts on these questons (Visual Basic 6 OR .NET)


- Is it possible to change menu runtime using API?

Regards,
0
Comment
Question by:ExpertPro
  • 2
4 Comments
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 200 total points
ID: 12231350
You can change menu items during runtime using API calls, yes.

You would use the "SendMessage" API routine.

BFN,

fp.
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 300 total points
ID: 12235548
Here is sample

'Download the full source+pictures+.. at http://www.allapi.net/php/redirect/redirect.php?action=download&id=13
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Const MF_BITMAP = 4
Const MF_CHECKED = 8
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim hMenu As Long, hSubMenu As Long, lngID As Long

    'Get the handle of the form's menu
    hMenu = GetMenu(Me.hWnd)
    'Get the handle of the form's submenu
    hSubMenu = GetSubMenu(hMenu, 0)

    'Change first item (index=0)
    picBitmaps(0).Picture = picBitmaps(0).Image
    lngID = GetMenuItemID(hSubMenu, 0)
    Call ModifyMenu(hMenu, lngID, MF_BITMAP, lngID, CLng(picBitmaps(0).Picture))

    'Change second item (index=1)
    picBitmaps(1).Picture = picBitmaps(1).Image
    lngID = GetMenuItemID(hSubMenu, 1)
    Call ModifyMenu(hMenu, lngID, MF_BITMAP, lngID, CLng(picBitmaps(1).Picture))

    'Change third item (index=2)
    picBitmaps(2).Picture = picBitmaps(2).Image
    lngID = GetMenuItemID(hSubMenu, 2)
    Call ModifyMenu(hMenu, lngID, MF_BITMAP, lngID, CLng(picBitmaps(2).Picture))

    mnuBitmap1.Checked = True
End Sub
Private Sub mnuBitmap1_Click()
    mnuBitmap1.Checked = Not mnuBitmap1.Checked
End Sub
Private Sub mnuBitmapEnd_Click()
    End
End Sub
0
 
LVL 1

Author Comment

by:ExpertPro
ID: 12331150
Thanks everyone for help!
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 12332673
You're welcome.

Hope you passed the interview.

BFN,

fp.
[ http://NigelLee.info ]
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question