Is there something special about the wndProc messages for a RichEdit20WPT window?

♀尐吖头ヾ 提交于 2019-12-20 06:48:31

问题


I am currently trying to subclass an Edit Control, in particular the subject of en Email in the Outlook Client. This control is of class RichEdit20WPT.

I get a wndProc by using the following WINAPI methods.

<DllImport("ComCtl32.dll", CharSet:=CharSet.Auto)> _
    Public Shared Function SetWindowSubclass(hWnd As IntPtr, newProc As Win32SubClassProc, uIdSubclass As IntPtr, dwRefData As IntPtr) As Integer
    End Function

 <DllImport("comctl32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Shared Function DefSubclassProc(ByVal hWnd As IntPtr, ByVal uMsg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
    End Function

    Public Delegate Function Win32SubClassProc(hWnd As IntPtr, Msg As IntPtr, wParam As IntPtr, lParam As IntPtr, uIdSubclass As IntPtr, dwRefData As IntPtr) As Integer

And would then have a wndProc like this;

Private WM_CONTEXTMENU As IntPtr = &H7B

Private Function SubClassProc(hWnd As IntPtr, Msg As IntPtr, wParam As IntPtr, lParam As IntPtr, uIdSubclass As IntPtr, dwRefData As IntPtr) As Integer

        Select Case Msg

            Case WM_DESTROY                   

            Case WM_NCDESTROY

            Case WM_LBUTTONDOWN

            Case WM_CONTEXTMENU   'NEVER HAPPENS

            Case WM_RBUTTONDOWN

        End Select

        Return DefSubclassProc(hWnd, Msg, wParam, lParam)
    End Function

I get the L and R button down and up messages but no WM_CONTEXTMENU. My current intention is to add a menu item to the context menu so as an alternative I am using the WM_RBUTTONDOWN message.

Is this control special and known to not show the WM_CONTEXTMENU message?

I also have a challenge to find the messages that occur after choosing something on the context menu. My understanding is that the messages of the menu item clicked in the context menu are given to the parent which in this case is this RichEdit20WPT window. Is this correct? Note I am not making my own context menu I am appending to the existing one so I am not changing the owner of the context menu or anything like that.


回答1:


Thank you to all the comments which helped me to at least keep searching for answers or in this case messages. For anyone coming here and wanting to add to the context menu of an Outlook Menu.

First here are two good links which explain generally what to do. How to disable copy/paste commands in the Windows edit control context menu? Modify right-click context menu in standard controls Anyone reading them can assume for a standard edit control such as a text box on a windows form application that the messages will be sent.

For Outlook (At least 2007 / 2010) this is what I have found;

  1. The text box you need to find for both an Explorer and Inspector is RichEdit20WPT
  2. This window however does not get two of the key messages required. (a) it does not get WM_INITMENUPOPUP to know before the context menu is being shown and secondly (b) it does not get a message when you choose something in the context menu which is a WM_COMMAND in this case.
  3. Inorder to amend the context menu you need to subclass the subject text box's parent which is a window of class #32770.
  4. As the parent is subclassed there are a few challenges. To know when our target text box as had a right click from the #32770 window you need to look for the WM_SETCURSOR.

Something like this where the wParam will be the text box's Hwnd and the HiWord will be the mouse message;

Case NativeMethodsEX.WM_SETCURSOR
    If wParam = subjectHwnd Then
        Dim pMap As New NativeMethodsEX.LParamMap(lParam)
    If pMap.hiword = NativeMethodsEX.WM_RBUTTONUP Then
        rightClickOnSubject = True
    Else
        rightClickOnSubject = False
    End If
    End If

Then shortly after there will be this message

Case NativeMethodsEX.WM_INITMENUPOPUP
    If rightClickOnSubject Then
        'check here if you want to display something.
    End If

Once you know this, you can implement the ideas from the other forum answers.



来源:https://stackoverflow.com/questions/41039964/is-there-something-special-about-the-wndproc-messages-for-a-richedit20wpt-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!