Page 1 of 1

Redirect F1 key and define maximized window

Posted: Fri Oct 15, 2021 12:38 pm
by mol
Hi guys!
I'm wonder if is the way t o redirect F1 key in whole application to another function tha windows help procedure.
I know I can use SET KEY F1.... but it must be used separately for every defined window.

And second question.
How to define maximized window to whole screen?
We can maximize it after definition, but it causes flickering

Re: Redirect F1 key and define maximized window

Posted: Fri Oct 15, 2021 7:52 pm
by edk
Hi Marek.
mol wrote: Fri Oct 15, 2021 12:38 pm Hi guys!
I'm wonder if is the way t o redirect F1 key in whole application to another function tha windows help procedure.
I know I can use SET KEY F1.... but it must be used separately for every defined window.
Without change in sources, I think there's probably no other way.
mol wrote: Fri Oct 15, 2021 12:38 pm And second question.
How to define maximized window to whole screen?
We can maximize it after definition, but it causes flickering
I do this in that way:

Code: Select all

#include "hmg.ch"

#define SM_CXFRAME	32
#define SM_CYFRAME	33

Function Main
Local nXSizeFrame := GetSystemMetrics( SM_CXFRAME )
Local nYSizeFrame := GetSystemMetrics( SM_CYFRAME )

Public nMaximizedWindowCol    := 0 - nXSizeFrame
Public nMaximizedWindowRow    := 0 - nYSizeFrame
Public nMaximizedWindowWidth  := GetDesktopRealWidth()  + nXSizeFrame * 2
Public nMaximizedWindowHeight := GetDesktopRealHeight() + nYSizeFrame * 2
  
	DEFINE WINDOW Form_1 ;
		AT nMaximizedWindowRow, nMaximizedWindowCol ;
		WIDTH nMaximizedWindowWidth ;
		HEIGHT nMaximizedWindowHeight ;
		TITLE 'Demo' ;
		MAIN 
 
	END WINDOW

	ACTIVATE WINDOW Form_1

Return

Re: Redirect F1 key and define maximized window

Posted: Fri Oct 15, 2021 8:01 pm
by mol
Thanks!
I'll try!

Re: Redirect F1 key and define maximized window

Posted: Sat Oct 16, 2021 10:45 am
by edk
edk wrote: Fri Oct 15, 2021 7:52 pm
mol wrote: Fri Oct 15, 2021 12:38 pm Hi guys!
I'm wonder if is the way t o redirect F1 key in whole application to another function tha windows help procedure.
I know I can use SET KEY F1.... but it must be used separately for every defined window.
Without change in sources, I think there's probably no other way.
But I was wrong, we can do it by using a trick with Create Event :mrgreen: :idea:

Code: Select all

#include "hmg.ch"

#define SM_CXFRAME	32
#define SM_CYFRAME	33

Function Main
Local nXSizeFrame := GetSystemMetrics( SM_CXFRAME )
Local nYSizeFrame := GetSystemMetrics( SM_CYFRAME )
Local nEventIdx

Public nMaximizedWindowCol    := 0 - nXSizeFrame
Public nMaximizedWindowRow    := 0 - nYSizeFrame
Public nMaximizedWindowWidth  := GetDesktopRealWidth()  + nXSizeFrame * 2
Public nMaximizedWindowHeight := GetDesktopRealHeight() + nYSizeFrame * 2
  
	DEFINE WINDOW Form_1 ;
		AT nMaximizedWindowRow, nMaximizedWindowCol ;
		WIDTH nMaximizedWindowWidth ;
		HEIGHT nMaximizedWindowHeight ;
		TITLE 'Window1' ;
		MAIN 

		ON KEY F2 ACTION MsgInfo("F2 key pressed")

		@  2,10 LABEL Label_1 ;
			WIDTH 100 HEIGHT 20 ;
			VALUE 'Press F1' ;
			ACTION HMG_PressKey ( VK_F1 )

		@  2,120 LABEL Label_2 ;
			WIDTH 100 HEIGHT 20 ;
			VALUE 'Press F2' ;
			ACTION HMG_PressKey ( VK_F2 )

		@ 30,10 BUTTON Button_1 ;
			CAPTION 'Window 2' ;
			ACTION Window2() ;
			TOOLTIP 'WINDOW 2'

		@ 70,10 BUTTON Button_2 ;
			CAPTION 'Release' ;
			ACTION ThisWindow.Release 
	END WINDOW

	CREATE EVENT PROCNAME F1_KEY_TRAP() STOREINDEX nEventIdx

	ACTIVATE WINDOW Form_1

Return

Procedure WINDOW2()
	IF isWindowDefined( Form_2 )
		DoMethod('Form_2','SetFocus')
		DoMethod('Form_2','Restore')
		Return
	ENDIF
	
	DEFINE WINDOW Form_2 ;
		AT nMaximizedWindowRow, nMaximizedWindowCol ;
		WIDTH nMaximizedWindowWidth ;
		HEIGHT nMaximizedWindowHeight ;
		TITLE 'Window2'  

		@  2,10 LABEL Label_1 ;
			WIDTH 100 HEIGHT 20 ;
			VALUE 'Press F1' ;
			ACTION HMG_PressKey ( VK_F1 )

		@ 70,10 BUTTON Button_2 ;
			CAPTION 'Release' ;
			ACTION ThisWindow.Release 
	END WINDOW

	ACTIVATE WINDOW Form_2
Return
************************************************************
FUNCTION F1_KEY_TRAP()
LOCAL  nHWnd := EventHWND ()
LOCAL  nMsg := EventMSG ()
//LOCAL  nWParam := EventWPARAM ()
//LOCAL  nLParam := EventLPARAM ()
LOCAL  cFormName 

#define WM_ACTIVATE    6

IF nMsg = WM_ACTIVATE
	cFormName := GetFormNameByIndex(GetFormIndexByHandle( nHWnd ))
	ON KEY F1 OF &(cFormName) ACTION MsgInfo("FormName: " + ThisWindow.Name + CRLF + ;
						 "Form Title: " + ThisWindow.Title + CRLF + ;
						 "width :=" + AllTrim( hb_ValToStr(ThisWindow.Width) ) + CRLF + ;
						 "height:=" + AllTrim( hb_ValToStr(ThisWindow.Height) ) + CRLF + ;
						 "row   :=" + AllTrim( hb_ValToStr(ThisWindow.Row) ) + CRLF + ;
						 "col   :=" + AllTrim( hb_ValToStr(ThisWindow.Col) ) )

EndIF
RETURN

Re: Redirect F1 key and define maximized window

Posted: Fri Oct 29, 2021 10:00 am
by edk
mol wrote: Fri Oct 15, 2021 12:38 pm And second question.
How to define maximized window to whole screen?
We can maximize it after definition, but it causes flickering
Marek, try this simple trick: define the window as NOSHOW and ON INIT define the "Maximize" and "Show" methods, example:

Code: Select all

#include "hmg.ch"
Function Main
  
	DEFINE WINDOW Form_1 ;
		AT 50, 50 ;
		WIDTH 400 ;
		HEIGHT 300 ;
		TITLE 'Demo Maximized' ;
		MAIN ;
		NOSHOW ;
		ON INIT ( ThisWindow.Maximize, ThisWindow.Show )
 
	END WINDOW

	ACTIVATE WINDOW Form_1

Return

Re: Redirect F1 key and define maximized window

Posted: Fri Oct 29, 2021 12:16 pm
by mol
Thank you!