BIll,
I have not attempted what you are trying from within MB, but I have solved
similar problems from within VB using Integrated Mapping.
A Mapinfo Layout window has no way of centering text from MB (at least it
has never worked correctly). I was able to get centered text in a Layout
window by using VB's Printer.TextWidth function to get the width of the text
and decide where to place it (my function below). Unfortunately, this is not
as precise as I would like it to be. If you also changed the default printer
to the one you are going to use on your layout, it would help, but still not
be perfect.
- Brad
Public Sub TextCenter(ByVal Address As String, x1 As Single, x2 As Single)
Dim A As Integer, b As Integer
Dim W As Single, nl As Integer
' Set the font attributes I am using
Printer.Font = "Times New Roman"
Printer.FontSize = 18
Printer.FontBold = True
Printer.FontItalic = True
' Use inches
Printer.ScaleMode = 5
' If there is a newline in the address then get the longest line
nl = InStr(Address, "\n")
If nl > 0 Then
If nl < (Len(Address) / 2) Then
Address = Mid$(Address, nl + 2)
Else
Address = left$(Address, nl - 1)
End If
End If
' get the width of the line in inches. Cycling the bold attribute is a
workaround to a VB5 bug.
' Haven't tested VB6 to see if bug is gone.
W = Printer.TextWidth("Hello THere")
Printer.FontBold = False
W = Printer.TextWidth("Hello")
Printer.FontBold = True
W = Printer.TextWidth(Address)
' Get the start and ending locations on the page in inches
x1 = ((Printer.ScaleWidth - W) / 2) + 0.2
x2 = ((Printer.ScaleWidth - W) / 2) + W + 0.2
End Sub
> -----Original Message-----
> From: Bill Thoen [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, January 03, 2000 2:05 PM
> To: MapInfo-L
> Subject: MI Question for MB and Win API experts
>
> 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]
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]