• Welcome to Valhalla Legends Archive.
 

Adding Menu Items?

Started by BaDDBLooD, August 24, 2004, 09:58 PM

Previous topic - Next topic

BaDDBLooD

How do you add a Menu item through Code?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Spht

Quote from: BaDDBLooD on August 24, 2004, 09:58 PM
How do you add a Menu item through Code?

See PluginMenu.  C++, but very straight-forward for porting if you know VB.

BaDDBLooD

Thanks, but i can't port from c++ to VB yet.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

The-FooL

Depending on what your adding, you can create menu items, set them not visible by default, then change the caption/visibility during runttime.

BaDDBLooD

Yeah but, i dont want waisted menu items :O
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Eli_1

Set the index to 0, and load new instances of it every time you want another menu (?)

Spht

Quote from: BaDDBLooD on August 24, 2004, 10:46 PM
Thanks, but i can't port from c++ to VB yet.

Did you try?  Or are you assuming you can't?  As I said, the PluginMenu module is VERY straight-forward for porting.  You basically just need to know VB and have API Viewer on hand.  Example (since you probably still don't have enough courage to go and port it all on your own):

HMENU FindPluginMenu(HMENU hMainMenu)
{
   UINT MenuItems = GetMenuItemCount(hMainMenu);

   for(UINT i = 0; i < MenuItems; i++) {
       int MenuStringSize;
       LPSTR MenuString = new CHAR[MenuStringSize = GetMenuString(hMainMenu, i, 0, 0, MF_BYPOSITION)+1];
       if(GetMenuString(hMainMenu, i, MenuString, MenuStringSize, MF_BYPOSITION)
           && !strcmp(MenuString, PLUGIN_MENU_NAME)) {
           delete [] MenuString;
           return GetSubMenu(hMainMenu, i);
       }

       delete [] MenuString;
   }

   // Menu not found, create it

   HMENU PopupMenu = CreateMenu();

   AppendMenu(hMainMenu, MF_STRING | MF_POPUP, (UINT_PTR)PopupMenu, PLUGIN_MENU_NAME);

   return PopupMenu;
}


Function FindPluginMenu(ByVal hMainMenu As Long) As Long
   Dim MenuItems As Long
   Dim MenuString As String
   Dim MenuStringSize As Long
   Dim i As Long

   MenuItems = GetMenuItemCount(hMainMenu)
   For i = 0 To MenuItems
       MenuStringSize = GetMenuString(hMainMenu, i, 0, 0, MF_BYPOSITION)
       MenuString = String(MenuStringSize, vbNullChar)
       If GetMenuString(hMainMenu, i, MenuString, MenuStringSize, MF_BYPOSITION) Then
           If Left$(MenuString, InStr(MenuString, vbNullChar) - 1) <> PLUGIN_MENU_NAME Then FindPluginMenu = GetSubMenu(hMainMenu, i)
       End If
   Next i

   If FindPluginMenu = 0 Then
       ' Menu not found, create it
       Dim PopupMenu As Long

       PopupMenu = CreateMenu()
       AppendMenu hMainMenu, MF_STRING Or MF_POPUP, PopupMenu, PLUGIN_MENU_NAME
       FindPluginMenu = PopupMenu
   End If
End Function


That should get you started.  If you take the time to carefully read through the code, you'll realize it is quite simple.  Now go do the rest.

BaDDBLooD

Relying on your example *HEAVILY*, i managed to come out with this.



Function FindPluginMenu(ByVal hMainMenu As Long) As Long
   Dim MenuItems As Long
   Dim MenuString As String
   Dim MenuStringSize As Long
   Dim i As Long

   MenuItems = GetMenuItemCount(hMainMenu)
   For i = 0 To MenuItems
       MenuStringSize = GetMenuString(hMainMenu, i, 0, 0, MF_BYPOSITION)
       MenuString = String(MenuStringSize, vbNullChar)
       If GetMenuString(hMainMenu, i, MenuString, MenuStringSize, MF_BYPOSITION) Then
           If Left$(MenuString, InStr(MenuString, vbNullChar) - 1) <> PLUGIN_MENU_NAME Then FindPluginMenu = GetSubMenu(hMainMenu, i)
       End If
   Next i

   If FindPluginMenu = 0 Then
       ' Menu not found, create it
       Dim PopupMenu As Long

       PopupMenu = CreateMenu()
       AppendMenu hMainMenu, MF_STRING Or MF_POPUP, PopupMenu, PLUGIN_MENU_NAME
       FindPluginMenu = PopupMenu
   End If
End Function

Function RemovePluginMenu(ByVal hMainMenu as Long) as Long
   Dim MenuItems as Long
   Dim Menustring as String
   Dim MenuStringSize as Long
   Dim i as Long

   For i = 0 To Menu Items
   MenuStringSize = GetMenuString(hMainMenu, i, 0, 0, MF_BYPOSITION)
   MenuString = String(MenuStringSize, vbNullChar)
   If GetMenuString(hMainMenu, i, MenuString, MenuStringSize, MF_BYPOSITION) Then
           If Left$(MenuString, InStr(MenuString, vbNullChar) - 1) <> PLUGIN_MENU_NAME Then DeleteMenu(hMainMenu, i, MF_BYPOSITION)
       End If
   Next I
End Function

Function CheckContiguousMenuID(ByVal Menu as Long, ByVal MenuID as Long, ByVal Required as Long) as Boolean
   Dim EndRange as Long
   EndRage = MenuID + Required
   Do
   If GetMenuState(Menu, MenuID+Required, MF_BYCOMMAND) <> -1 Then
       MenuID = EndRange
       CheckContiguousMenuID = False
   End If
   While Required = Required - 1   
   CheckContiguousMenuID = True
End Function



Dunno if that's right or not, but that's what i came up with.  Not sure on how to do the WINAPI Ones...
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

MyndFyre

Quote from: BaDDBLooD on August 25, 2004, 05:28 PM

Dunno if that's right or not, but that's what i came up with.  Not sure on how to do the WINAPI Ones...

Have you searched the CRT files for:


#define WINAPI /* the code value you're looking for to emulate */

?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

BaDDBLooD

Nope.. not sure what a CRT File is lmao
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

MyndFyre

Quote from: BaDDBLooD on August 25, 2004, 06:07 PM
Nope.. not sure what a CRT File is lmao

C runtime.  I believe the C runtime source is included in the Platform SDK for Win32.  I could be wrong, though.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

BaDDBLooD

Could you explain that in less complex terms?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

MyndFyre

Quote from: BaDDBLooD on August 25, 2004, 06:27 PM
Could you explain that in less complex terms?

www.google.com.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

UserLoser.

#13
You don't need to worry about WINAPI (__stdcall).  Visual Basic is nothing but Standard calls.  In VB, you can't really change the calling convention from stdcall to fastcall, cdecl, ect.  Therefore, you don't need to worry about setting the calling convention on your function to stdcall.