Need Help Creating a "MainMenu" on a Userform using API calls.

Pastor

New Member
Joined
Jun 23, 2010
Messages
20
I am trying to create a “mainmenu”
On a Userform using API calls.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Created a Userform and named it Form1.
Added a command button to the form and
named it Command1.
<o:p> </o:p>
In THISWORKBOOK code:
<o:p> </o:p>
Code:
[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Private Sub Workbook_Open()[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Form1.Show[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]End Sub[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5][Code/][/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]In FORM1 code module code:[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5][Code][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Private Sub Command1_Click()[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Dim Form1Handle As Long[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Dim MainMenuHandle As Long[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Dim ReturnValue As Long[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Dim PopUpMenuHandle As Long[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]'Get a handle for the active form[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Form1_Handle = GetActiveWindow()[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]'Create a main menu and hold on to its handle[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]MainMenuHandle = CreateMenu()[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]'Add the main menu to the form[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]ReturnValue = SetMenu(Form1Handle, MainMenuHandle)[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]‘Create a popupmenu and hold on to its handle[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]PopUpMenuHandle = CreatePopupMenu()[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]'Append the Popupmenu to the Main Menu[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]'ERROR OCCURS ON THE FOLLOWING LINE:[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]ReturnValue = AppendMenu(MainMenuHandle, MF_POPUP, PopUpMenuHandle, "&File")[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]'Draw the Main Menu on the form[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]ReturnValue = DrawMenuBar(Form1Handle)[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]End Sub[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5][Code/][/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]In code module coded:[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5][Code][/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Public Const MF_POPUP = &H10[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Public Declare Function GetActiveWindow Lib "user32" () As Long[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Public Declare Function CreateMenu Lib "user32" () As Long[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Public Declare Function CreatePopupMenu Lib "user32" () As Long[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" ( _[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]       ByVal hMenu As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]       ByVal wFlags As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]       ByVal wIDNewItem As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]       ByVal lpNewItem As String)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]       [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Public Declare Function SetMenu Lib "user32" ( _[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]       ByVal hwnd As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]       ByVal hMenu As Long) As Long[/FONT][/SIZE]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5][Code/][/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[SIZE=5][FONT=Times New Roman]I open the file and Form1 is shown with its command button.  [/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]When I click the command button I get an error: [/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]Run-time error ’49:[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Bad DLL calling convention.[/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=5]What is the correct convention?[/SIZE][/FONT]
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Andrew,

Thanks for responding.

I found and looked at that link before I tried coding my own.

I will have to set it aside for the weekend and get back to it in a few days.

God Bless & Thanks again.
 
Upvote 0
Thanks Andrew for the reference. I sometime feel guilty in getting such charitable help. so i hoe this helps someone who will follow me.

The following it meant to be an example of how to create a simple menu on a user form using API calls. I hopw that someone can benefit form this example...

In ThisWorkBook code:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Code:
[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Private Sub Workbook_Open()[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        Ask_A_Question[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]End Sub[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]
<o:p> </o:p>
In form named fMainMenu code:
<o:p> </o:p>
Code:
[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Option Explicit[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Clean_Up[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]End Sub[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]Private Sub UserForm_Terminate()[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Safety_Clean_Up[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]End Sub[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]
<o:p> </o:p>
In code module code:
<o:p> </o:p>
Code:
[/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Option Explicit[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function CreateMenu Lib "user32" () As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function CreatePopupMenu Lib "user32" () As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function FindWindow Lib "user32" _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            Alias "FindWindowA" ( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal lpClassName As String, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal lpWindowName As String) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function AppendMenu Lib "user32" _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            Alias "AppendMenuA" ( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal hMenu As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal wFlags As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal wIDNewItem As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal lpNewItem As String) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function SetMenu Lib "user32" ( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal hwnd As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal hMenu As Long) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function SetWindowLong Lib "user32" _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            Alias "SetWindowLongA" ( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal hwnd As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal nIndex As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal dwNewLong As Long) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]                            [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function CallWindowProc Lib "user32" _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            Alias "CallWindowProcA" ( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal lpPrevWndFunc As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal hwnd As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal msg As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal wParam As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal lParam As Long) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function DrawMenuBar Lib "user32" _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            (ByVal hwnd As Long) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]                            [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    Public Declare Function DestroyMenu Lib "user32" ( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                            ByVal hMenu As Long) As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    'PUBLIC DECLARATIONS[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Const GWL_WNDPROC = (-4)[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public fMainMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public lMainMenuHandle As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]                            [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    'MODULE LONG DECLARATIONS[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Dim lPreviousProcedure As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub Ask_A_Question()[/FONT][/SIZE]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[SIZE=5][FONT=Times New Roman]        'DEFINE INTEGERS[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim iMsgBoxResponse As Integer[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]           [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Ask the User if he/she wants to use see the MainMenu[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        iMsgBoxResponse = MsgBox( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                          "Do you want to see the Main Menu?", _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                          vbYesNoCancel + vbDefaultButton3, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                          "Go To MAin Menu?")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Anaylze the user's response[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        If iMsgBoxResponse = vbYes Then[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]           'Call a routine to initialize the form with the[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]           'main menu on it[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]           Initialize_fMainMenu[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]           [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]           'Show the Main Menu form with its new main menu[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]           fMainMenu.Show[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]           [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        End If[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub Initialize_fMainMenu()[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'CONSTANT DECLARATIONS[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        Const MF_POPUP = &H10[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Const MF_STRING = &H0[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Const MF_SEPARATOR As Long = &H800&[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'LONG DECLARATIONS[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim fMainMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lMainMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lFileMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lMusicMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lHelpMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lMoreMenuHandle As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lReturnCode As Long[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim lUniqueId As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Initialize lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = 0[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Get the UserForm's Handle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        fMainMenuHandle = FindWindow(vbNullString, fMainMenu.Caption)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]  [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Create a Menu and get its handle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lMainMenuHandle = CreateMenu()[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put the MainMenu on the fMainMenu form[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = SetMenu(fMainMenuHandle, lMainMenuHandle)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Create the FILE menu item and get its handle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lFileMenuHandle = CreatePopupMenu()[/FONT][/SIZE]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[SIZE=5][FONT=Times New Roman]        'Put the FileMenuHandle into the MainMenu on the frmForm and label it "File"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMainMenuHandle, MF_POPUP, lFileMenuHandle, "File")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "Save" on the "FILE" menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lFileMenuHandle, MF_STRING, lUniqueId, "Save")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a SEPARATOR mark into the Menu after the "Save" item under "File"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lFileMenuHandle, MF_SEPARATOR, &O0, vbNullString)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "Exit" on the "FILE" menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lFileMenuHandle, MF_STRING, lUniqueId, "Exit")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]          [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Create the MUSIC menu item and get its handle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lMusicMenuHandle = CreatePopupMenu()[/FONT][/SIZE]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[SIZE=5][FONT=Times New Roman]        'Put the MusicMenuHandle into the MainMenu on the frmForm and label it "Music"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMainMenuHandle, MF_POPUP, lMusicMenuHandle, "Music")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "Lyrics" on the "Music" menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMusicMenuHandle, MF_STRING, lUniqueId, "Lyrics")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "PlayLists" on the "Music" menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMusicMenuHandle, MF_STRING, lUniqueId, "Playlists")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "Songs" on the "Music" menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMusicMenuHandle, MF_STRING, lUniqueId, "Songs")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]            [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a SEPARATOR mark into the Main Menu after the "Music" item[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMainMenuHandle, MF_SEPARATOR, &O1, vbNullString)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Create the HELP menu item and get its handle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lHelpMenuHandle = CreatePopupMenu()[/FONT][/SIZE]
<o:p>[FONT=Times New Roman][SIZE=5] [/SIZE][/FONT]</o:p>
[SIZE=5][FONT=Times New Roman]        'Put the HelpMenuHandle into the MainMenu on the frmForm and label it "Help"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMainMenuHandle, MF_POPUP, lHelpMenuHandle, "Help")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]       [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Create the MORE menu item and get its handle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lMoreMenuHandle = CreatePopupMenu()[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put the More menu item into the Help[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lHelpMenuHandle, MF_POPUP, lMoreMenuHandle, "More...")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "About" on the "More..." menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMoreMenuHandle, MF_STRING, lUniqueId, "About")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Increment lUniqueID[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lUniqueId = lUniqueId + 1[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Put a submenu item named "Code" on the "More..." menu.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lReturnCode = AppendMenu(lMoreMenuHandle, MF_STRING, lUniqueId, "Code")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]         [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Have windows redraw the form with the new Main Menu[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        DrawMenuBar fMainMenuHandle[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Swap the default procedure with the MenuEventsProcedure[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        lPreviousProcedure = SetWindowLong( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                              fMainMenuHandle, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                              GWL_WNDPROC, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                              AddressOf MenuEventsProcedure)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '***********************************************************[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '* MENUEVENTSPROCEDURE                                     *[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '* If the user has clicked on one of the menu items        *[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '* then operating system passes the value of WM_COMMAND    *[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '* as the value of uMsg and passes the menu item's ID as   *[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '* the value of wParam.                                    *[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    '***********************************************************[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Function MenuEventsProcedure( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    ByVal hwnd As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    ByVal uMsg As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    ByVal wParam As Long, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    ByVal lParam As Long) As Long[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]                    [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'CONSTANT DECLARATIONS[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Const WM_COMMAND = &H111[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'STRING DECLARATIONS[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        Dim sMacroName As String[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Determine if a menu Item was selected.[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        If uMsg = WM_COMMAND Then[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]            'Calculate the name of the macro to run based on[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]            'the value of wPran[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]            Select Case wParam[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 1[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "File_Save"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 2[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "File_Exit"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 3[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "Music_Lyrics"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 4[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "Music_Playlists"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 5[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "Music_Songs"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 6[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "More_About"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                   Case 7[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                    sMacroName = "More_Code"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]            End Select[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]            [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]            'Get the name of the Macro to run[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]            Application.Run sMacroName[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]        [/SIZE][/FONT]
[SIZE=5][FONT=Times New Roman]        'Swap this procurde aout ans use the previous[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        'procedure[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MenuEventsProcedure = CallWindowProc( _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                              lPreviousProcedure, _[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]                              hwnd, uMsg, wParam, lParam)[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Function[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub Clean_Up()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        DestroyMenu lMainMenuHandle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        SetWindowLong fMainMenuHandle, GWL_WNDPROC, lPreviousProcedure[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub Safety_Clean_Up()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        DestroyMenu lMainMenuHandle[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        SetWindowLong fMainMenuHandle, GWL_WNDPROC, lPreviousProcedure[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub File_Save()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the File_Save routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub File_Exit()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the File_Exit routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub Music_Lyrics()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the Music_Lyrics routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub Music_Playlists()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the Music Playlists routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]     Public Sub Music_Songs()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the Music Songs routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    Public Sub More_About()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the More About routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]     Public Sub More_Code()[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]        MsgBox "This is the More Code routine"[/FONT][/SIZE]
[SIZE=5][FONT=Times New Roman]    End Sub[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=5]

This thread has come to a conclusion.

thank you one and all.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top