Solved

how to unload popup menu?

Posted on 1998-11-23
13
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

752 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