Results 1 to 9 of 9

Thread: hairpulling popup menus

  1. #1

    Thread Starter
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    Unhappy hairpulling popup menus

    I know this one's probably easy, but I can't figure it out.
    Here it goes : I wanna use a popup (context) menu on one of my textboxes. How do I override the default Windows popup menu that comes up (the one with "Copy", "Paste" and so on) ?

    Plz take a look at this :
    VB Code:
    1. Private Sub Text49_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     If Button = 2 Then Call Me.PopupMenu(FAddress)
    3. End Sub
    But when I right click on my textbox, first the default Windows menu pops up. I have to right click it one more time and only then my "FAddress" menu pops up.
    Does NE1 have a solution for me ?
    Can it only be done with API ? Or is there a simpler way out ?

    TIA

  2. #2
    Si_the_geek
    Guest
    try using mouseDOWN, as that is when the Windows standard menu pops up

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function LockWindowUpdate Lib "User32" (ByVal hwndLock As Long) As Long
    2.            
    3. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.            If Button = vbRightButton Then
    5.            'lock the text box for my personal use
    6.            LockWindowUpdate Text1.hWnd
    7.            'the text box MUST be disabled to
    8.            'prohibit default popup menu
    9.            Text1.Enabled = False
    10.            PopupMenu mnuFile   'your popup menu name
    11.            'this releases the lock
    12.            LockWindowUpdate 0&
    13.            'naturally, after my popup menu is displayed
    14.            'it must be reenabled to allow input
    15.            Text1.Enabled = True
    16.         End If
    17. End Sub

  4. #4
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160
    Hey cool. I've been wondering about this myself.

  5. #5

    Thread Starter
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    HACK, thank you , BUT >>>

    OK Hack, I did it like you said :
    VB Code:
    1. Private Sub Text49_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     If Button = vbRightButton _
    3.     Then
    4.             LockWindowUpdate Text49.hwnd
    5.             Text49.Enabled = False
    6.             Me.PopupMenu FAddress
    7.             LockWindowUpdate 0&
    8.             Text49.Enabled = True
    9.     End If
    10. End Sub
    and it works fine, but what if my Text49 had the focus while right-clicking upon it ? I tried it and my textbox lost the focus. The focus was passed to the next control in the TabStop order. And I don't want that. Can't it be done without disabling the textbox somehow ?
    TIA

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    You could just do a text49.setfocus afterwards.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7

    Thread Starter
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    Thumbs down unacceptable :-(

    SLH >>
    Thank you but as you know, any code following the popup method is not executed until the user had eather selected something form the popup menu or he/she had disabled the popup menu. In my case, when my Text49 loses the focus it is extremely visible on my interface, as another textbox gets the focus and changes its background color.
    The scenario goes like this :
    - Text49 has the focus (it is vividly colored)
    - user right clicks on Text49
    - my custom popup menu appears
    - at the same time, text49 loses focus (no more color) and ANOTHER textbox gets the focus (and gets vividly colored)

    I don't like that. Any more suggestions please ? TIa

  8. #8
    GingerFreak
    Guest
    You could always use a rich text box instead of the normal text
    box because it doesn't display a popupmenu unless you set
    Autoverbmenu to true. This is how i do it

  9. #9

    Thread Starter
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    Thumbs up subclassing is the answer

    ok everybody, I found an ellegant solution to my problem. For NE1 interested, this is a good link :
    Subclass textboxes to display custom popups menus
    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width