Hi everyone,
I don't get around to programming much but I had the week off and I thought I would give it a try.
My problem:
I have subclassed a Rich edit control in order to #1: Get the mouse position in the Rich Edit
#2: Display a context menu at the coordinates of the mouse when a right button up is triggered.
I have searched the forums and most of the time I can find anwers to my problems but this one I could not.
MSDN says something about xPos= GET_X_PARAM(LPARAM lParam) in order to acquire the x and y mouse positions but I am lost ???
Here is some of the code I am using:
SUB SubClass_RE(hWnd:UINT, uMsg:UINT, wParam:UINT, lParam:UINT),UINT
UINT OriginalWndProc
OriginalWndProc = _GetWindowLong(hwnd, GWL_USERDATA)
SELECT uMsg
CASE WM_MOUSEMOVE
@MOUSEX: ' Don't know how to read the mouse coordinates
CASE WM_RBUTTONUP
[b]CONTEXTMENU d1, @MOUSEX,@MOUSEY[/b] :'The problem is here d1 is being read and not control 1
MENUITEM "Cut",0,15
MENUITEM "Copy",0,16
MENUITEM "Paste",0,17
ENDMENU
'MESSAGEBOX d1, STR$(xPos),""
ENDSELECT
RETURN _CallWindowProc(OriginalWndProc, hWnd, uMsg, wParam, lParam)
ENDSUB
Thank you for your time and help :)
I do it differently.
Top of code:
SETID "ENMSGFILTER",0x700
TYPE MSGFILTER
def hwndFrom:INT
def idFrom:INT
def code:INT
def msg:INT
def wparam:INT
def lparam:INT
ENDTYPE
DEF mf:MSGFILTER
DEF mx,my:INT
mx and my will hold mouse coords and don't need to be passed to the sub that manages the context menu.
In the event handler for the window:
SUB Handler
SELECT @MESSAGE
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'riched
Iin the handler for the riched control (I do not subclass):
IF @NOTIFYCODE = @ENMSGFILTER
mem = @QUAL:'read in the MSGFILTER structure
READMEM mem,1,mf
mx= (mf.lparam & 0xffff) + 38
my= mf.lparam / 0x10000
IF mf.msg = @IDRBUTTONDN THEN GOSUB DoContextMenu
ENDIF
jay, @MOUSEX/Y is initialized by the Ebasic GUI core before it calls your window handler:
@MOUSEX = lParam & 0xFFFF
@MOUSEY = lParam >> 16
You can reuse @MOUSEX/Y in your SubClass_RE subroutine, or define your own local variables (signed):
SUB SubClass_RE(...)
word x,y
...
CASE WM_MOUSEMOVE
x = lParam & 0xFFFF
y = lParam >> 16
If you prefer integers:
SUB SubClass_RE(...)
int x,y
...
CASE WM_MOUSEMOVE
x = *<word>(&lParam)
y = *<word>(&lParam+2)
To use CONTEXTMENU you'll need a temporay WINDOW object:
SUB SubClass_RE(...)
WINDOW tempwin
...
CASE WM_RBUTTONUP
tempwin.hwnd = hWnd
CONTEXTMENU tempwin, x, y
Or without tempwin, x, y:
CONTEXTMENU *<WINDOW>(&hWnd), *<word>(&lParam), *<word>(&lParam+2)
Thank you Alyce. ;)
Thank you Sapero. ;)
This has helped out more than you know. ;D