1. Gregory Rusak
  2. PowerBuilder
  3. Thursday, 9 May 2024 23:10 PM UTC

Hello,

We're trying to implement our own Right Mouse Button menu on the RichTextEdit control overriding the PopMenu property having set it to false.

What we don't understand is how to get the x and y coordinates of where the user had right clicked on the control. The rbuttondown EVENT mapped to pbm_renrbuttondown (Syntax 2) unlike Syntax 1, does not provide the xpos and ypos in order to provide these to a custom function to display a menu.

We also need these coordinates in order to provide our Sentry Spellchecker control with the arguments in the SSCE_CheckCtrlBackgroundMenu function to provide spelling suggestions. (Using SSCE Windows SDK with PowerBuilder (wintertree-software.com)

So how can you get those coordinates? Am I missing something basic here? Wouldn't be the first time.

We're on PowerBuilder 2022 R3 build 3356.

As always, any feedback is much appreciated.

Kind Regards,

Greg

John Fauss Accepted Answer Pending Moderation
  1. Friday, 10 May 2024 15:15 PM UTC
  2. PowerBuilder
  3. # 1

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

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.