Page 1 of 1

Posted: Fri Aug 30, 2002 9:04 pm
by BackupUser
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

Posted: Sat Aug 31, 2002 4:48 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

How did you create the RE control ??
With plain API or with El_Choni´s Lib ??

Any example how you did it ??

cya,
...Danilo

(registered PureBasic user)

Posted: Sat Aug 31, 2002 10:07 am
by BackupUser
Restored from previous forum. Originally posted by freak.

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
It seems like the Control sends no Messages at all, that's strange.
Maybe some more errors from my side?

Timo

Posted: Sat Aug 31, 2002 11:07 am
by BackupUser
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:

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
End

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)

Posted: Sat Aug 31, 2002 11:55 am
by BackupUser
Restored from previous forum. Originally posted by freak.

Thanks!! :)