On Mon, Feb 11, 2013 at 3:48 PM, Staffan Tylen <staffan.ty...@gmail.com>wrote:


> I'm trying to add a context menu to a group box but cannot get the menu to
> appear when right-clicking within the box. It works fine if I change the
> control to for example a treeview. I haven't found anything in the doc
> saying that it won't work for a group box control.
>


The reason is that the operating system generates a WM_CONTEXT message and
sends if to the window under the mouse, if the window receives mouse
messages.  If the window does not handle it, and it is a child window, the
operating system passes the message to the parent and sets a parameter of
the message to the window handle of the child window.

Mouse messages are not sent to group boxes.  So the message goes straight
to the dialog.  This code works and only puts up the context menu if the
mouse click was over the group box:

a=.dialog~new
a~execute
return

::class dialog subclass userdialog
::requires "oodialog.cls"

::method init
forward class(super) continue
self~createCenter(200,200,"Dialog Title")

::method defineDialog
expose menu
self~createGroupBox(100,10,10,180,150,,"GroupBox")
menu=.PopupMenu~new(200)
menu~insertItem(1,201,"Exit",,,.TRUE)

::method initDialog
expose menu boxRect

box = self~newGroupBox(100)
boxRect = box~clientRect
box~mapWindowPoints(self~hwnd, boxRect)

menu~assignTo(self)
menu~connectContextMenu(onContext)
menu~connectCommandEvent(201,onExit)

::method onContext unguarded
expose menu boxRect
use arg h,x,y

reply 0
pos = .Point~new(x,y)
p = pos~copy
self~screen2client(p)
if p~inRect(boxRect) then do
  menu~~show(pos)
end

/*
::method onExit unguarded
self~cancel:super()
*self~finished = 0   -- Do not touch self~finished*
*return self~finished*
*/

::method onExit unguarded
return self~cancel:super()

--
Mark Miesfeld
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to