CreateFontIndirect를 사용한 문자열 세로 출력
CreateFontIndirect는 CreateFont는 논리적 폰트를 생성하는 것은 같다.
그러나 CreateFontIndirect는 CreateFont와 달리는 논리적 폰트에 대한 생성 정보를 함수의 인수로 각각 지정하지 않고, LOGFONT라는 구조체를 사용해서 폰트의 정보를 지정하는것이 다르다.
아래는 CreateFontIndirect를 사용해서 폰트를 회전시겨 세로로 표시되게 하는 논리적 폰트 생성한 이미지이다.
상단의 가로로 출력된 문자열은 원래의 폰트에 대한 출력이고, 아래의 세로로 표시된 문자열은 CreateFontIndirect를 사용해 생성한 논리적 폰트로 출력을 표시한 것이다.
다음은 소스이다.
' 논리적 폰트 생성 문자열을 회전해서 세로로 출력
Option Explicit
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
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 Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim RotateMe As LOGFONT ' 논리적 폰트 생성 정보
Dim FontHandle As Long ' 생성한 폰트 핸들
Dim PreviousFontHandle As Long ' 이전 폰트 핸들
With Picture1
.AutoRedraw = True
Picture1.Print "테스트" ' 원 폰트 출력 모양
RotateMe.lfEscapement = 270 * 10 ' 세로로 출력하는 논리적 폰트
RotateMe.lfHeight = (20 * -20) / Screen.TwipsPerPixelY
FontHandle = CreateFontIndirect(RotateMe)
PreviousFontHandle = SelectObject(.hdc, FontHandle)
.CurrentX = 500
.CurrentY = 300
Picture1.Print "테스트"
PreviousFontHandle = SelectObject(.hdc, PreviousFontHandle)
Call DeleteObject(FontHandle)
End With
End Sub
LOGFONT 구조체의 각 멤버는 다음과 같다.