Menu items attached to controls (not forms)

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Menu items attached to controls (not forms)

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:20 pm

by Craig Shearer >> Thu, 11 Nov 1999 3:39:22 GMT

Yo, Windows API Gurus...

We are currently developing a whizzy new control in JADE and we want to be able to have context sensitive menus on it. Context sensitive menus are easy on Forms - you simply design a hidden menu in the Painter then call popupMenu(contextMenu, x, y) in response to a right-mouse down event.

However, we want to have a popup menu attached to a control. This control can be painted on any form, so it will be inconvenient (to say the least!) to have to define its menu on the form on which it is painted. We thought we could create a menuItem object at runtime as follows:

MyConrol::windowCreated(blah...)
begin

if not isInPainter then
create myMenuItem transient;
myMenuItem.caption := "test'";
myMenuItem.form := form;
endif;

.....
end;

then...

mouseDown(blah...)
begin

if button = 2 then
form.popupMenu(myMenuItem, x.Integer, y.Integer);
endif;

.....
end;


However, when this is tested, we get a 14017 exception: Menu Item not found - This error is returned when the physical menu associated with a menu object cannot be found.

JADE Support doesn't have any answers to this problem.


Is there an easy set of Windows API calls that could be used to implement this functionality?

Here's hoping!

Craig.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Menu items attached to controls (not forms)

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:20 pm

by Torrie Moore >> Sun, 14 Nov 1999 21:07:56 GMT

Craig

I have a control that approaches this in a slightly different way. A blank form has a menu that you will use for your control. When the mouse button fires it creates an instance of the form and then displays the menu on the form (the form remains invisible). If the menu form is blank except for the menu then the speed is acceptable. The code looks like this

mouseDown(table : Table input; button : Integer; shift : Integer; x : Real; y : Real) updating;
vars

formX, formY : Real;
menuForm : FmTableMenu;
begin


create myMenuForm transient;
menuForm.visible := false;
menuForm.setFormParent(table.form);
menuForm.initialiseMenuItems(table);

table.column := table.convertPositionToColumn(x);
menuForm.screenToWindow(formX, formY);
self.windowToScreen(formX, formY);
menuForm.popupMenu(menuForm .mTablePopup, (formX + x).Integer, (formY + y).Integer);

end;

Torrie


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 31 guests