デバイスコンテキストの文字色を変更する
Declare Function SetTextColor Lib "gdi32.dll" _
(ByVal hdc As Long, ByVal crColor As Long) As Long
Declare Function SetTextColor Lib "gdi32.dll" _
(ByVal hdc As Integer, ByVal crColor As Integer) As Integer
COLORREF SetTextColor(
HDC hdc,
COLORREF crColor
);
引数
hdc
デバイスコンテキストのハンドルcrColor
文字色を表すRGB値戻り値
正常終了のとき 直前の文字色サンプル
エラーのとき CLR_INVALID(=&HFFFF&)
ダウンロード(SetBkColor.lzh 1.90kB)
'バックグラウンドの塗りつぶしモード設定する
Private Declare Function SetBkMode Lib "gdi32.dll" _
(ByVal hdc As Long, ByVal iBkMode As Long) As Long
'iBkModeの定数
Private Const OPAQUE = 2 'バックグラウンドカラーをつける
Private Const TRANSPARENT = 1 '同、つけない
'デバイスコンテキストの背景色を取得する
Private Declare Function SetBkColor Lib "gdi32.dll" _
(ByVal hdc As Long, ByVal crColor As Long) As Long
'テキストを指定の位置に出力する
Private Declare Function TextOut Lib "gdi32.dll" Alias "TextOutA" _
(ByVal hdc As Long, ByVal nXStart As Long, ByVal nYStart As Long, _
ByVal lpString As String, ByVal cbString As Long) As Long
Dim ColorIndex As Integer '現在が何色を指定しているかを保持
Dim ColorArray(3) As Long 'カラーの配色
Private Sub Command1_Click()
Dim x, y, temp As String, hdc As Long, cch As Long
x = 10
y = 20
hdc = Me.Picture1.hdc
'背景色のモードを設定する
Call SetBkMode(hdc, OPAQUE)
'背景色を設定する
Call SetBkColor(hdc, ColorArray(ColorIndex))
temp = "背景色あり"
cch = LenB(StrConv(temp, vbFromUnicode))
Call TextOut(hdc, x, y, temp, cch)
'背景色のモードを設定する
Call SetBkMode(hdc, TRANSPARENT)
y = y + 30
temp = "背景色なし"
cch = LenB(StrConv(temp, vbFromUnicode))
Call TextOut(hdc, x, y, temp, cch)
End Sub
Private Sub Form_Load()
Me.Picture1.ScaleMode = 3 'ピクセル単位
ColorIndex = 3 'Green
Me.Option1(ColorIndex).Value = True
For a = 0 To 3
ColorArray(a) = Me.Label1(a).BackColor
Next
End Sub
Private Sub Option1_Click(Index As Integer)
ColorIndex = Index
End Sub