Restored from previous forum. Originally posted by freak.
How can i detect a RightClick on a Richedit control?
I tried with WindowCallback, but no Messages are sent from the control.
I also tried sending the #EM_SETEVENTMASK message to make it send Event Messages, but still doesn't work.
Any Richedit-experts out there who can help me?
Thanks,
Timo
Catching Events on a Richedit control?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by freak.
Here is what i tried...
It seems like the Control sends no Messages at all, that's strange.
Maybe some more errors from my side?
Timo
Here is what i tried...
Code: Select all
Global hRich
Procedure Callback(WindowID, Message, wParam, lParam)
If Message = #WM_RBUTTONDOWN ; does not work
MessageRequester("","Click",0)
EndIf
If WindowID = hRich ; absolutely no message seems to be sent from hRich
MessageRequester("","Some Message",0)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu, "")
hRich = OpenRichEdit(WindowID(), 0, 0, 0, 640, 480, "Some Text") ; simple Richedit using Library Version 1.6
SetWindowCallback(@Callback())
If SendMessage_(hRich, #EM_SETEVENTMASK, 0, #ENM_MOUSEEVENTS) = 0 ; Should tell the Control to send MouseEvents
MessageRequester("ERROR",Str(GetLastError_()), 0) ; returns no Error, but also has no effect.
EndIf
Repeat
Event = WaitWindowEvent()
If EventType() = #PB_EventType_RightClick ; doesn't work either (i didn't expect it to)
MessageRequester("", "Click", 0)
EndIf
Until Event = #PB_EventCloseWindow
EndIf
End
Maybe some more errors from my side?
Timo
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
RichEdit uses its own class with its own
Window procedure.
You have to change that with SetWindowLong(),
BUT you have to call the original System Callback !!
See this:
Its very important to make the Callback like shown.
You have to call the original RichEdit Callback,
so it can process the message.
You can make it like it is now, or like the 3 commented lines.
So you can FORWARD some messages to RichEdit: result = CallWindowProc_(...
or BLOCK some Messages from it: result = 0 ; without calling original Callback
Start my modified version, right click on the RichEdit window
and start to type something in the Edit field (#WM_CHAR).
Hope it helps...
cya,
...Danilo
(registered PureBasic user)
RichEdit uses its own class with its own
Window procedure.
You have to change that with SetWindowLong(),
BUT you have to call the original System Callback !!
See this:
Code: Select all
Global hRich, OldCallback
Procedure Callback(WindowID, Message, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If WindowID = hRich
Select Message
Case #WM_RBUTTONDOWN
MessageRequester("","RIGHT Mouse Button Down",0)
;result = 0
Case #WM_CHAR
BEEP_(800,30)
;result = CallWindowProc_(OldCallback, WindowID, Message, wParam, lParam)
Default
;result = CallWindowProc_(OldCallback, WindowID, Message, wParam, lParam)
EndSelect
result = CallWindowProc_(OldCallback, WindowID, Message, wParam, lParam)
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu, "")
hRich = OpenRichEdit(WindowID(), 0, 0, 0, 540, 380, "Some Text") ; simple Richedit using Library Version 1.6
;RichEditBackgroundColor($0)
RichEditTextColor($FFFF00)
RichEditOptions(GetRichEditStyle(),0)
SetWindowCallback(@Callback())
If SendMessage_(hRich, #EM_SETEVENTMASK, 0, #ENM_MOUSEEVENTS) = 0 ; Should tell the Control to send MouseEvents
MessageRequester("ERROR",Str(GetLastError_()), 0) ; returns no Error, but also has no effect.
EndIf
;
; Change the Callback for RichEdit
;
OldCallback = GetWindowLong_(hRich,#GWL_WNDPROC)
SetWindowLong_(hRich,#GWL_WNDPROC,GetWindowLong_(WindowID(),#GWL_WNDPROC))
Repeat
Event = WaitWindowEvent()
If EventType() = #PB_EventType_RightClick ; doesn't work either (i didn't expect it to)
MessageRequester("", "Click", 0)
EndIf
Until Event = #PB_EventCloseWindow
EndIf
EndIts very important to make the Callback like shown.
You have to call the original RichEdit Callback,
so it can process the message.
You can make it like it is now, or like the 3 commented lines.
So you can FORWARD some messages to RichEdit: result = CallWindowProc_(...
or BLOCK some Messages from it: result = 0 ; without calling original Callback
Start my modified version, right click on the RichEdit window
and start to type something in the Edit field (#WM_CHAR).
Hope it helps...
cya,
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm