Using Windows Font

Using Windows Font

Postby TimStone » Mon Jan 26, 2009 5:59 pm

Instead of setting my own font for a program, I simply want to use the current window font. No problem to find out the font, but how about setting the font size ? If my client uses a larger font size I want to use the same in the program.

Thanks
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Using Windows Font

Postby Enrico Maria Giordano » Mon Jan 26, 2009 7:22 pm

Try

Code: Select all  Expand view
DEFINE FONT oFnt NAME GETSYSFONT()


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Using Windows Font

Postby Antonio Linares » Mon Jan 26, 2009 9:09 pm

Tim,

> If my client uses a larger font size I want to use the same in the program

The dialogboxes of your application use some specific dimensions and fonts.

How do you plan to combine both ideas ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using Windows Font

Postby TimStone » Mon Jan 26, 2009 10:48 pm

Right now the client says "the font is too small" . The cursor problem I had was with an Arial font and it went away if I used the system font. So now I change to the system font, size -12 and it works OK. However, some people are used to a smaller font, and some want it larger, and they set that based on their theme and windows setting. I get the same font by using GetSysFont( ) but that doesn't return the size.

If I apply the system font to the application, and it doesn't fit, I can simply tell them to reduce the size of the system font to fix the problem.

It may not be the best answer technically, but it sure is better then dealing with complaints !

GetSysFont( ) does give me the font name, but not the current size.

Right now, I set a master font, oMFont, and then I use that in the main window, and inherit it from the main window in the dialogs.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Using Windows Font

Postby James Bott » Tue Jan 27, 2009 3:14 am

Tim,

Here is some VB code to get the system font size.

http://vbcity.com/page.asp?f=howto&p=system_fontsize

Maybe Antonio or Encrico can translate it to FW.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Using Windows Font

Postby Antonio Linares » Tue Jan 27, 2009 1:26 pm

Tim,

I found the same website as James :-)

Here you have it: GetSysFontSize()
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   MsgInfo( GetSysFontSize() )

return nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( GETSYSFONTSIZE )
{
   HWND hWnd = GetDesktopWindow();
   HDC  hDC  = GetWindowDC( hWnd );
   int iOldMode = SetMapMode( hDC, MM_TEXT );
   TEXTMETRIC tm;
   
   GetTextMetrics( hDC, &tm );
   SetMapMode( hDC, iOldMode );
   ReleaseDC( hWnd, hDC );
   
   hb_retnl( tm.tmHeight );
}

#pragma ENDDUMP   
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using Windows Font

Postby TimStone » Tue Jan 27, 2009 10:15 pm

Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Using Windows Font

Postby José Luis Sánchez » Thu Jan 29, 2009 6:59 am

Tim,
You have the way to use the font from the system, including big fonts at http://www.avemundi.com/?p=216
I use this code in my programs and it's perfect.

Regards,
User avatar
José Luis Sánchez
 
Posts: 556
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España

Re: Using Windows Font

Postby Otto » Thu Jan 29, 2009 7:28 am

Hello José,

I saw your source code and I am very interested in this topic.

Could you please explain where to put this line:
::oFont = TFont():New( GetDefaultFontName(), 0, GetDefaultFontHeight(),, )

Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Using Windows Font

Postby José Luis Sánchez » Fri Jan 30, 2009 11:26 am

::oFont is a data from my Application class. I take this fron system calling GetDefaultFontName() and GetDefaultFontHeight(). After this I can inherit this font in all my dialogs.

Regards,
User avatar
José Luis Sánchez
 
Posts: 556
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España

Re: Using Windows Font

Postby Antonio Linares » Fri Jan 30, 2009 3:37 pm

Jose Luis,

We copy here the source code of those functions for other users, thanks
Code: Select all  Expand view
#pragma BEGINDUMP

#include <Windows.h>
#include <hbapi.h>

HB_FUNC( GETDEFAULTFONTNAME )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT ) , sizeof( LOGFONT ), &lf );
   hb_retc( lf.lfFaceName );
}

HB_FUNC( GETDEFAULTFONTHEIGHT )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT ) , sizeof( LOGFONT ), &lf );
   hb_retni( lf.lfHeight );
}

#pragma ENDDUMP

y en el programa definir de esta manera la fuente de la ventana principal:

::oFont = TFont():New( GetDefaultFontName(), 0, GetDefaultFontHeight(),, )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using Windows Font

Postby Otto » Fri Jan 30, 2009 5:12 pm

Antonio,
would you please post a working example.
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Using Windows Font

Postby Antonio Linares » Fri Jan 30, 2009 6:41 pm

Otto,

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg, oFont

   DEFINE FONT oFont NAME GetDefaultFontName() SIZE 0, -GetDefaultFontHeight()

   DEFINE DIALOG oWnd TITLE "Test" FONT oFont

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

return nil

If you don't want to create and destroy oFont, again and again, you can keep it in a public memvar and reuse it for each dialog.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests