我目前正在尝试子类化编辑控件,特别是Outlook客户端中的电子邮件主题。此控件属于RichEdit20WPT类。
我使用以下WINAPI方法获得了一个wndProc。
<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
然后会有像这样的wndProc;
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
我得到了L和R按钮,但没有WM_CONTEXTMENU。我目前的目的是在上下文菜单中添加一个菜单项,以便我可以使用WM_RBUTTONDOWN消息。
此控件是否特殊且已知不显示WM_CONTEXTMENU消息?
我也很难找到在上下文菜单中选择内容后发生的消息。我的理解是,在上下文菜单中单击的菜单项的消息将提供给父级,在这种情况下,该父级是RichEdit20WPT窗口。它是否正确?注意我没有创建我自己的上下文菜单我附加到现有菜单,所以我没有更改上下文菜单的所有者或类似的东西。
答案 0 :(得分:0)
感谢所有帮助我至少继续搜索答案的评论或在这种情况下的消息。对于来到此处并希望添加到Outlook菜单的上下文菜单的任何人。
首先,这里有两个很好的链接,可以解释一般该做什么。 How to disable copy/paste commands in the Windows edit control context menu? Modify right-click context menu in standard controls 阅读它们的任何人都可以采用标准的编辑控件,例如Windows窗体应用程序上的文本框,以便发送消息。
对于Outlook(至少2007/2010年),这是我发现的;
像这样的东西,wParam将是文本框的Hwnd,而HiWord将是鼠标消息;
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
然后不久会有这条消息
Case NativeMethodsEX.WM_INITMENUPOPUP
If rightClickOnSubject Then
'check here if you want to display something.
End If
一旦你知道这一点,你就可以从其他论坛的答案中实现这些想法。