Position of a child window

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Position of a child window

Post by bluebird »

Dear Mentors

If I need a child window to appear within its parent, can I specify exactly where
the position will appear inside the parent?

Sorry to ask if answer is obvious.

PS. If its just an ordinary window, is the answer the same?

Thanks
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Position of a child window

Post by Rathinagiri »

Yes. You can!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Re: Position of a child window

Post by bluebird »

Thanks, but please explain.

I found out from HMG reference that you can "center" a window within another window, but how can you "place" it exactly with row and column
values referring to the parent window?

Thanks
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: Position of a child window

Post by serge_girard »

Bluebird try this:

Code: Select all

DEFINE WINDOW        Form_Child   ;
   AT                0,0 ;
   WIDTH             600	;  
   HEIGHT            300 ;
   TITLE             'title ;	
   ICON              "DEFAULT"	;
   NOSIZE; 
   BACKCOLOR         somecolor;
   CHILD;
   FONT              "Arial" SIZE 09 ;
   TOPMOST
The AT property !

Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Position of a child window

Post by edk »

Try to use <ParentWindowName>.Row and <ParentWindowName>.Col into define of child window.
Sample:

Code: Select all

#include "hmg.ch"

Function Main

	DEFINE WINDOW Win_1 ;
		ROW 200 ;
		COL 200 ;
		WIDTH 400 ;
		HEIGHT 400 ;
		TITLE 'Hello World!' ;
		WINDOWTYPE MAIN  
		 
		DEFINE BUTTON Win2
		ROW     10
		COL     10
		WIDTH   170
		HEIGHT  28
		CAPTION "Child Window"
		ACTION  def_child_win()
		END BUTTON

	END WINDOW

	Win_1.Activate
Return

Function def_child_win()
	DEFINE WINDOW Win_2 ;
		ROW Win_1.Row ;
		COL Win_1.Col ;
		WIDTH 300 ;
		HEIGHT 300 ;
		TITLE 'Child' ;
		WINDOWTYPE CHILD  
	
	
	DEFINE BUTTON UL
		ROW     5
		COL     5
		WIDTH   100
		HEIGHT  28
		CAPTION "UpperLeft"
		ACTION  ( SetProperty('Win_2','Row',Win_1.Row), SetProperty('Win_2','Col',Win_1.Col) )
	END BUTTON
	
	DEFINE BUTTON UR
		ROW     5
		COL     180
		WIDTH   100
		HEIGHT  28
		CAPTION "UpperRight"
		ACTION  ( SetProperty('Win_2','Row',Win_1.Row), SetProperty('Win_2','Col', (Win_1.Col) + (Win_1.Width) - (Win_2.Width) ))
	END BUTTON
	
	DEFINE BUTTON BL
		ROW     225
		COL     5
		WIDTH   100
		HEIGHT  28
		CAPTION "BottomLeft"
		ACTION  ( SetProperty('Win_2','Row', (Win_1.Row) + (Win_1.HEIGHT) - (Win_2.HEIGHT) ), SetProperty('Win_2','Col',Win_1.Col) )
	END BUTTON
	
	DEFINE BUTTON BR
		ROW     225
		COL     180
		WIDTH   100
		HEIGHT  28
		CAPTION "BottomRight"
		ACTION  ( SetProperty('Win_2','Row', (Win_1.Row) + (Win_1.HEIGHT) - (Win_2.HEIGHT) ) , SetProperty('Win_2','Col', (Win_1.Col) + (Win_1.Width) - (Win_2.Width) ))
	END BUTTON
	
	DEFINE BUTTON CE
		ROW     105
		COL     90
		WIDTH   100
		HEIGHT  28
		CAPTION "Center"
		ACTION  ( SetProperty('Win_2','Row', (Win_1.Row) + (Win_1.HEIGHT /2) - (Win_2.HEIGHT /2) ) , SetProperty('Win_2','Col', (Win_1.Col) + (Win_1.Width /2) - (Win_2.Width /2) ))
	END BUTTON
	
	END WINDOW
	Win_2.Activate
Return
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Re: Position of a child window

Post by bluebird »

Thanks to Serge and Mr edk, I can now do what I wished, ie. set a small window pecisely within a larger parent window.
The code below shows what I learned to do. It deeds a lot of fiddeling with the precise setting as you can see from the Local variables
needed to make the fit exact.

If anyone tries to run it, I could benefit from any suggested improvments

Thanks
/*
* HMG General Test Utility
*
* ..\build gentestx
*/


#include "hmg.ch"

#define USEROFFSET 35

#define NEWLINE 13
#define DODGERBLUE {28,134,248}
#define MYVASEBLUE {121,147,172}
#define LIGHTGOLDENROD {238 ,221 ,130 }
#define MAROON {238 ,48 ,100 }
#define COBALT1 {0,71,171}
#define COBALT2 {61,82,200}
#define TESTCOLOR {40,165,85}
#define MAXSUMTERMS 20
#define MAXPLOTPOINTS 400

*------------------------------------------------------------*
Function Main
*------------------------------------------------------------*

Local l2Tests:=.t.

SET AUTOSCROLL ON
DEFINE WINDOW Win_1 ;
ROW 10 ;
COL 10 ;
WIDTH 600 ;
HEIGHT 500 ;
BACKCOLOR MYVASEBLUE ;
TITLE 'A General Test Form!' ;
WINDOWTYPE MAIN


Define BUTTON TestIt
Parent win_1
Row 250
Col 25
CAPTION "Click to Test Something"
WIDTH 220
Height 40
ONCLICK DoSomething()
END BUTTON

Define BUTTON TestAnother
Parent win_1
Row 310
Col 25
CAPTION "Click to Test Another"
WIDTH 220
Visible l2Tests
Height 40
ONCLICK DoSomethingElse()
END BUTTON

Define FRAME PlaceWin
Parent win_1
row 250
col 400
width 114
height 160
END FRAME

ON KEY ESCAPE of win_1 action {||(win_1.release)}
END WINDOW

Win_1.Activate

Return

*------------------------------------------------------------*
Function DoSomething()

*------------------------------------------------------------*
#include "hmg.ch"

Local Win_TopLeftRow:=2, Win_TopLeftCol:=2
Local Win_Margin:=2, nCBox_Spc:=30, nCBox_Width:=60
Local nCBox_Col:=Win_TopLeftCol+Win_Margin
Local LabelCol:=nCBox_Col+nCBox_Width+22

If !iswindowdefined("Win_2")
DEFINE WINDOW Win_2 ;
ROW Win_1.Row ;
COL Win_1.Col ;
WIDTH 110 ;
HEIGHT 152 ;
TITLE 'Options' ;
NOMAXIMIZE ;
NOMINIMIZE ;
NOAUTORELEASE ;
NOSIZE ;
WINDOWTYPE CHILD

@ Win_TopLeftRow+Win_Margin,nCBox_Col CHECKBOX cb1 ;
PARENT Win_2 ;
CAPTION "Delay Filter";
VALUE .T.

@ Win_TopLeftRow+nCBox_Spc,nCBox_Col CHECKBOX cb2 ;
PARENT Win_2 ;
CAPTION "Ratio Filter";
VALUE .F.

@ Win_TopLeftRow+2*nCBox_Spc,nCBox_Col CHECKBOX cb3 ;
PARENT Win_2 ;
CAPTION "Diagnostics ";
VALUE .T.

@ Win_TopLeftRow+Win_Margin+8,LabelCol LABEL Lcb1;
PARENT Win_2 ;
value "";
Width 10;
height 10

@ Win_TopLeftRow+nCBox_Spc+8,LabelCol LABEL Lcb2;
PARENT Win_2 ;
value "";
Width 10;
height 10

@ Win_TopLeftRow+2*nCBox_Spc+8,LabelCol LABEL Lcb3;
PARENT Win_2 ;
value "";
Width 10;
height 10

Define BUTTON SelectEm
Parent Win_2
Row Win_TopLeftRow+3*nCBox_Spc
Col nCBox_Col
CAPTION "Verify Selection"
WIDTH 100
Height 30
ONCLICK Confirm()
END BUTTON

END WINDOW



SetProperty('Win_2','Row', Win_1.row+250+USEROFFSET ); SetProperty('Win_2','Col',Win_1.col+410)

Win_2.Activate
EndIf

return


*------------------------------------------------------------*
Function DoSomethingElse()
*------------------------------------------------------------*
msgstop ("Nothing to do yet")

return

*------------------------------------------------------------*
Procedure Confirm()
*------------------------------------------------------------*
If Win_2.cb1.value =.T.
Win_2.lcb1.backcolor:= GREEN
Else
Win_2.lcb1.backcolor:= RED
Endif

If Win_2.cb2.value =.T.
Win_2.lcb2.backcolor:= GREEN
Else
Win_2.lcb2.backcolor:= RED
Endif

If Win_2.cb3.value =.T.
Win_2.lcb3.backcolor:= GREEN
Else
Win_2.lcb3.backcolor:= RED
Endif

return NIL
Post Reply