Solved

Is it possible to change menu runtime using API?

Posted on 2004-10-05
4
237 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now