Creating a context menu attached to a control w/o rightclick (OpenInsight 32-bit Specific)
At 17 FEB 2003 12:44:45PM Peter Walter wrote:
I would like to display a menu attached to a control on the fly, similar to the "context menu" feature of OI which is accessible by a right click. However, I do not want to *replace* the right-click menu - I want to create (and display) a totally seperate menu, attached to a control, accessible by a keystroke (Alt-M) while the control has the focus. I understand how to create the menu structure; however, I cannot figure out how to display it! Can anyone explain how to invoke the menu (and have it disappear) once a menu entry is selected ?
Thanks,
Peter
At 18 FEB 2003 07:54AM Leon Shaffer wrote:
Just a thought -
Sounds like to me that you want a static informational popup to be executed when a user presses the assigned hot-key assigned to an MDI Frame, much like an F2 function, F9 function, F3 (Zoom) function - this would be the Alt+M function.
I would design a static informational popup with the "menu" selections that you want, then when the user gets to the control and executes the assigned hot-key, get the x-y coordinates of the control that has focus, execute the popup with starting point of popup window to be x+a,y+b (a being an offset from the start of the x coordinate of the focused control and b being and offset fromt the y coordinate), get the result returned by the user selecting whatever from the popup, execute any additional processing you want, drop that value into the control you want it to go into etc…..
At 18 FEB 2003 09:54AM Peter Walter wrote:
Leon, thanks for responding. I had considered the "popup" method, but I would strongly prefer an actual menu because the data I am presenting is in a menu-like format. Can anyone shed light on how to invoke a floating menu in OpenInsight? I have successfully CREATed the menu object; I just need to know how to display it.
At 18 FEB 2003 11:06AM Donald Bakke wrote:
Peter,
I haven't tried this but if you call the same code that the sample context menu code calls it should work. If you have the menu structure then the essential code to launch the menu would be this:
Utility("CREATE", menuStruct)PostMessage(hWnd, WM_RBUTTONDOWN, 0, lParam)Utility("DESTROY", menuStruct)Keep in mind, however, that your menu won't necessarily display where you want it. I believe this is because lParam is being used to determine where the mouse cursor is during the right-click. Since you are activating this via an accelerator then this parameter will have to be provided by you. I could be wrong, but I believe the positional value will be relative to the desktop and not the window. Therefore this will need to be dynamically created.
At 19 FEB 2003 01:15AM Peter Walter wrote:
Don,
Thanks very much for your assistance. I will try the code and let you know how it works out.
Peter
At 23 FEB 2003 01:50PM Peter Walter wrote:
Don,
I tried the following code:
equ WM_RBUTTONDOWN$ To 516
.
.
.
Handle=Get_Property(Control,"HANDLE")
ControlSize=AbsoluteSize(Control) ;* returns absolute coords of a control
xControl =ControlSize ;* x position of control
yControl =ControlSize ;* y position of control
wControl =ControlSize ;* width of control
hControl =ControlSize ;* height of control
* pass location of dummy "cursor" lParam as DWORD
lParam=xControl + Int(wControl / 2)
lParam=lParam + 1) * 65536)
PostMessage(Handle,WM_RBUTTONDOWN$,0,lParam)
However, it does not work - no context menu pops up. I tried this code on controls that had new context menus defined, and those that used the predefined context menu. A real "right-click" of the mouse works in both cases. Does my code look correct to you? Do you have any debugging suggestions I could try?
Thanks in advance,
Peter
At 23 FEB 2003 02:34PM Peter Walter wrote:
A follow-up …
The reason my user-defined context menu did not pop up was because of an unrelated programming error. I have also discovered that you do NOT need to set Lparam - sending a zero places the context menu at the correct control. However, the default context menu still does not appear when triggered programatically. This is something I will live with for now.
Peter
At 23 FEB 2003 05:45PM Donald Bakke wrote:
Peter,
However, the default context menu still does not appear when triggered programatically.
Do you mean when you right-click versus your accelerator key? I would have expected that since the creation of your own popup menu effectively replaces the default, regardless of how you launch it.
We've experimented with different context menus for the same control based on various circumstances. However, we ran into problems with the first context menu that we created remaining in place until we destroyed the control (or closed and re-opened the window) and called a new context menu.
At 23 FEB 2003 11:20PM Peter Walter wrote:
Don,
With controls for which I did NOT program my own context menu, if I right-click, the default context menu (the one with the edit options) appears. If I use the accelerator key, the default context menu does NOT appear.
With controls for which I have created my context menu, both a right-click AND the accelerator key works.
I was just curious as to why the default context menu will not appear when triggered programatically, but I suppose I can live with the result.
Peter