How to detect owner of context menu?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

How to detect owner of context menu?

Post by mol »

From sometime, each control can have its own contet menu.
Correct menu is displayed even the control is not focused.

Image

Is it the way to detect owner of context menu?
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

How to detect owner of context menu?

Post by Pablo César »

Hi Marek,

Have you seen C:\hmg.3.2\samples\Controls\MENU_ControlContext.1 example ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to detect owner of context menu?

Post by mol »

I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 * bpd2000@gmail.com
*/

/*
* modified for control moving and context menu testing
* by Marek Olszewski MOL (2014.04.18)
* mol@pro.onet.pl
*
*/

#include "minigui.ch"

FUNCTION MAIN
   Public nTitleBarHeight := GetTitleHeight()
   Public nBorderWidth := GetBorderWidth()
	private i 
	

	Define window oEdit At 0,0 width 600 height 400 main title "Move & Resize Control?" 

   DEFINE STATUSBAR Font "Arial" SIZE 8
			STATUSITEM "" 
		END STATUSBAR

      DEFINE button MoveControl1
         Row 120
         Col 15
         width 120
		 height 30
         caption "TEST BUTTON"
       action MsgBox( "Call context menu of this button to move or resize control" )
       END button

	   DEFINE CONTROL CONTEXTMENU  MoveControl1
			MenuItem "Move button"	action moveControl( "MoveControl1" )
			MenuItem "Resize button"	action ResizeControl( "MoveControl1" )
		END MENU
		
		for i :=1 to 3
			cLabelName := "LBL_"+str(i,1)
			
			define label &cLabelName 
					PARENT oEdit
					row 20
					col 120*(i-1) + 40
					value "Label no. "+ str(i,1)
					Width 110
					Height 40
					Fontsize 10
					tooltip "this is label no.  "+str(i,1)
					Alignment Center
					BackColor {255,255,0}
					TabStop .t.
			end label
			
			bInfoBlock := "msgbox("+str(i,1)+")"
			bMoveBlock := "MoveControl('" + cLabelName  +"')"
			bResizeBlock := "ResizeControl('" + cLabelName  +"')"
			
			DEFINE CONTROL CONTEXTMENU  &cLabelName 
				MenuItem "Label no." +str(i,1)	action &bInfoBlock
				MenuItem "Move label"	action &bMoveBlock
				MenuItem "Resize label"	action &bResizeBlock		
			END MENU
		next i 

End window

oEdit.center
oEdit.activate

return nil

************************************
function CallContextMenu
	
	local i, posx, posy
	local xContextMenuHandle, xFormHandle
	
	
	i := GetControlIndex (This.Name, ThisWindow.Name )
		nScreenRow := LISTVIEW_GETFIRSTITEM ( _HMG_SYSDATA [3] [i] )
		posx := This.Row + This.Height
		posy := This.Col + This.Width

		i := GetFormIndex ( thisWindow.Name )
		xContextMenuHandle := _HMG_SYSDATA [ 74 ][i]
		xFormHandle := _HMG_SYSDATA [ 67 ] [i]
		TrackPopupMenu ( xContextMenuHandle  , posy , posx , xFormHandle )
return
************************************


PROCEDURE MoveControl( cControlName )
   LOCAL ControlHandle

	DoMethod(ThisWindow.Name, cControlName, "SetFocus")

	ControlHandle := GetControlHandle(cControlName, thisWindow.Name)

	InterActiveMove()
	nCurrentCol := GetWindowCol( ControlHandle ) - oEdit.Col - nBorderWidth
	nCurrentRow := GetWindowrow( ControlHandle ) - oEdit.Row - nTitleBarHeight - nBorderWidth
	//nCurrentCol := int(nCurrentCol / 10) * 10
	//nCurrentRow := int(nCurrentRow / 10) * 10

	SetProperty(ThisWindow.Name, cControlName,"Col", nCurrentCol)
	SetProperty(ThisWindow.Name, cControlName,"Row", nCurrentRow)

RETURN

/*----------------------------------------------------------------------*/

PROCEDURE ResizeControl( cControlName )
	LOCAL ControlHandle := GetControlHandle( cControlName, 'oEdit' )
	local nNewWidth, nNewHeight
	
	DoMethod(ThisWindow.Name, cControlName, "SetFocus")
	ControlHandle := GetControlHandle(cControlName, thisWindow.Name)
	InterActiveSize()
	nNewWidth	:= GetWindowWidth( ControlHandle )
	nNewHeight	:= GetWindowHeight( ControlHandle )
	SetProperty(ThisWindow.Name, cControlName,"Width",nNewWidth)
	SetProperty(ThisWindow.Name, cControlName,"Height", nNewHeight )

RETURN

/*----------------------------------------------------------------------*/

*******************************************************

#pragma BEGINDUMP

#include <windows.h>

#include "hbapi.h"

HB_FUNC( SETPIXEL )
{
   hb_retnl( (ULONG) SetPixel( (HDC) hb_parnl( 1 ) ,
				hb_parni( 2 )      ,
				hb_parni( 3 )      ,
			(COLORREF) hb_parnl( 4 ) ) );
}

HB_FUNC( SETCROSSCURSOR )
{
   SetClassLong( ( HWND ) hb_parnl(1), GCL_HCURSOR, ( LONG ) LoadCursor(NULL, IDC_CROSS) );
}

HB_FUNC( INTERACTIVEMOVE )
{
   keybd_event(
      VK_RIGHT,  // virtual-key code
      0,         // hardware scan code
      0,         // flags specifying various function options
      0          // additional data associated with keystroke
      );

   keybd_event(
      VK_LEFT,   // virtual-key code
      0,         // hardware scan code
      0,         // flags specifying various function options
      0          // additional data associated with keystroke
      );

   SendMessage( GetFocus(), WM_SYSCOMMAND, SC_MOVE, 10 );
   RedrawWindow( GetFocus(), NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASENOW | RDW_UPDATENOW );
}

HB_FUNC( INTERACTIVESIZE )
{
   keybd_event(
      VK_DOWN,
      0,
      0,
      0
      );

   keybd_event(
      VK_RIGHT,
      0,
      0,
      0
      );

   SendMessage( GetFocus(), WM_SYSCOMMAND, SC_SIZE, 0 );
}

#pragma ENDDUMP
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

How to detect owner of context menu?

Post by Pablo César »

Very nice Marek !

Functions SETPIXEL and SETCROSSCURSOR are not used in your code.

Your examples is very cool man. Thank you to share.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to detect owner of context menu?

Post by mol »

Pablo César wrote:Very nice Marek !

Functions SETPIXEL and SETCROSSCURSOR are not used in your code.

Your examples is very cool man. Thank you to share.
SETPIXEL and SETCROSSCURSOR were copied from ide.prg attached by BPD2000. This code is really not used in this sample...
SETCROSSCURSOR can be used while moving control.
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: How to detect owner of context menu?

Post by Javier Tovar »

Hola Mol,

Muy buena tu aplicación, Felicidades! :D :D :D

Saludos
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to detect owner of context menu?

Post by srvet_claudio »

mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Wow, good, very good Marek !!!
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: How to detect owner of context menu?

Post by bpd2000 »

srvet_claudio wrote:
mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Wow, good, very good Marek !!!
Dear Claudio
Request to included MoveControl and ResizeControl in next version of HMG
Regards
BPD
Convert Dream into Reality through HMG
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: How to detect owner of context menu?

Post by esgici »

bpd2000 wrote:
srvet_claudio wrote:
mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Wow, good, very good Marek !!!
Dear Claudio
Request to included MoveControl and ResizeControl in next version of HMG
Regards
+1
Viva INTERNATIONAL HMG :D
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to detect owner of context menu?

Post by srvet_claudio »

bpd2000 wrote:
srvet_claudio wrote:
mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Wow, good, very good Marek !!!
Dear Claudio
Request to included MoveControl and ResizeControl in next version of HMG
Regards
OK
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply