フォームの背景色を取得          <TOP>


例ではフォームの背景色を取得します。

OleTranslateColor カラーコードへの変換(OLE_COLORタイプをCOLORREFに変換)

 

色選択ダイアログで選択した色をフォームの背景色とし、その色を取得しカラーコードに変換表示しています。

 

 

'================================================================
'= フォームの背景色を取得
'=    (TranslateColor.bas)
'================================================================
#include "Windows.bi"

'カラーコードへの変換(OLE_COLORタイプをCOLORREFに変換)
Declare Function Api_OleTranslateColor& Lib "olepro32" Alias "OleTranslateColor" (ByVal lOleColor&, ByVal lHPalette&, ByRef lColorRef&)

Var Shared Text(3) As Object

For i = 0 To 3
    Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1)))
Next i

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var RealColor As Long

    SetMapMode 2
    If ChooseColor(RealColor) Then
        SetBackColor RealColor
        Cls
    End If
End Sub

'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var Ret As Long
    Var RealColor As Long

    Ret = Api_OleTranslateColor(GetBackColor, 0, RealColor)

    Text(1).SetWindowText " R = " & "&&H" & Hex$(RealColor And &HFF) & " (" & Trim$(Str$(RealColor And &HFF)) & ")" & Chr$(13,10)
    Text(2).SetWindowText " G = " & "&&H" & Hex$((RealColor And &HFF00) / 2 ^ 8) & " (" & Trim$(Str$((RealColor And &HFF00) / 2 ^ 8)) & ")" & Chr$(13,10)
    Text(3).SetWindowText " B = " & "&&H" & Hex$((RealColor And &HFF0000) / 2 ^ 16) & " (" & Trim$(Str$((RealColor And &HFF0000) / 2 ^ 16)) & ")"
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End