Solved

how to unload popup menu?

Posted on 1998-11-23
13
374 Views
Last Modified: 2009-12-16
In MSFlexGrid, i want to present different popup menu for each column when the user right-clicks on a column. my question is how to unload the present popup menu and show a different popup menu?? any sample code will be highly appreciated.

thanks in advance
vmano
0
Comment
Question by:vmano
  • 6
  • 5
  • 2
13 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1446373
You have to do as follow :

Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_USER = &H400&


SetForegroundWindow Me.hwnd            ' Set current window as ForegroundWindow
DisplayPopupMenu
PostMessage Me.hwnd, WM_USER, 0&, 0&   ' Update form...

0
 
LVL 3

Author Comment

by:vmano
ID: 1446374
WATY,
your code doesn't seem to be working. it's not at all unloading the present popup menu. do you have any other ideas???

here is what i did :

Private Sub fgrInBox_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

If Button = 2 Then
  SetForegroundWindow Me.hwnd  'Set current window as..
  PopupMenu mnuHide1
  PostMessage Me.hwnd, WM_USER, 0&, 0&   ' Update form...
End If

End Sub

am i doing some thing wrong?? please let me know. again thanks for your help

vmano
0
 
LVL 14

Expert Comment

by:waty
ID: 1446375
I use the code I provided you to hide the popup menu when the user click at another place.

NB : I create also my popup menu dynamically at runtime.

see the VBDiamon site (in my profile)
0
 
LVL 3

Author Comment

by:vmano
ID: 1446376
hi Waty,
sorry for not responding all these days. actually i was on vacation for thanksgiving. coming back to work, i couln't find any of the code for popupmenu in your web site. can you please show me the code for Creating a popupmenu with menu items, separators, submenus etc.. at run time??? and also i have another question -  is it possible to insert menu items at run time in to a menu which is created at design time? Please consider this comment and looking forward for a positive reply/answer. i will increase the points if you want.
thanks in advance,
vmano
 
 
0
 
LVL 14

Expert Comment

by:waty
ID: 1446377
Give me your e-mail, I will send you the code for that.

0
 
LVL 3

Author Comment

by:vmano
ID: 1446378
here is my e-mail : vmano@hotmail.com

thanks for the response,
vmano
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 14

Expert Comment

by:waty
ID: 1446379
I have sended it to you
0
 
LVL 3

Author Comment

by:vmano
ID: 1446380
hi waty,
thanks for the mail but can you please tell me how to proceed with it. i couldn't figure out what references/components i have to make to the project to get it work. for ex: Dim cPopMenu As New cPopupMenu, how will i get this to work? and what all images i have to include in the imagelist etc. etc..

thanks again for your continuous support,
vmano
0
 
LVL 3

Author Comment

by:vmano
ID: 1446381
Waty,
I am still waiting on your input as to how to use/proceed with your code.

vmano
0
 
LVL 14

Expert Comment

by:waty
ID: 1446382
Sorry for the delay, but I was on vacation

Here is a sample on how I create a menu :

Private Sub DisplayPopupMenuRTF(rtf As RichTextBox, bExtended As Boolean, nX As Single, nY As Single)
   ' *** Display a popupmenu for RTF
   
   Dim nIndex        As Long
   Dim nIconIndex    As Long
   Dim bEnabled      As Boolean

   Set clsPopupMenu = New cPopupMenu
   
   ' *** Initialise the Image List:
   clsPopupMenu.ImageList = ImageListRTF

   ' *** Initialise the hWndOwner (you must do this before showing a menu):
   clsPopupMenu.hWndOwner = Me.hwnd

   ' *** Add the menu Items
   nIconIndex = ImageListRTF.ListImages("SAVE").Index - 1
   clsPopupMenu.AddItem "&Save changes", , , , nIconIndex, , IIf(bRTFChange, True, False), "SAVE"
   
   clsPopupMenu.AddItem "-"

   If bExtended = False Then
      nIconIndex = ImageListRTF.ListImages("COLORIZE").Index - 1
      clsPopupMenu.AddItem "Colori&ze code", , , , nIconIndex, , IIf(Len(rtf.Text) = 0, False, True), "COLORIZE"
     
      nIconIndex = ImageListRTF.ListImages("UNDERSCORE").Index - 1
      clsPopupMenu.AddItem "Remove all u&nderscore", , , , nIconIndex, , IIf(Len(rtf.Text) = 0, False, True), "UNDERSCORE"
     
      clsPopupMenu.AddItem "-"
   End If
   
   If Len(rtf.SelText) = 0 Then
      bEnabled = False
   Else
      bEnabled = True
   End If
   nIconIndex = ImageListRTF.ListImages("DELETE").Index - 1
   clsPopupMenu.AddItem "&Delete", , , , nIconIndex, , bEnabled, "DELETE"

   nIconIndex = ImageListRTF.ListImages("CUT").Index - 1
   clsPopupMenu.AddItem "Cu&t", , , , nIconIndex, , bEnabled, "CUT"

   nIconIndex = ImageListRTF.ListImages("COPY").Index - 1
   clsPopupMenu.AddItem "&Copy", , , , nIconIndex, , bEnabled, "COPY"

   nIconIndex = ImageListRTF.ListImages("PASTE").Index - 1
   clsPopupMenu.AddItem "&Paste", , , , nIconIndex, , IIf(Clipboard.GetFormat(vbCFText), True, False), "PASTE"

   nIconIndex = ImageListRTF.ListImages("SELECTALL").Index - 1
   clsPopupMenu.AddItem "Select &All", , , , nIconIndex, , IIf(Len(rtf.Text) = 0, False, True), "SELECTALL"

   If bExtended = True Then
      ' *** Add Font formatiing
      clsPopupMenu.AddItem "-"
   
      nIconIndex = ImageListRTF.ListImages("BOLD").Index - 1
      clsPopupMenu.AddItem "&Bold", , , , nIconIndex, , bEnabled, "BOLD"
   
      nIconIndex = ImageListRTF.ListImages("UNDERLINE").Index - 1
      clsPopupMenu.AddItem "&Underline", , , , nIconIndex, , bEnabled, "UNDERLINE"
   
      nIconIndex = ImageListRTF.ListImages("ITALIC").Index - 1
      clsPopupMenu.AddItem "&Italic", , , , nIconIndex, , bEnabled, "ITALIC"
   
   End If
   
   clsPopupMenu.AddItem "-"
   
   nIconIndex = ImageListRTF.ListImages("SEARCH").Index - 1
   clsPopupMenu.AddItem "Searc&h", , , , nIconIndex, , IIf(Len(rtf.Text) = 0, False, True), "SEARCH"

   nIconIndex = ImageListRTF.ListImages("PRINT").Index - 1
   clsPopupMenu.AddItem "P&rint", , , , nIconIndex, , IIf(Len(rtf.Text) = 0, False, True), "PRINT"

   nIconIndex = ImageToolbar.ListImages("ABOUT").Index - 1
   clsPopupMenu.AddItem "A&bout", , , , nIconIndex, , , "ABOUT"

   nIndex = clsPopupMenu.ShowPopupMenu(nX, nY)

   If (nIndex > 0) Then
      Call TreatRTF(clsPopupMenu.ItemKey(nIndex), rtf)
   End If
   Set clsPopupMenu = Nothing

End Sub

0
 

Accepted Solution

by:
israelw earned 50 total points
ID: 1446383
dear Vmano!

hi, I want to answer your question but i don't know if you mean do this. so, just tell me after you see my solutio, if it's good.

(Sorry about my pure english language, I'm israeli)

ok!
first you have to create amenu with the menuaditor and make it visible = false. then you have to add a few (let's say 5) sub menus but without captions and all visible = true.

now, in the code you have todo this:
Private Sub grd1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then
        ClickedColumen = grd1.MouseCol
        ChangePopUpMenu ClickedColumen
    End If
End Sub

Private Sub ChangePopUpMenu(ByVal ClickedColumen As Integer)
 
   Select Case ClickedColumen
        Case 1
            GridPopUp(0).Caption = "a"
            GridPopUp(1).Caption = "b"
            GridPopUp(2).Visible = False
            PopUpMenu MainPopUp
        Case 2
            GridPopUp(0).Caption = "a"
            GridPopUp(1).Caption = "b"
            GridPopUp(2).Visible = True
            GridPopUp(2).Caption = "c"
            PopUpMenu MainPopUp
   End Select
End Sub

0
 

Expert Comment

by:israelw
ID: 1446384
hi!

i can to proposed another option with unload and load popupmenus
in the first answer is visible unvisible swap but second way is so:
1. you have to create at design time one main menu with visible=false.

2. add one submenu with index=0

3. in the monedown event in the grid use the mousecol property

4. and so:
  Select Case grd1.mousecol
    Case 1
      GridPopUp(0).Caption = "Option 1"
      load GridPopUp(1)
           GridPopUp(1).caption = "Option2"
      PopUpMenu MainPopUp
    Case 2
      GridPopUp(0).Caption = "a"
      load GridPopUp(1)
           GridPopUp(1).Caption = "b"
      load GridPopUp(2)
           GridPopUp(1).Caption = "c"
      PopUpMenu MainPopUp
  End Select
  for i=1 to gridpopup.count-1
     unload gridpopup(i)
  next i
End Sub

5. assume gridpopup it's the submenu

6. the for loop in the sub occure only after you hide the popup menu

be weel.
israelw

0
 
LVL 3

Author Comment

by:vmano
ID: 1446385
Hi Israelw,
thanks for your proposed answer and comment. I could not evaluate your proposed answer immediately as I was on vacation all these days. sorry for that. now, give me some time and i will let you know about your solution. thanks for the answer though.
vmano
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now