Print Page | Close Window

Creating a Popup Menu

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=9128
Printed Date: 08 October 2024 at 10:46am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Creating a Popup Menu
Posted By: Neil
Subject: Creating a Popup Menu
Date Posted: 17 December 2007 at 7:59pm
I want to create a popup menu (through code - NOT the designer), and  (if possible) to be able to add KeyBindings (i.e. hot keys) to the pop up menus.


1). I can see a PopupControl in the documentation, but I cannot locate it in the object hierarchy - also,  the VB6 object browser cannot locate it (search for PopupControl fails to find it) - so it is not clear how to create/use this control

2). I am aware (after searching this forum's archives), that there is a VB6 sample that apparently shows how to do the above - (atleast - how to show popups). However, I have not been able to find an example that shows popup creation in code (i.e. without the help of teh designer).

Anyone knows how to do this?



Replies:
Posted By: ijwelch
Date Posted: 17 December 2007 at 9:36pm
Here's a basic popup menu:

Dim oBar As XtremeCommandBars.CommandBar
Dim oControl As XtremeCommandBars.CommandBarControl
Dim oPopup As XtremeCommandBars.CommandBarPopup

Set oBar = CommandBars1.Add("Popup Toolbar Name", xtpBarPopup)
With oBar.Controls
    'standard items
    .Add xtpControlButton, ID_ITEM1, "Item1"
    .Add xtpControlButton, ID_ITEM2, "Item2"
    .Add(xtpControlButton, ID_ITEM3, "Item3").BeginGroup = True
    'checkbox
    Set oControl = .Add(xtpControlCheckBox, ID_ITEM4, "Checkbox")
    oControl.Checked = True
    oControl.BeginGroup = True
    'sub-menu
    Set oPopup = .Add(xtpControlPopup, ID_ITEM5, "Sub Menu")
    With oPopup.CommandBar.Controls
        .Add xtpControlButton, ID_SUBITEM1, "SubItem1"
        .Add xtpControlButton, ID_SUBITEM2, "SubItem2"
    End With
End With
'show it
oBar.ShowPopup


Keybindings are included in the VB RibbonSample (in Form_Load event).



Posted By: Neil
Date Posted: 18 December 2007 at 5:46am
Fantastic!. This is EXACTLY what I needed. BTW, I do not have the RibbonSample. Could you please include a few lines of code that show how to use keybindings (hotkeys) with  PopupMenu?

MTIA


Posted By: ijwelch
Date Posted: 18 December 2007 at 6:01am
Yep,

These lines add the keybindings:

    CommandBars.KeyBindings.Add FCONTROL, Asc("N"), ID_FILE_NEW
    CommandBars.KeyBindings.Add FCONTROL, Asc("O"), ID_FILE_OPEN
    CommandBars.KeyBindings.Add FCONTROL, Asc("S"), ID_FILE_SAVE
    CommandBars.KeyBindings.Add FCONTROL, Asc("X"), ID_EDIT_CUT
    CommandBars.KeyBindings.Add FCONTROL, Asc("C"), ID_EDIT_COPY
    CommandBars.KeyBindings.Add FCONTROL, Asc("V"), ID_EDIT_PASTE

And these constants define the values for special keys:

Public Const FSHIFT = 4
Public Const FCONTROL = 8
Public Const FALT = 16

Public Const VK_BACK = &H8
Public Const VK_TAB = &H9
Public Const VK_ESCAPE = &H1B
Public Const VK_SPACE = &H20
Public Const VK_PRIOR = &H21
Public Const VK_NEXT = &H22
Public Const VK_END = &H23
Public Const VK_HOME = &H24
Public Const VK_LEFT = &H25
Public Const VK_UP = &H26
Public Const VK_RIGHT = &H27
Public Const VK_DOWN = &H28
Public Const VK_INSERT = &H2D
Public Const VK_DELETE = &H2E
Public Const VK_MULTIPLY = &H6A
Public Const VK_ADD = &H6B
Public Const VK_SEPARATOR = &H6C
Public Const VK_SUBTRACT = &H6D
Public Const VK_DECIMAL = &H6E
Public Const VK_DIVIDE = &H6F
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public Const VK_F12 = &H7B


Posted By: Neil
Date Posted: 18 December 2007 at 8:11am
Once again, thanks very much for your help


Posted By: Ayub
Date Posted: 09 January 2008 at 5:56am
Can we get C++ code for the same?



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net