Click here to Skip to main content
15,917,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Debug information crashes my app :( Pin
AlexO3-Apr-03 8:52
AlexO3-Apr-03 8:52 
GeneralRe: Debug information crashes my app :( Pin
rbc3-Apr-03 10:18
rbc3-Apr-03 10:18 
GeneralRe: Debug information crashes my app :( Pin
Tim Smith3-Apr-03 10:23
Tim Smith3-Apr-03 10:23 
QuestionPolygon class? Pin
Anonymous3-Apr-03 8:03
Anonymous3-Apr-03 8:03 
AnswerRe: Polygon class? Pin
Maximilien3-Apr-03 8:43
Maximilien3-Apr-03 8:43 
QuestionCan I add a menu item to Internet Explorer Pin
rdautel3-Apr-03 7:44
rdautel3-Apr-03 7:44 
AnswerRe: Can I add a menu item to Internet Explorer Pin
Chris Richardson3-Apr-03 11:39
Chris Richardson3-Apr-03 11:39 
GeneralDrawText - BUG? - When using Italic font, returns incorrect width using DT_CALCRECT Pin
noirs23-Apr-03 7:30
noirs23-Apr-03 7:30 
I'm using the DrawText API, and passing in DT_CALCRECT to query the size of the text.

It works well, but when the font it is italic, and I draw it into the rect returned, it gets cut off by a few pixels!

Below is VB sample code that shows the problem.

Has anyone else seen this? am i doing something wrong? Is this a bug?

Thanks!

- Alex






' Font:
Private Const LF_FACESIZE = 32
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type
Private Const FW_NORMAL = 400
Private Const FW_BOLD = 700
Private Const FF_DONTCARE = 0
Private Const DEFAULT_QUALITY = 0
Private Const DEFAULT_PITCH = 0
Private Const DEFAULT_CHARSET = 1
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const LOGPIXELSY = 90

' Testing the font:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Const DT_CALCRECT = &H400
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long

Public Sub Test(ByVal hdc As Long, fntThis As StdFont)
Dim tLF As LOGFONT
Dim hFnt As Long
Dim hFntOld As Long
Dim tR As RECT

' Create a LOGFONT structure equivalent to the
' StdFont font:
pOLEFontToLogFont fntThis, hdc, tLF

' Convert the LOGFONT into a font handle:
hFnt = CreateFontIndirect(tLF)

' Test the font out:
hFntOld = SelectObject(hdc, hFnt)
DrawText hdc, "NIPIGON", -1, tR, DT_CALCRECT
OffsetRect tR, 32, 32
DrawText hdc, "NIPIGON", -1, tR, 0&
SelectObject hdc, hFntOld

' Always remember to delete the font when finished
' with it:
DeleteObject hFnt

End Sub

Private Sub pOLEFontToLogFont(fntThis As StdFont, ByVal hdc As Long, tLF As LOGFONT)
Dim sFont As String
Dim iChar As Integer
Dim b() As Byte

' Convert an OLE StdFont to a LOGFONT structure:
With tLF
sFont = fntThis.Name
b = StrConv(sFont, vbFromUnicode)
For iChar = 1 To Len(sFont)
.lfFaceName(iChar - 1) = b(iChar - 1)
Next iChar
' Based on the Win32SDK documentation:
.lfHeight = -MulDiv((fntThis.Size), (GetDeviceCaps(hdc, LOGPIXELSY)), 72)
.lfItalic = fntThis.Italic
If (fntThis.Bold) Then
.lfWeight = FW_BOLD
Else
.lfWeight = FW_NORMAL
End If
.lfUnderline = fntThis.Underline
.lfStrikeOut = fntThis.Strikethrough
.lfCharSet = fntThis.Charset
End With

End Sub






Private Sub Command1_Click()

Dim sFnt As New StdFont
sFnt.Name = "Copperplate Gothic Bold"
sFnt.Size = 48
sFnt.Bold = True
sFnt.Italic = True
Test Me.hdc, sFnt

End Sub



GeneralRe: DrawText - BUG? - When using Italic font, returns incorrect width using DT_CALCRECT Pin
Davide Pizzolato3-Apr-03 8:01
Davide Pizzolato3-Apr-03 8:01 
GeneralRe: DrawText - BUG? - When using Italic font, returns incorrect width using DT_CALCRECT Pin
noirs23-Apr-03 8:35
noirs23-Apr-03 8:35 
Generaldeclaring 2D arrays Pin
Anonymous3-Apr-03 7:13
Anonymous3-Apr-03 7:13 
GeneralRe: declaring 2D arrays Pin
Maximilien3-Apr-03 7:16
Maximilien3-Apr-03 7:16 
GeneralComand line error D2016 Pin
ElizabethC3-Apr-03 7:13
ElizabethC3-Apr-03 7:13 
GeneralRe: Comand line error D2016 Pin
AlexO3-Apr-03 8:03
AlexO3-Apr-03 8:03 
GeneralCSocket and threads Pin
Beer3-Apr-03 6:56
Beer3-Apr-03 6:56 
GeneralRe: CSocket and threads Pin
valikac3-Apr-03 8:16
valikac3-Apr-03 8:16 
GeneralRe: CSocket and threads Pin
Beer3-Apr-03 9:15
Beer3-Apr-03 9:15 
GeneralRe: CSocket and threads Pin
markkuk3-Apr-03 9:49
markkuk3-Apr-03 9:49 
GeneralRe: CSocket and threads Pin
Beer3-Apr-03 13:05
Beer3-Apr-03 13:05 
QuestionHow to scroll down a CEdit control? Pin
IGx893-Apr-03 6:54
IGx893-Apr-03 6:54 
GeneralGet Click from subcontroller Pin
Mathias S.3-Apr-03 6:49
Mathias S.3-Apr-03 6:49 
QuestionActiveX on Dialog breaks DialogBoxParam on Callback? Pin
Dan Thurman3-Apr-03 6:46
Dan Thurman3-Apr-03 6:46 
GeneralNetworking woes... Pin
Navin3-Apr-03 6:23
Navin3-Apr-03 6:23 
GeneralRe: Networking woes... Pin
Navin3-Apr-03 10:44
Navin3-Apr-03 10:44 
GeneralDisplaying Forms From A Visual Studio Macro Pin
nde_plume3-Apr-03 5:19
nde_plume3-Apr-03 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.