I am trying to create a “mainmenu”
On a Userform using API calls.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
Created a Userform and named it Form1.
Added a command button to the form and
named it Command1.
<o> </o>
In THISWORKBOOK code:
<o> </o>
On a Userform using API calls.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
Created a Userform and named it Form1.
Added a command button to the form and
named it Command1.
<o> </o>
In THISWORKBOOK code:
<o> </o>
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]