Window's Title to Center

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

Post Reply
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Window's Title to Center

Post by Pablo César »

How do I make the Window's Title align in “Center” not in “Left”.

How do I change the window's title alignment to center ? Like this:
a.jpg
a.jpg (13.45 KiB) Viewed 2611 times
I have tried to set Window's font to Courier New which is monospaced (fixed-width) but for title is not working.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
esgici
Posts: 4532
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 407 times
Been thanked: 116 times
Contact:

Post by esgici »

Pablo César wrote:How do I make the Window's Title align in “Center” not in “Left”.
How do I change the window's title alignment to center ? Like this:
a.jpg
I have tried to set Window's font to Courier New which is monospaced (fixed-width) but for title is not working.
IMHO this is another unbreakable Windows rule : Window title must be left aligned ! :(

Regards
Viva INTERNATIONAL HMG :D

User avatar
gfilatov
Posts: 747
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 29 times
Been thanked: 367 times
Contact:

Post by gfilatov »

Pablo César wrote: How do I change the window's title alignment to center ?
Hello Pablo,

Please be so kind to try the following simple sample:

Code: Select all

/*
 * MiniGUI Window Demo
 * (c) 2012 Grigory Filatov
*/

#include "hmg.ch"

Procedure Main

	SET MULTIPLE OFF

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 ;
		HEIGHT 480 ;
		TITLE 'Main Window' ;
		MAIN ;
		ON INIT MoveTitle() ;
		ON MAXIMIZE MoveTitle() ;
		ON SIZE MoveTitle() ;
		BACKCOLOR GRAY

	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

Procedure MoveTitle()

	ThisWindow.Title := xPadC( 'Main Window', ThisWindow.Width * 1.2 - 40 )

Return

function xPadC( cText, nPixels, cChar )

   local cRet    := If( Valtype( cText ) == "C", AllTrim( cText ), "" )
   local nLen    := Len( cText )
   local nPixLen
   local nPad

   DEFAULT cChar := Chr(32)

   nPixLen := GetTextWidth( , cText )
   nPad    := GetTextWidth( , cChar )

   if nPixels > nPixLen
      cRet := PadC( cRet, Int( nLen + ( nPixels - nPixLen ) / nPad ), cChar )
   endif

return cRet
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César »

Wow Master ! Thank you for your indications, Mr. Grigory. It is almost quite 100% OK, but in order to avoid "..." as part of title shown, I have make some changings. Probably it is for my Windows is not main Window. Ssorry I have mentioned as main but in real is MODAL and with NOSIZE and NOSYSMENU. So I subtract -70 (wich is not exact value) but it approximally center aligned.

Could you please explain why in you code is subtracted 40 ?

I have adapted my STRU code like this:

Code: Select all

..//..
DEFINE WINDOW MyAlert AT 0, 0  ;
    WIDTH 425 HEIGHT 155       ;
	TITLE cTitle MODAL         ;
	ON INIT MoveTitle(cTitle)  ;
	NOSIZE NOSYSMENU
...//..

Function MoveTitle(cTitle)
ThisWindow.Title := xPadC( cTitle, (ThisWindow.Width - 70) * 1.2 ) // please note here
Return Nil
If I do not change your code ,ThisWindow.Width * 1.2 - 40 ) for ,(ThisWindow.Width - 70) * 1.2 ) then my window is going to show these caracters "...", please see picture below:
Screen40.PNG
Screen40.PNG (9.7 KiB) Viewed 2580 times
I feel I am so near to reach a final solution regarding this value subtracted and I wish to avoid these points... so It will be very much appreciated your explanation about this subtracted value and why to multiply with 1.2 ?. Any way thanks again Mr. Grigory ! :D
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
esgici
Posts: 4532
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 407 times
Been thanked: 116 times
Contact:

Post by esgici »

Apparently, unbreakable is for novices like me; not for gurus ;)

Thanks Grigory :)

Regards
Viva INTERNATIONAL HMG :D

User avatar
srvet_claudio
Posts: 2072
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 46 times
Been thanked: 187 times
Contact:

Post by srvet_claudio »

Hi Pablo.
Test with:

Code: Select all

 ON INIT RTrim (MoveTitle(cTitle))  ;

Best regards,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César »

srvet_claudio wrote:Hi Pablo.
Test with:

Code: Select all

 ON INIT RTrim (MoveTitle(cTitle))  ;

Best regards,
Claudio.
GRANDE, amigo ! Buena idea ! Muchas gracias.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

Post Reply