How to programmatically call the context menu?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

How to programmatically call the context menu?

Post 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
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: How to programmatically call the context menu?

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to programmatically call the context menu?

Post 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?
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: How to programmatically call the context menu?

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
gfilatov
Posts: 1116
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: How to programmatically call the context menu?

Post 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 :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: How to programmatically call the context menu?

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to programmatically call the context menu?

Post 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...
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to programmatically call the context menu?

Post 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
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to programmatically call the context menu?

Post 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?
Post Reply