|
-
Nov 22nd, 2000, 11:19 PM
#1
Thread Starter
Fanatic Member
How do you create a font (a simple one like Arial) and select it into a DC using API calls??
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Nov 23rd, 2000, 04:40 AM
#2
Thread Starter
Fanatic Member
I figured it out, here is a little wrapper in case anybody ever runs across the same problem....
Wrapper Function:
Code:
Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Public Const FW_BOLD = 700
Public Const FW_NORMAL = 400
Public Function FontObject(pFontName As String, Optional pHeight As Long = 0, Optional pWidth As Long = 0, Optional pBold As Boolean = False, Optional pItalic As Boolean = False, Optional pUnderline As Boolean = False, Optional pStrikethru As Boolean = False) As Long
Dim lFontOut As Long
Dim lWgt As Long
If pBold = True Then lWgt = FW_BOLD Else lWgt = FW_NORMAL
FontObject = CreateFont(pHeight, 8, 0, 0, lWgt, CLng(pItalic), CLng(pUnderline), CLng(pStrikethru), 0, 0, 0, 0, 0, pFontName)
End Function
Implementation:
Code:
Public Sub Form_Paint()
dim lRet as Long
dim lFont as Long
dim lTempDC as Long
dim lBMP as Long
'Create Font
lFont = FontObject("Comic Sans MS", 24, 0, True, True, True, True)
'Create Temporary DC to Draw to
lTempDC = CreateCompatibleDC(Form1.hDC)
'Create a Temporary Bitmap 50 pixels high by 50 pixels wide
lBMP = CreateCompatibleBitmap(Form1.hDC, 50, 50)
'Prepare DC for drawing
lRet = SelectObject(lTempDC, lBMP)
lRet = SelectObject(lTempDC, lFont)
'Draw My Name onto temporary DC
lRet = TextOut(lTempDC, 0, 0, "Jon", 3)
'Display the temporary DC on the current form
lRet = BitBlt(Form1.hDC, 0, 0, 50, 50, lTempDC, 0, 0, SRCCOPY)
'Take out the trash
lRet = DeleteObject(lBMP)
lRet = DeleteObject(lFont)
lRet = DeleteDC(lTempDC)
End Sub
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|