Page 1 of 2
How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 11:51 am
by mol
How to programmatically call the context menu?
I want to call context menu for browse, after searching record.
1. I don't want to define new window with buttons, because I placed all needed functions in context menu.
How to do it?
2. When I press context menu button on the kayboard, context menu appears in the right down corner of the sceen.
It doesn't look fine - detached from the component (especially in the browse - from current row).
Is it possible to control position of context menu on the screen?
Best regards, MAREK
Re: How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 1:01 pm
by Roberto Lopez
mol wrote:How to programmatically call the context menu?
I want to call context menu for browse, after searching record.
1. I don't want to define new window with buttons, because I placed all needed functions in context menu.
How to do it?
2. When I press context menu button on the kayboard, context menu appears in the right down corner of the sceen.
It doesn't look fine - detached from the component (especially in the browse - from current row).
Is it possible to control position of context menu on the screen?
Best regards, MAREK
Is not clear to me the first part of your post.
Anyway, there is no high level implementation for this yet.
The function to call a context menu is:
Code: Select all
TrackPopupMenu ( MenuHandle , x , y , ParentWIndowHandle )
ParentWindow Handle is easy to get, the problem could be the MenuHandle.
You should first to get the form index in data array.
i := GetFormIndex ( cFormName )
ContextMenuHandle is in: _HMG_SYSDATA [ 74 ]
It should give you control about context menu.
Regards,
Roberto.
Re: How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 1:20 pm
by mol
Normally, you can call context menu using right mouse button or special key on the keyboard.
But I wanna call this menu after searching record automatically.
I've tried:
Code: Select all
i := GetFormIndex ( "OknoZlecenia" )
ContextMenuHandle := _HMG_SYSDATA [ 74 ] [i]
TrackPopupMenu ( ContextMenuHandle , 50 , 50 , "OknoZlecenia" )
where:
OknoZlecenia - is the name of window
but... nothing happens.
What's wrong?
Re: How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 2:15 pm
by Roberto Lopez
mol wrote:Normally, you can call context menu using right mouse button or special key on the keyboard.
But I wanna call this menu after searching record automatically.
I've tried:
Code: Select all
i := GetFormIndex ( "OknoZlecenia" )
ContextMenuHandle := _HMG_SYSDATA [ 74 ] [i]
TrackPopupMenu ( ContextMenuHandle , 50 , 50 , "OknoZlecenia" )
where:
OknoZlecenia - is the name of window
but... nothing happens.
What's wrong?
No.
The last parameter should be GetFormHandle('OknoZlecenia')
Regards,
Roberto.
Re: How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 2:22 pm
by gfilatov
mol wrote:Normally, you can call context menu using right mouse button or special key on the keyboard.
But I wanna call this menu after searching record automatically.
I've tried:
Code: Select all
i := GetFormIndex ( "OknoZlecenia" )
ContextMenuHandle := _HMG_SYSDATA [ 74 ] [i]
TrackPopupMenu ( ContextMenuHandle , 50 , 50 , "OknoZlecenia" )
where:
OknoZlecenia - is the name of window
but... nothing happens.
What's wrong?
Hi Marek,
Please be so kind to try the following
working sample:
Code: Select all
#include "minigui.ch"
Function main()
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 200 ;
TITLE 'Menu Test' ;
MAIN
DEFINE MAIN MENU
POPUP 'File'
ITEM 'Test' ACTION showcontext()
END POPUP
POPUP 'Help'
ITEM 'About' ACTION MsgInfo ('Help:ABout')
END POPUP
END MENU
DEFINE CONTEXT MENU
ITEM 'Item 1' ACTION MsgInfo ('Item 1')
ITEM 'Item 2' ACTION MsgInfo ('Item 2')
SEPARATOR
ITEM 'Item 3' ACTION MsgInfo ('Item 3')
END MENU
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil
Function showcontext()
Local i, ContextMenuHandle, FormHandle
i := GetFormIndex ( "Form_1" )
ContextMenuHandle := _HMG_SYSDATA [ 74 ] [i]
FormHandle := _HMG_SYSDATA [ 67 ] [i]
TrackPopupMenu ( ContextMenuHandle , Form_1.Col + 50 , Form_1.Row + 50 , FormHandle )
Return Nil
I hope that helps

Re: How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 4:22 pm
by Roberto Lopez
gfilatov wrote:
Please be so kind to try the following
working sample:
Code: Select all
#include "minigui.ch"
[/quote]
Thanks for the sample.
Regards,
Roberto.
Re: How to programmatically call the context menu?
Posted: Tue Oct 27, 2009 8:54 pm
by mol
Many thanks, guys!
Re: How to programmatically call the context menu?
Posted: Wed Oct 28, 2009 6:50 am
by mol
Following this, I wanna ask, if it is possible to determine screen position of selected row in the browse.
It will be superfine, when context menu will appear exactly under seected row...
Re: How to programmatically call the context menu?
Posted: Wed Oct 28, 2009 7:40 am
by mol
I've reached satisfactory result.
Below modified code of Grigori sample:
PS. If somebody want to test it, remember to define Browse_1
Code: Select all
Function showcontext()
Local i, ContextMenuHandle, FormHandle, nScreenRow, posx, posy
i := GetControlIndex ( "Browse_1", "Form_1" )
nScreenRow := LISTVIEW_GETFIRSTITEM ( _HMG_SYSDATA [3] [i] )
posx := Form_1Row + Form_1.Browse_1.Row + (nScreenRow+3) * (Form_1.Browse_1.FontSize + 1)
posy := Form_1.Col + Form_1.Browse_1.Col + Form_1.Browse_1.Width/2
i := GetFormIndex ( "Form_1" )
ContextMenuHandle := _HMG_SYSDATA [ 74 ] [i]
FormHandle := _HMG_SYSDATA [ 67 ] [i]
TrackPopupMenu ( ContextMenuHandle ,posy , posx, FormHandle )
Return Nil
Re: How to programmatically call the context menu?
Posted: Wed Oct 28, 2009 7:42 am
by mol
Working with context menu, I think, it will be fine to define context menu for exact component, not for whole window.
maybe it's future?