March 28, 2024, 03:39:06 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Contextmenu on RichEdit

Started by aurelCB, May 05, 2008, 04:26:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

I need some help!
How get context menu on richedit control?
if it's posibile?
bye

LarryMc

What have you tried so far?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

I need this for my interpreter.
Would you help me?
Like context menu in CBasic editor.
thanks anyway...

aurelCB

I find Aurora example but i dont know how translate
to CBasic code:
'rich edit context menu
TYPE POINTAPI
  def x:int
  def y:int
ENDTYPE

def Cursor:POINTAPI
def error:int
def x,y:int

type POINT
mx:int
my:int
endtype

'//richedit mouse event mask
setid "EN_MSGFILTER",0x700
setid "ENM_MOUSEEVENTS",0x20000
setid "WM_RBUTTONDOWN",0x204
setid "EM_GETSELTEXT",(0x400 + 62)

declare "user32.dll",GetCursorPos(pPoint:POINTAPI),INT
declare "user32.dll",ScreenToClient(hWnd:int,pPoint:POINTAPI),INT
declare "user32.dll",GetCaretPos(lpPoint:POINT),INT
DEF win:window

WINDOW win,0,0,450,350,@MINBOX|@MAXBOX|@SIZE,0,"Main-",main
setwindowcolor win,rgb(200,200,200)
CONTROL win,"RE,,7,35,400,210,0x50B010C4,1"




run = 1
waituntil run = 0
closewindow win
end

sub main
select @class
case @idclosewindow
run=0

case @IDCREATE
CenterWindow win

CASE @IDRBUTTONUP
'If error=CONTROLCMD (win, 1, @RTGETEVENTMASK)
'If @notifycode=GetCursorPos(Cursor)
hwnd=win
x=@mousex
y=@mousey
'If @notifycode=GetCursorPos(Cursor)
CONTEXTMENU win,@MOUSEX,@MOUSEY,"I,Color,0,99","I,Clear,0,1"
'Endif

CASE @IDCONTROL
IF @CONTROLID = 5
SELECT @NOTIFYCODE
GetCursorPos(Cursor)
x=@mousex
y=@mousey
'endif
ENDSELECT
endif


endselect
return



I try like this but nothing work?

sapero

May 06, 2008, 02:24:02 PM #4 Last Edit: May 06, 2008, 07:45:23 PM by sapero
Hello aurelCB

I have already installed CB, but have forget how to code in it, i have also IBasic Standard but not used it since Pro was released.
My code should work, but an exception is generated in line 62 with "if (mf.msg = @IDRBUTTONUP)".
Maybe Paul can help here
:DEF d1:Dialog


' defines for context menu in richedit, copied from Platform SDK
CONST ENM_MOUSEEVENTS = 0x20000
CONST EN_MSGFILTER    = 0x00700
CONST WM_CUT    = 0x300
CONST WM_COPY   = 0x301
CONST WM_PASTE  = 0x302
TYPE NMHDR
def hwndFrom as UINT
def idFrom as UINT
def code as UINT
ENDTYPE
TYPE MSGFILTER
def nmhdr as NMHDR
def msg as UINT
def wParam as UINT
def lParam as UINT
ENDTYPE
TYPE POINT
def x as INT
def y as INT
ENDTYPE
' customized helper function
declare "kernel32.dll", CopyNMHDR alias RtlMoveMemory(lpTo as POINTER, lpFrom as UINT, size as UINT)
declare "user32.dll", GetCursorPos(lpPt as POINT)
DECLARE "user32.dll", ScreenToClient(win:int,xy:point)
' global variables
def mf:MSGFILTER
def pt as POINT
def mem:MEMORY

' custom defines for context menu
CONST IDM_CUT   = 1000
CONST IDM_COPY  = 1001
CONST IDM_PASTE = 1002



DIALOG d1,0,0,587,360,0x80C80080,0,"Rich Edit demo",Handler
CONTROL d1,"RE,,7,35,570,294,0x50B010C4,1"

DOMODAL d1
END

' window message handler
Handler:
SELECT @CLASS
CASE @IDINITDIALOG
CONTROLCMD d1, 1, @RTSETEVENTMASK, ENM_MOUSEEVENTS

CASE @IDMENUPICK
SELECT @MENUNUM
CASE IDM_CUT   : SendMessage d1, WM_CUT, 0, 0, 1
CASE IDM_COPY  : SendMessage d1, WM_COPY, 0, 0, 1
CASE IDM_PASTE : SendMessage d1, WM_PASTE, 0, 0, 1
ENDSELECT

CASE @IDCONTROL
SELECT @CONTROLID
case 1: 'richedit
if (@NOTIFYCODE = EN_MSGFILTER)
' received advanced richedit notification, enabled by @RTSETEVENTMASK
' copy the MSGFILTER pointed by @QUAL (also lParam)
mem = @QUAL
readmem mem,1,mf

' check if the message was fired by right mouse button
if (mf.msg = @IDRBUTTONUP)
GetCursorPos(pt)
ScreenToClient(@HITWINDOW, pt)
CONTEXTMENU @HITWINDOW, pt.x, pt.y, "I,Cut,0,1000","I,Copy,0,1001","I,Paste,0,1002"
endif
endif
ENDSELECT

ENDSELECT
RETURN

aurelCB


ExMember001

i've send you a pm about that...
but have same problem as sapero ;)
but as always ... sapero code seems better than the one i pm you ... so thrash mine :P

ExMember001

May 06, 2008, 04:47:19 PM #7 Last Edit: May 06, 2008, 08:41:25 PM by KrYpT
Found it  ;D
Sapero turn a light on in my head :P



DECLARE "user32.dll",GetCursorPos(xy:point),int
DECLARE "user32.dll",ScreenToClient(win:int,xy:point),int

'richedit mouse event mask
SETID "EN_MSGFILTER",&H700
SETID "ENM_MOUSEEVENTS",&H20000
SETID "WM_RBUTTONDOWN",&H204

TYPE NMHDR
    DEF hwndFrom:INT
    DEF idFrom:UINT
    DEF code:UINT
ENDTYPE

TYPE MSGFILTER
    DEF nmhdr:NMHDR
    DEF msg:UINT
    DEF wParam:UINT
    DEF lParam:UINT
ENDTYPE

'use to get context menu x,y coord
TYPE POINT
   DEF x:int
   DEF y:int
ENDTYPE

'/////////////////////////////////////////////////////////////////////////

Autodefine "off"

def d1:dialog
def pt:POINT
def mf:MSGFILTER
def mem:MEMORY

DIALOG d1,0,0,441,300,0x80C80080,0,"context menu in richedit",Handlermain
CONTROL d1,"RE,,16,14,404,272,0x50B110C4,1"
domodal d1
end

sub HANDLERmain

   select @class

         case @idclosewindow
             CLOSEDIALOG d1,@IDOK
         CASE @IDINITDIALOG
             CONTROLCMD  d1, 1, @RTSETEVENTMASK, @ENM_MOUSEEVENTS
         CASE @IDCONTROL

             SELECT @CONTROLID
                   CASE 1: 'RICHEDIT
                       if @NOTIFYCODE = @EN_MSGFILTER
                          mem = @QUAL
                          readmem mem,1,mf
                          SELECT mf.msg
                               CASE @WM_RBUTTONDOWN: 'Right mouse button clicked
                                   'use API to get mouse position in Richedit
                    GetCursorPos(Pt)
                    ScreenToClient(d1,Pt)
                                    CONTEXTMENU d1,pt.x,pt.y,"I,Exit,0,101"
                          ENDSELECt
                       endif
                       
             ENDSELECT

   endselect
return

sapero

KrYpT, your Amazing ;D I've also updated my sample.

aurelCB

Hi guys realy tank you!
I tray krypt example and work fine,and
i also try without autodefine "off" and also work ok.
I think that is Paul in his example for Aurora also use:
DECLARE "user32.dll",GetCursorPos(xy:point),int
DECLARE "user32.dll",ScreenToClient(win:int,xy:point),int
and i try something but i dont know how.
I hope that is the same with Window frame, i try.
Autodefine i dont use in interprerter and i think
that would work without him.
Thanks again....
zlatko

aurelCB

And finaly work properly i just add little code:
DECLARE "user32.dll",GetCursorPos(xy:point),int
DECLARE "user32.dll",ScreenToClient(win:int,xy:point),int
',by kRypt,sapero
'richedit mouse event mask
SETID "EN_MSGFILTER",&H700
SETID "ENM_MOUSEEVENTS",&H20000
SETID "WM_RBUTTONDOWN",&H204

TYPE NMHDR
    DEF hwndFrom:INT
    DEF idFrom:UINT
    DEF code:UINT
ENDTYPE

TYPE MSGFILTER
    DEF nmhdr:NMHDR
    DEF msg:UINT
    DEF wParam:UINT
    DEF lParam:UINT
ENDTYPE

'use to get context menu x,y coord
TYPE POINT
   DEF x:int
   DEF y:int
ENDTYPE

'/////////////////////////////////////////////////////////////////////////

'Autodefine "on"

def d1:dialog
def pt:POINT
def mf:MSGFILTER
def mem:MEMORY

DIALOG d1,0,0,441,300,0x80C80080,0,"context menu in richedit",Handlermain
CONTROL d1,"RE,,16,14,404,272,0x50B110C4,1"
domodal d1
end

sub HANDLERmain

   select @class

         case @idclosewindow
             CLOSEDIALOG d1,@IDOK

         CASE @IDINITDIALOG
             CONTROLCMD  d1, 1, @RTSETEVENTMASK, @ENM_MOUSEEVENTS

         CASE @IDCONTROL

             SELECT @CONTROLID
                   CASE 1: 'RICHEDIT
                       if @NOTIFYCODE = @EN_MSGFILTER
                          mem = @QUAL
                          readmem mem,1,mf
                          SELECT mf.msg
                               CASE @WM_RBUTTONDOWN: 'Right mouse button clicked
                                   'use API to get mouse position in Richedit
                    GetCursorPos(Pt)
                    ScreenToClient(d1,Pt)
                                    CONTEXTMENU d1,pt.x,pt.y,"I,Cut,0,101","I,Copy,0,102","I,Paste,0,103"
                          ENDSELECT
                       endif
ENDSELECT
CASE @IDMENUPICK
SELECT @MENUNUM
CASE 101 : CONTROLCMD d1,1,@RTCUT
CASE 102 : CONTROLCMD d1,1,@RTCOPY
CASE 103 : CONTROLCMD d1,1,@RTPASTE
ENDSELECT

   endselect
return