CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    [RESOLVED] Context menu for TextBox

    Hello 2 u, programmer :-)

    How can I get standard context menu of TextBox (ThunderTextBox) using VB6 and/or WinAPI and add my own menu item(s) to it?
    Someone wrote something like: "use standard menu from user32.dll, byt I can't recall the method."
    So the question is... How? How to realize the functionality? Is it real at least?

    P.S. The goal is to add custom item to standard context menu.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Context menu for TextBox

    If it's your program, it isn't hard. Somebody else's program is different
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Re: Context menu for TextBox

    Quote Originally Posted by dglienna View Post
    If it's your program, it isn't hard. Somebody else's program is different
    So... Where's the solution? Excuse me, but u wrote nothing except common words.

    The problem is:
    1. Where's no WM_INIT... messages it's only WM_CONTEXTMENU - so there's no handle to menu
    2. I don't know the resource identifier within system dll to direct load the menu
    And u said "it's not hard"... :-/

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Context menu for TextBox

    What he said was if it is your program it is not that hard but if it is someone elses it is a different story. Meaning if you wrote the program and have the source code it is fairly easy. If someone else wrote it and you do not have the source then that is another matter.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Re: Context menu for TextBox

    Gosh!
    Men don't you read my first post?
    I clearly noted "standard". Have I explain you "standard".

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Context menu for TextBox

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Re: Context menu for TextBox

    Quote Originally Posted by dglienna View Post
    Have you SEARCHED for an answer?
    Yes 2 days of searchin' via MSDN and internet (google, yandex, rambler).
    And I didn't find anythin except "supress context menu" or "create your own menu and substitu standard one". But the question is: "How to get standard menu and change it (append item)"...

    I apreciate your answers and hope your last link helps me.

  8. #8
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Question Re: Context menu for TextBox

    Unfortunately, I think, I can't understand that I need.
    Ok. Here's an attachment.
    The question still "How to do?"

    P.S. Sorry, I didn't specify that the application is mine. I need to extend standard textbox's context menu. Standard means that the menu is not specialy created and show but generated by the control itself.

    CH "I think I'm goin' crazy"
    Attached Images Attached Images  
    Last edited by Psych0; October 15th, 2010 at 04:37 AM.

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Context menu for TextBox

    So you can add, for example: DESTROY WORLD, or DELETE FILES?

    That wouldn't be so good. That's why windows doesn't allow it.

    You can create a CONTEXT MENU that lives in the taskbar with Windows 7

    That, you can add items to
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Re: Context menu for TextBox

    Quote Originally Posted by dglienna View Post
    That wouldn't be so good.
    No way! I'm a friendly programmer. :-)

    I created a program that helps me with my duties with my job.
    There's a ServiceDesk that strores service calls. My job is analize the calls and make various report based on it. I create my own data base (mdb) and a cliend (vb6) to automate rut. (Export some information from ServiceDesk, import to my database, analyzing and reporting i've done). Now I work on my code to maximum automate rut.
    There's primary actions that I've automated via hot-keys, but there's a secondary one that I wanna realize via context menu.

    I just need to select part of text information in text box and have ability to select from context menu there the selection to store (there's a number of a textboxes). But there's a number of colleagues working with my application with its own habits (some of them like to use context menu instead of hot-keys to copy/paste)

    I think its foolish to wrote so big project just for masking desructive things... If I would wish to write a virus or malware i'd like to use C++. :-)

    I can realize my own context menu (that's not a problem) but on the spot i've got WinXP, at home Win7 and there's a different menues in both the systems. That's why I need smart solution to add items to standard menu

    Uh...

    Think I won't be banned for offtop :-)
    Last edited by Psych0; October 15th, 2010 at 11:30 AM.

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Context menu for TextBox

    If you wrote the client, then you'd have to change it to create your menu. You can create a menu on the fly, but not from a different program.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Unhappy Re: Context menu for TextBox

    Quote Originally Posted by dglienna View Post
    You can create a menu on the fly, but not from a different program.
    Dear Dglienna, I don't need a different program. I just want standard menu of a standard control.

    I misunderstand you or you misunderstand me.

    If I will follow your logic then I need to create my own TextBox control. No, no, no! That a control? Write whole program in Notepad using mnemonics of processor :-)

    I've explain that I've done. I've explain that I need. I've explain almost everything but there's no answer. Now I hope you will tell me "It's impossible" or "You have to do... to realize it".

  13. #13
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Re: Context menu for TextBox

    Dr. Dglienna, u realy POWER Poster! :-) (in good part)

  14. #14
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Context menu for TextBox

    This is an API that you might be able to use. Notice that the button COLORIZES the menu items.

    Code:
     Option Explicit
    
    Private Const MIM_BACKGROUND As Long = &H2
    Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
    
    Private Type MENUINFO
        cbSize As Long
        fMask As Long
        dwStyle As Long
        cyMax As Long
        hbrBack As Long
        dwContextHelpID As Long
        dwMenuData As Long
    End Type
    
    Private Declare Function DrawMenuBar Lib "user32" _
        (ByVal hWnd As Long) As Long
    
    Private Declare Function GetSubMenu Lib "user32" _
        (ByVal hMenu As Long, ByVal nPos As Long) As Long
    
    Private Declare Function GetMenu Lib "user32" _
        (ByVal hWnd As Long) As Long
    
    Private Declare Function SetMenuInfo Lib "user32" _
        (ByVal hMenu As Long, _
         mi As MENUINFO) As Long
    
    Private Declare Function CreateSolidBrush Lib "gdi32" _
        (ByVal crColor As Long) As Long
    
    Private Sub Command1_Click()
    Dim mi As MENUINFO
       
        With mi
            .cbSize = Len(mi)
            
            .fMask = MIM_BACKGROUND
            .hbrBack = CreateSolidBrush(vbYellow)
            SetMenuInfo GetMenu(Me.hWnd), mi  'main menu bar
                    .fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
            .hbrBack = CreateSolidBrush(vbCyan)
            SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 0), mi 'File menu (item 0)
                    .hbrBack = CreateSolidBrush(vbGreen)
            SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 1), mi 'Edit menu (item 1)
                    .hbrBack = CreateSolidBrush(vbRed)
            SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 2), mi 'Select menu (item 2)
                End With
            DrawMenuBar Me.hWnd
    
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  15. #15
    Join Date
    Sep 2010
    Location
    Russia
    Posts
    15

    Re: Context menu for TextBox

    That's no the goal!
    Thank you, but that's not a goal!
    Yes, that's not a goal!
    And u know what I mean!
    Last edited by Psych0; October 15th, 2010 at 12:25 PM.

Page 1 of 2 12 LastLast

Tags for this Thread

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

Featured