文字列をグレー表示(T) <TOP>
文字列をグレー表示します。
GetSysColor システムの背景色を取得
SetBkColor デバイスコンテキストの背景色を設定
GetPixel 指定された座標のピクセルのRGB値を取得
CreateFontIndirect 論理フォントを作成
SelectObject 指定されたデバイスコンテキストのオブジェクトを選択
DrawState イメージを加工して表示
左:フォーム設定 右:Buttonのシステムカラーを取得し、その色をフォーム背景色に。DrawStateのみの場合文字背景色が白になる
左:Enableボタンを選択した場合 右:Disableボタンを選択した状態
'================================================================ '= 文字列をグレー表示
'= (DrawState2.bas)
'================================================================ #include "Windows.bi" #define LF_FACESIZE 32 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 ' システムの背景色を取得 Declare Function Api_GetSysColor& Lib "user32" Alias "GetSysColor" (ByVal nIndex&) ' デバイスコンテキストの背景色を設定 Declare Function Api_SetBkColor& Lib "gdi32" Alias "SetBkColor" (ByVal hDC&, ByVal crColor&) ' 指定された座標のピクセルのRGB値を取得 Declare Function Api_GetPixel& Lib "gdi32" Alias "GetPixel" (ByVal hDC&, ByVal X&, ByVal Y&) ' 論理フォントを作成 Declare Function Api_CreateFontIndirect& Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) ' 指定されたデバイスコンテキストのオブジェクトを選択 Declare Function Api_SelectObject& Lib "gdi32" Alias "SelectObject" (ByVal hDC&, ByVal hObject&) ' イメージを加工して表示 Declare Function Api_DrawState& Lib "user32" Alias "DrawStateA" (ByVal hDC&, ByVal hBrush&, ByVal lpDrawStateProc&, ByVal lData$, ByVal wData&, ByVal X&, ByVal Y&, ByVal cx&, ByVal cy&, ByVal fFlags&) ' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得 Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&) ' デバイスコンテキストを解放 Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&) #define TXT_DISABLED &H20 #define TXT_PREFIXTEXT &H2 #define TXT_TEXT &H1 #define COLOR_BTNFACE 15 'コマンドボタンの表面色 Var Shared XPos As Long Var Shared YPos As Long Var Shared hDC As Long Var Shared rgbColor As Long '================================================================ '= '================================================================ Declare Sub sDrawTextEnabledDisabled(Index As Integer) Sub sDrawTextEnabledDisabled(Index As Integer) Var LF As LOGFONT Var rFont As Long Var Size As Integer Var lDrawStateFlag As Long Var Txt As String Var BkCol As Long Txt = "北海道札幌市" Size = 40 XPos = 5 YPos = 20 LF.lfHeight = Size LF.lfWeight = 700 rFont = Api_CreateFontIndirect(LF) hDC = Api_GetDC(GethWnd) If Index = 1 Then lDrawStateFlag = TXT_DISABLED cls BkCol = Api_GetPixel(hDC, 0, 0) 'フォームの背景色取得 Ret = Api_SetBkColor(hDC, BkCol) '文字の背景色を設定 Ret = Api_SelectObject(hDC, rFont) 'フォームの指定位置に指定角度・大きさで文字列を描画 Ret = Api_DrawState(hDC, 0, 0, Txt, Len(Txt), XPos, YPos, 0, 0, TXT_TEXT Or lDrawStateFlag) End Sub '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() rgbColor = Api_GetSysColor(COLOR_BTNFACE) 'Buttonの表面色を取得(EDE9EC) SetBackColor rgbColor 'Mainformを取得色で塗り ShowWindow -1 'Mainformを表示 Index = 0 sDrawTextEnabledDisabled 0 End Sub '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Index = 0 sDrawTextEnabledDisabled 0 End Sub '================================================================ '= '================================================================ Declare Sub Button2_on edecl () Sub Button2_on() Index = 1 sDrawTextEnabledDisabled 1 End Sub '================================================================ '= '================================================================ Declare Sub MainForm_QueryClose edecl (Cancel As Integer, Mode As Integer) Sub MainForm_QueryClose(Cancel As Integer, Mode As Integer) If Cancel = 0 Then Ret = Api_ReleaseDC(GethWnd, hDC) End If End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End