Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

how to unload popup menu?

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
vmano
Asked:
vmano
  • 6
  • 5
  • 2
1 Solution
 
watyCommented:
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
 
vmanoAuthor Commented:
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
 
watyCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vmanoAuthor Commented:
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
 
watyCommented:
Give me your e-mail, I will send you the code for that.

0
 
vmanoAuthor Commented:
here is my e-mail : vmano@hotmail.com

thanks for the response,
vmano
0
 
watyCommented:
I have sended it to you
0
 
vmanoAuthor Commented:
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
 
vmanoAuthor Commented:
Waty,
I am still waiting on your input as to how to use/proceed with your code.

vmano
0
 
watyCommented:
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
 
israelwCommented:
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
 
israelwCommented:
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
 
vmanoAuthor Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now