FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Using Windows Font
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Using Windows Font
Posted: Mon Jan 26, 2009 05: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Using Windows Font
Posted: Mon Jan 26, 2009 07:22 PM
Try

DEFINE FONT oFnt NAME GETSYSFONT()


EMG
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using Windows Font
Posted: Mon Jan 26, 2009 09: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
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Using Windows Font
Posted: 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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Using Windows Font
Posted: Tue Jan 27, 2009 03:14 AM

Tim,

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

http://vbcity.com/page.asp?f=howtop=system_fontsize

Maybe Antonio or Encrico can translate it to FW.

Regards,
James

&

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using Windows Font
Posted: Tue Jan 27, 2009 01:26 PM
Tim,

I found the same website as James :-)

Here you have it: GetSysFontSize()
#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
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Using Windows Font
Posted: 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
Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Re: Using Windows Font
Posted: Thu Jan 29, 2009 06: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,

Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Using Windows Font
Posted: Thu Jan 29, 2009 07: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

Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Re: Using Windows Font
Posted: 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,

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using Windows Font
Posted: Fri Jan 30, 2009 03:37 PM
Jose Luis,

We copy here the source code of those functions for other users, thanks
#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
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Using Windows Font
Posted: Fri Jan 30, 2009 05:12 PM

Antonio,
would you please post a working example.
Thanks in advance
Otto

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using Windows Font
Posted: Fri Jan 30, 2009 06:41 PM
Otto,

#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

Continue the discussion