how to catch mouse event in a grid ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

How to catch mouse event in a grid ?

Post by jpp »

hi to all

i'm trying to catch some mouse event in a a grid but i can not !
event WM_KEYPRESS is catched, but none of the mouse.
Where is my mistake please ?

Code: Select all

/*
* HMG Virtual Grid Demo
* (c) 2003 Roberto Lopez
*/

#include "hmg.ch"

Function Main
	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 450 ;
		HEIGHT 400 ;
		TITLE 'Hello World!' ;
		MAIN 

		@ 10,10 GRID Grid_1 ;
		WIDTH 400 ;
		HEIGHT 330 ;
		HEADERS {'Column 1'} ;
		WIDTHS {140};
		VIRTUAL ;
		ITEMCOUNT 1000 ;
		ON QUERYDATA QueryTest()

	END WINDOW

	create event procname test HWND form_1.grid_1.handle

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

proc test
local msg:= eventmsg()
do case
case msg== WM_KEYDOWN
	msgbox("key_down")
case msg== WM_MOUSEWHELL
	msgbox("Mouse wheel")
case msg== WM_LBUTTONDOWN
	msgbox("Mouse lbtn Down")
case msg== WM_RBUTTONDOWN 
	msgbox("Mouse Rbtn Down")
endcase
return nil


Procedure QueryTest()
    This.QueryData := Str ( This.QueryRowIndex ) + ',' + Str ( This.QueryColIndex )
Return
Italia1
Posts: 60
Joined: Mon Mar 24, 2014 10:55 am
Location: Italia

Re: how to catch mouse event in a grid ?

Post by Italia1 »

Hi jpp,
I don't know if I can help you, but I see WM_NCMOUSEMOVE, WM_NCLBUTTONDOWN, WM_NCLBUTTONUP, WM_NCLBUTTONDBLCLK, WM_NCRBUTTONDOWN, WM_NCRBUTTONUP, WM_NCRBUTTONDBLCLK, WM_NCMBUTTONDOWN, WM_NCMBUTTONUP, WM_NCMBUTTONDBLCL.
I hope you helpful.
I use the great HMG3.2(stable). Have i nice international HMG to everyone!
jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

Re: how to catch mouse event in a grid ?

Post by jpp »

hello italia1,

Thx for answer but in the grid mouse events are windows events and are not catch by create event.
I've found a workaround by 'patching' the events function in the source code and now i can catch everything !

if someone have interest for that, i will publish it !

bye
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: how to catch mouse event in a grid ?

Post by serge_girard »

Hello jpp,

I have interest!

Thx, Serge
There's nothing you can do that can't be done...
jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

Re: how to catch mouse event in a grid ?

Post by jpp »

here the way :

Code: Select all


Here is the patch of the event fnt ( H_WINDOWS.PRG )

*-------------------------------------------------------------------------------------------------------------------*
Function EventProcess (hWnd, nMsg, wParam, lParam, IsKeyboardMessage, IsHMGWindowsMessage, nHookID, nHookCode)
*-------------------------------------------------------------------------------------------------------------------*
LOCAL nIndex
LOCAL cProcName, Ret := NIL
LOCAL lProcessMessage

   FOR nIndex = 1 TO HMG_LEN (_HMG_EventData)

      lProcessMessage := .F.
      IF EventProcessAllHookMessage (nIndex) == .T.
         lProcessMessage := .T.
      ELSEIF EventProcessHMGWindowsMessage (nIndex) == .T. .AND. IsHMGWindowsMessage == .T.
         lProcessMessage := .T.
      ELSEIF EventProcessKeyboardMessage   (nIndex) == .T. .AND. IsKeyboardMessage   == .T.
         lProcessMessage := .T.
      *-- Deb Jpp
      ELSEIF AT("BYPASS", UPPER( EventGetPROCNAME (nIndex))) > 0
          lProcessMessage := .T.
      *-- Fin Jpp      
      ENDIF

      IF EventCompareParam (_HMG_EventData[nIndex][2], hWnd) .AND. ;
         EventCompareParam (_HMG_EventData[nIndex][3], nMsg) .AND. ;
         EventSTOP (nIndex) <> .T.                           .AND. ;
         lProcessMessage == .T.

         EventSTOP (nIndex, .T.)   // avoids re-entry
         _PushEventInfo()
            _HMG_EventIsInProgress        := .T.
            _HMG_EventIsKeyboardMessage   := IsKeyboardMessage
            _HMG_EventIsHMGWindowsMessage := IsHMGWindowsMessage
            _HMG_EventHookID              := nHookID
            _HMG_EventHookCode            := nHookCode
            _HMG_EventINDEX               := nIndex
            _HMG_EventHWND                := hWnd
            _HMG_EventMSG                 := nMsg
            _HMG_EventWPARAM              := wParam
            _HMG_EventLPARAM              := lParam
            _HMG_EventPROCNAME            := ALLTRIM (EventGetPROCNAME (nIndex))
            cProcName := _HMG_EventPROCNAME
            IF HB_URIGHT(cProcName, 1) <> ")"
               Ret := &cProcName()
            ELSE
               Ret := &cProcName
            ENDIF
            _HMG_EventIsInProgress := .F.
         _PopEventInfo()
         EventSTOP (nIndex, .F.)   // restore entry
      ENDIF
   NEXT

Return Ret    



Then if the name of your create event proc have 'Bypass' in the name
you catch all events of the control.


Example :

create event procname Check_Event_bypass() HwND form_1.GRID_1.HANDLE 



#define DO_EVENT    Nil
#define NO_EVENT    1

proc check_event_bypass()

local nMsg:= eventMsg()


if nMsg==WM_MOUSEWHEEL  
    return  NO_EVENT
elseif nMsg==WM_MOUSEMOVE
    return NO_EVENT    
elseif nMsg== WM_LBUTTONDOWN    
    return DO_EVENT
elseif nMsg== WM_RBUTTONDOWN
    return DO_EVENT
elseif nMsg== WM_KEYUP    
    return DO_EVENT
elseif nMsg== WM_KEYDOWN  
......

User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: how to catch mouse event in a grid ?

Post by serge_girard »

Thanks for sharing JPP !

Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

how to catch mouse event in a grid ?

Post by Pablo César »

Nice implementation JPP ! (I wish t know your real name :P ) I thought was not possible to do it... Thank you to share your experience in all around for events propierties.

Just for good understanding for rest of colleagues I make a demo after changings with ByPass in H_WINDOWS.PRG source lib file:

Code: Select all

#include <hmg.ch>

#define DO_EVENT    Nil
#define NO_EVENT    1

#define WM_MOUSEMOVE      512    // 0x0200      // ok
#define WM_LBUTTONDOWN    513    // 0x0201      // ok
#define WM_LBUTTONUP      514    // 0x0202      // ok

#define WM_RBUTTONDOWN    516    // 0x0204      // ok
#define WM_RBUTTONUP      517    // 0x0205      // ok
#define WM_MOUSEWHEEL     522    // 0x020A      // ok
/*
#define WM_KEYDOWN        256    // 0x0100
#define WM_KEYUP          257    // 0x0101
#define WM_MOUSEHOVER     673    // 0x02A1
#define WM_MOUSELEAVE     675    // 0x02A3
*/

Function Main
Private cMsg

DEFINE WINDOW Form_1 ;
    AT 0,0 ;
    WIDTH 430 ;
    HEIGHT 500 ;
    TITLE 'Demo Events' ;
    MAIN NOSIZE
    
    DEFINE STATUSBAR FONT "Courier New" SIZE 9
        STATUSITEM PadC("",75)
    END STATUSBAR
    
    @ 10,10 GRID Grid_1 ;
        WIDTH 400 ;
        HEIGHT 330 ;
        HEADERS {'Column 1','Column 2','Column 3'} ;
        WIDTHS {120,120,120} ;
        VIRTUAL ;
		CELLNAVIGATION ;
        ITEMCOUNT 1000 ;
        ON QUERYDATA QueryTest()
	
	@ 360, 50 CHECKBOX Check_1 CAPTION 'Switch behaviour' WIDTH 150
	
	@ 360, 250 TEXTBOX Text_1 ;
		VALUE "" ;
		TOOLTIP 'Just Setting Focus and test'
		
	@ 400,10 LABEL Label_1 VALUE "Test with: keys Down and Up | Mouse Wheel | Mouse Left Btn | Mouse Right Btn" WIDTH 400 HEIGHT 60 FONT 'Arial' SIZE 8
	
	@ 420,60 LABEL Label_2 VALUE "Mouse moving | Switch Check Box | Set Focus in TextBox" WIDTH 400 HEIGHT 60 FONT 'Arial' SIZE 8
	
END WINDOW
CREATE EVENT PROCNAME Check_Event_ByPass() HwND form_1.GRID_1.HANDLE
// CREATE EVENT PROCNAME Check_Event_Form() 
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil

Function Check_Event_Form()
Local WM_:=EventMSG()

IF EventHWND() == Form_1.HANDLE
   DO CASE
      CASE WM_ == WM_KEYDOWN
           msgbox("key_down")
      CASE WM_ == WM_MOUSEWHEEL
           msgbox("Mouse wheel")
      CASE WM_ == WM_LBUTTONDOWN
           msgbox("Mouse lbtn Down")
      CASE WM_ == WM_RBUTTONDOWN 
           msgbox("Mouse Rbtn Down")
   ENDCASE
ENDIF
Return Nil

Function Check_Event_ByPass()
Local nMsg := EventMsg()
Local xRet := DO_EVENT

DO CASE
   CASE nMsg == WM_KEYUP
        cMsg:="key_up"
		xRet:=NO_EVENT
   CASE nMsg == WM_KEYDOWN
        cMsg:="key_down"
		xRet:=NO_EVENT
   CASE nMsg == WM_MOUSEWHEEL
        cMsg:="Mouse wheel"
		xRet:=NO_EVENT
   CASE nMsg == WM_MOUSEMOVE
		cMsg:="Mouse move"
		xRet:=NO_EVENT
   CASE nMsg == WM_LBUTTONDOWN
        cMsg:="Mouse lbtn Down"
   CASE nMsg == WM_RBUTTONDOWN 
        cMsg:="Mouse Rbtn Down"
ENDCASE
If GetProperty("Form_1","Check_1","Value")=.T.
   xRet:=If(xRet==DO_EVENT,NO_EVENT,DO_EVENT)
Endif
Form_1.StatusBar.Item(1):=cMsg
Return xRet

Procedure QueryTest()
This.QueryData := Str ( This.QueryRowIndex ) + ',' + Str ( This.QueryColIndex )
Return Nil
Nice work jpp and thanks. I hope all of you will enjoy it !
MouseGridEvents (Executable Demo file).rar
(839.78 KiB) Downloaded 366 times
I also wish to ask to Dr. Soto if this jpp implementation:

Code: Select all

*-- Deb Jpp
      ELSEIF AT("BYPASS", UPPER( EventGetPROCNAME (nIndex))) > 0
          lProcessMessage := .T.
*-- Fin Jpp
Could be added at H_WINDOWS.PRG source lib file. What do you think about Claudio ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

Re: how to catch mouse event in a grid ?

Post by jpp »

thanks Pablo to have some interest for my work ...

I'have made an other patch to the source code to avoid to create an array of itemcount element in a virtual grid when you specify a dynamicback of forecolor.

I'had posted about that problem but with no answer i've found a good workaround.

Ps: My name is Jean Pierre, old programmer since .... a big lot of time and i'm very impressived by the work made by the HMG community !

good weekend to all !
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: how to catch mouse event in a grid ?

Post by serge_girard »

Little joke:

event : how to catch a mouse in a grid ?

Serge
There's nothing you can do that can't be done...
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: how to catch mouse event in a grid ?

Post by Javier Tovar »

En verdad bonita aplicación, Felicidades app y demás que contribuyen a que esto sea una realidad.

Saludos
Post Reply