How do you add a Menu item through Code?
Quote from: BaDDBLooD on August 24, 2004, 09:58 PM
How do you add a Menu item through Code?
See PluginMenu (http://www.valhallalegends.com/pub/BCP/SDK/PluginMenu/). C++, but very straight-forward for porting if you know VB.
Thanks, but i can't port from c++ to VB yet.
Depending on what your adding, you can create menu items, set them not visible by default, then change the caption/visibility during runttime.
Yeah but, i dont want waisted menu items :O
Set the index to 0, and load new instances of it every time you want another menu (?)
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.
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...
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 */
?
Nope.. not sure what a CRT File is lmao
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.
Could you explain that in less complex terms?
Quote from: BaDDBLooD on August 25, 2004, 06:27 PM
Could you explain that in less complex terms?
www.google.com.
You don't need to worry about WINAPI (__stdcall (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core___stdcall.asp)). 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.