how to identify which Control is a that Position ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

how to identify which Control is a that Position ?

Post by AUGE_OHR »

hi,

for DragDrop i want to know on which Control i drop.
i can get Cursor Position so which API Function give me Information about Control at that Position. :idea:

---

under Xbase++ i can get Pos / Size from each Control so i "just" must compare if Position is in Pos / Size
how to do it with harbour / HMG :?:
have fun
Jimmy
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: how to identify which Control is a that Position ?

Post by mol »

try to adapt this sample - hover effect for labels:

Code: Select all

// OnMouseHover demo
// 2016.06.20 Marek Olszewski

#include "hmg.ch"

Function Main

	private aLabelColors := { => }
	
	aLabelColors [ "KAFEL1" ] := {100,100,100}
	aLabelColors [ "KAFEL2" ] := {100,200,0}
	aLabelColors [ "KAFEL3" ] := {0,200,200}
	
	// turn off case sensitive hash keys matching
	hb_HCaseMatch(aLabelColors, .F.)
	
	DEFINE WINDOW Form_Main ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 600 ;
		TITLE 'Main Window' ;
		MAIN 

		@ 60,10 LABEL KAFEL1 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "OPTION 1";
			BACKCOLOR aLabelColors [ "KAFEL1" ];
			CENTERALIGN
			
		@ 60,220 LABEL KAFEL2 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "OPTION 2";
			BACKCOLOR aLabelColors [ "KAFEL2" ];
			CENTERALIGN
			
		@ 270,220 LABEL KAFEL3 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "OPTION 3";
			BACKCOLOR aLabelColors [ "KAFEL3" ];
			CENTERALIGN

		@ 270,10 LABEL KAFEL4 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "STATIC OPTION NOT COLORIZED";
			BACKCOLOR {255,255,255};
			CENTERALIGN

	END WINDOW

	CENTER WINDOW Form_Main

	CREATE EVENT PROCNAME OnMouseHover( EventWPARAM(), "FORM_MAIN" )  HWND Form_Main.Handle
	
	ACTIVATE WINDOW Form_Main

Return 
*---------------------
function OnMouseHover
	param hWnd, cFormName
	
	LOCAL cControl := ""
	LOCAL cForm := ""
	static cPrevious := ""
	
	GetControlNameByHandle( hWnd, @cControl, @cForm )
		
	if empty(cControl)
		if !empty(cPrevious)
			// set oryginal color to previous control
			SetProperty(cFormName, cPrevious, "BackColor",aLabelColors [ cPrevious ])
			//to prevent flickering
			cPrevious := ""
			return
		endif
	endif
	
	// to avoid errors - eliminate changes for absent controls in aLabelColors array
	if HB_HPOS( aLabelColors,  cControl) == 0
		return
	endif

	
	if !empty(cPrevious)
		// to avoid flickering
		if !(cControl == cPrevious)
			SetProperty(cFormName, cPrevious, "BackColor",aLabelColors [ cPrevious ])
		endif
	endif

	SetProperty(cForm, cControl, "BackColor",{255,255,0})
	cPrevious := cControl
return
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: how to identify which Control is a that Position ?

Post by AUGE_OHR »

hi,
mol wrote: Mon Mar 23, 2020 7:04 am try to adapt this sample - hover effect for labels:
Thx for Tip, i will study Code.
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: how to identify which Control is a that Position ?

Post by AUGE_OHR »

hi,

based on Marek Tip i get this Solution :D

Code: Select all

   GetCursorPos (@nCol, @nRow)   // current Cursor Position
   hWnd := WindowFromPoint (nCol, nRow)     // which WINDOW
   nIndex := GetControlIndexByHandle (hWnd)  // Control Index ( Position of create ? )
   IF nIndex > 0
      // get Type of Child to drop
      cCtrlType := IF( nIndex > 0, GetControlTypeByIndex (nIndex) , "")
      * msginfo(cCtrlType)
      IF cCtrlType = "EDIT"
         // get Name of Control and Form
         GetControlNameByHandle( hWnd, @cControl, @cForm )
         IF !EMPTY( cControl )
---
it does work ... but i don´t understand how :idea:

Code: Select all

CREATE EVENT PROCNAME OnMouseHover( EventWPARAM(), "FORM_MAIN" )  HWND Form_Main.Handle
i know WM_MOUSEHOVER or WM_NCMOUSEHOVER but when search for "OnMouseHover" i get to DotNet :o
https://docs.microsoft.com/de-de/dotnet ... mework-4.8
have fun
Jimmy
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: how to identify which Control is a that Position ?

Post by SALINETAS24 »

AUGE_OHR wrote: Tue Mar 24, 2020 5:57 am hi,

based on Marek Tip i get this Solution :D

Code: Select all

   GetCursorPos (@nCol, @nRow)   // current Cursor Position
   hWnd := WindowFromPoint (nCol, nRow)     // which WINDOW
   nIndex := GetControlIndexByHandle (hWnd)  // Control Index ( Position of create ? )
   IF nIndex > 0
      // get Type of Child to drop
      cCtrlType := IF( nIndex > 0, GetControlTypeByIndex (nIndex) , "")
      * msginfo(cCtrlType)
      IF cCtrlType = "EDIT"
         // get Name of Control and Form
         GetControlNameByHandle( hWnd, @cControl, @cForm )
         IF !EMPTY( cControl )
---
it does work ... but i don´t understand how :idea:

Code: Select all

CREATE EVENT PROCNAME OnMouseHover( EventWPARAM(), "FORM_MAIN" )  HWND Form_Main.Handle
i know WM_MOUSEHOVER or WM_NCMOUSEHOVER but when search for "OnMouseHover" i get to DotNet :o
https://docs.microsoft.com/de-de/dotnet ... mework-4.8

Hola, funciona correctamente, excepto cuando se trata de un FRAME o un SPINNER,
¿hay alguna forma de detectarlos ..?
Saludos
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
Post Reply