How to detect owner of context menu?
Moderator: Rathinagiri
How to detect owner of context menu?
From sometime, each control can have its own contet menu.
Correct menu is displayed even the control is not focused.
Is it the way to detect owner of context menu?
Correct menu is displayed even the control is not focused.
Is it the way to detect owner of context menu?
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
How to detect owner of context menu?
Hi Marek,
Have you seen C:\hmg.3.2\samples\Controls\MENU_ControlContext.1 example ?
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
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: How to detect owner of context menu?
I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
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
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
How to detect owner of context menu?
Very nice Marek !
Functions SETPIXEL and SETCROSSCURSOR are not used in your code.
Your examples is very cool man. Thank you to share.
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
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: How to detect owner of context menu?
SETPIXEL and SETCROSSCURSOR were copied from ide.prg attached by BPD2000. This code is really not used in this sample...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.
SETCROSSCURSOR can be used while moving control.
-
- Posts: 1275
- Joined: Tue Sep 03, 2013 4:22 am
- Location: Tecámac, México
Re: How to detect owner of context menu?
Hola Mol,
Muy buena tu aplicación, Felicidades!
Saludos
Muy buena tu aplicación, Felicidades!
Saludos
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: How to detect owner of context menu?
Wow, good, very good Marek !!!mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Re: How to detect owner of context menu?
Dear Claudiosrvet_claudio wrote:Wow, good, very good Marek !!!mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Request to included MoveControl and ResizeControl in next version of HMG
Regards
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
- 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?
+1bpd2000 wrote:Dear Claudiosrvet_claudio wrote:Wow, good, very good Marek !!!mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Request to included MoveControl and ResizeControl in next version of HMG
Regards
Viva INTERNATIONAL HMG
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: How to detect owner of context menu?
OKbpd2000 wrote:Dear Claudiosrvet_claudio wrote:Wow, good, very good Marek !!!mol wrote:I have to write code to move or resize selected label.
Now, it works OK!
Nice testing!
Request to included MoveControl and ResizeControl in next version of HMG
Regards