説明

ヘッダ、およびフッタへの描画は、Win32APIを使って行いますが、このとき、SetTextColor関数等を利用して文字色を指定してから文字列描画関数(DrawTextなど)で描画しますと、希望の色で文字が印刷されます。

対応

(例)以下に製品サンプル内”全体像のサンプル”(Introductionサンプル)でコード例をあげます。

‘GetTestColor関数の定義
Private Declare Function GetTextColor Lib “gdi32” ( _
ByVal hdc As Long) As Long
‘SetTestColor関数の定義
Private Declare Function SetTextColor Lib “gdi32” ( _
ByVal hdc As Long, ByVal crColor As Long) As Long
:
:

Private Sub KnTView1_HeaderPrint( _
ByVal hdc As Long, _
ByVal Left As Long, _
ByVal Top As Long, _
ByVal Right As Long, _
ByVal Bottom As Long, _
ByVal CurPage As Long, _
ByVal NumPages As Long)

Dim fontOld As Long

Dim clrCurrent As Long
clrCurrent = GetTextColor(hdc) ‘現在の文字色を取得します
SetTextColor hdc, vbRed ‘文字色を赤に設定します
:
:

SetTextColor hdc, clrCurrent ‘文字色を戻します
End Sub