56.文字列を指定領域に出力する
< 使用用途 >
文字列を指定領域に出力する
< 説明 >
API関数のDrawTextを使用します
DrawText =>文字列を指定領域に出力する
<引数>
hdc:デバイスコンテキストのハンドル
lpStr:出力する文字列
nCount:すべての文字列を出力するとき-1
wFormat:定数(DT_××参照)
@戻り値@
正常終了0以外
< SAMPLE >
'標準モジュール
Public 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
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Const DT_BOTTOM = &H8'矩形の底辺にテキストを合せる
Public Const DT_CALCRECT = &H400
Public Const DT_CENTER = &H1 'テキストをを水平方向にセンタリング
Public Const DT_CHARSTREAM = 4 ' Character-stream, PLP
Public Const DT_DISPFILE = 6 ' Display-file
Public Const DT_EXTERNALLEADING = &H200
Public Const DT_EXPANDTABS = &H40 '領域に納まらないとき最後尾に........をつける
Public Const DT_INTERNAL = &H1000
Public Const DT_LEFT = &H0 '左位置揃え
Public Const DT_METAFILE = 5 ' Metafile, VDM
Public Const DT_NOPREFIX = &H800
Public Const DT_NOCLIP = &H100
Public Const DT_PLOTTER = 0 ' Vector plotter
Public Const DT_RASCAMERA = 3 ' Raster camera
Public Const DT_RASDISPLAY = 1 ' Raster display
Public Const DT_RASPRINTER = 2 ' Raster printer
Public Const DT_RIGHT = &H2 '右位置揃え
Public Const DT_SINGLELINE = &H20
Public Const DT_TABSTOP = &H80
Public Const DT_TOP = &H0 '上位位置揃え
Public Const DT_VCENTER = &H4
Public Const DT_WORDBREAK = &H10
'ここからはフォーム内の処理です
Private Sub Command1_Click()
Dim Basyo As RECT
Dim nString As String
Dim Ret As Long
'領域を設定
Basyo.Top = 0
Basyo.Left = 0
Basyo.Right = 100
Basyo.Bottom = 500
nString = "これはテストです"
'Form1に出力する
Ret = DrawText(hdc, nString, -1, Basyo, DT_LEFT)
End Sub