I'm trying to get access to font parameters in MapInfo from
Windows API calls (so someday I will be able to determine exact
text string sizes in pixels for exact map text placement), but
I'm seem to have encountered a basic flaw in my assumptions. I
thought that if you could get a mapper's Device Context, then
MapInfo's currently set font would be loaded in that DC. Perhaps
not, as the following short MB scrapplication suggests.

My question is, "How can I use API functions like
GetTextExtent(), GetTextMetrics(), etc. for the font currently
set with MapBasic's Set Style statement?" Or is there another
way?

The following code shows that the default font associated with a
mapper's DC has nothing to do with the font associated with the
Set Style statement. I set "Times New Roman", but the DC is still
using "System." Or did I overlook something? How do I get access
to a particular font setting? Do I need to call CreateFont() and
all its associated baggage like LOGFONT structures and related
font functions?

If anyone knows, I'd appreciate enlightment here. I'll summarize
in a few days.

- Bill Thoen

'-----
define Long Integer
Declare Function GetDC Lib "user32" 
  Alias "GetDC" (
  ByVal hwnd As Long) 
  As Long
Declare Function GetTextFace Lib "gdi32" 
  Alias "GetTextFaceA" (
  ByVal hdc As Long, 
  ByVal nCount As Long, 
  lpFacename As String) 
  As Long
Declare Sub ReleaseDC Lib "user32" 
  Alias "ReleaseDC" (
  ByVal hwnd As Long, 
  ByVal hdc As Long) 

include "mapbasic.def"
declare sub main

sub main
dim hWnd, hDC as integer
dim nResult as integer
dim sTextFace as string

  print chr$(12)
  close all interactive

  'Get a mapper open
  open table "World" interactive
  map from World

  'Change the default font?
  set style font 
      makefont ("Times New Roman", 0, 12, BLACK, -1)

  'Get a Windows handle to the mapper
  hWnd = WindowInfo (FrontWindow(), WIN_INFO_WND)

  'Get that window's Device Context 
  hDC = GetDC (hWnd)

  'Get the DC's current text face setting
  nResult = GetTextFace (hDC, 30, sTextFace)

  if nResult > 0 then
    'Why is it not "Times New Roman?"
    print " Text face is " + sTextFace
  end if

  'Clean up
  call ReleaseDC (hWnd, hDC)

end sub
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]

Reply via email to