Hi, Greg -
If you use a slightly different approach, I think you can accomplish what you want via a couple of simple Windows API function calls. You'll need a PB version of the WinAPI POINT structure:
global type s_point from structure
long x
long y
end type
You'll also require two external function declarations:
// Obtains the cursor position in screen coordinates (pixels).
FUNCTION Boolean GetCursorPos ( &
REF s_point lpPoint &
) LIBRARY "user32.dll"
// Translates a point from screen coordinates to client (window)
// coordinates (pixels).
FUNCTION Boolean ScreenToClient ( &
Longptr hWnd, &
REF s_point lpPoint &
) LIBRARY "user32.dll"
You'll need the Handle of the parent window that contains the RichTextEdit control. If the RTE does not reside in a tab control's tab page, you can use the "parent" pronoun in the PowerScript function as shown in the following code snippet. If the RTE does reside in a tab control, you need a way to get the handle of the parent window.
Finally, you'll need a little PowerScript code. How you implement the popup menu is up to you, of course, but I suggest you consider putting the following code in the RichTextEdit control's RButtonDown event. Use the following code to obtain the X,Y coordinates of the mouse cursor in pixels, relative to RTE's parent window. You'll then need to convert the X,Y coordinates to PBU's before calling the PopMenu PowerScript function:
Boolean lb_rc
s_point lstr_pt
// Determine the cursor's position in screen coordinates (pixels), then convert
// that point to parent window coordinates (pixels).
lb_rc = GetCursorPos(lstr_pt)
lb_rc = ScreenToClient(Handle(Parent),lstr_pt)
// Here's where you would convert pixels to PBU's and issue the PopMenu function...
Post Function MessageBox("Cursor Position (Pixels)","X: "+String(lstr_pt.x)+"~r~nY: "+String(lstr_pt.y))
Return 0
I have tested this code snippet in a RichTextEdit control in PB 2019 and it works. I hope this helps you develop a solution to your question.
Good luck and best regards, John