矩形に3D効果を与える(T)          <TOP>


3D効果矩形ラインを引きます。文字出力はDrawTextを用いています。

下の矩形ラインは、F-Basicのコマンドで描画しています。

DrawEdge  矩形に3D効果を与える

DrawText 文字列を指定領域に出力

OffsetRect 矩形領域の補正

 

 

'================================================================
'= 矩形に3D効果を与える(T)
'=    (DrawEdge.bas)
'================================================================
#include "Windows.bi"

Type RECT
    Left   As Long
    Top    As Long
    Right  As Long
    Bottom As Long
End Type

' 矩形に3D効果を与える
Declare Function Api_DrawEdge& Lib "user32" Alias "DrawEdge" (ByVal hDC&, qrc As RECT, ByVal edge&, ByVal grfFlags&)

' 文字列を指定領域に出力
Declare Function Api_DrawText& Lib "user32" Alias "DrawTextA" (ByVal hDC&, ByVal lpStr$, ByVal nCount&, lpRect As RECT, ByVal wFormat&)

' 矩形領域の補正
Declare Function Api_OffsetRect& Lib "user32" Alias "OffsetRect" (lpRect As RECT, ByVal x&, ByVal y&)

' バックグラウンドの塗りつぶしモード設定
Declare Function Api_SetBkMode& Lib "gdi32" Alias "SetBkMode" (ByVal hDC&, ByVal iBkMode&)

' 指定されたウィンドウのデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)

' デバイスコンテキストを解放
Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&)

#define DC_ACTIVE 1                     'アクティブなときの色
#define DC_NOTACTIVE &H2                '
#define DC_ICON 4                       'アイコン付き
#define DC_TEXT 8                       'タイトルテキスト付き

#define BDR_SUNKENOUTER &H2             '
#define BDR_RAISEDINNER &H4             '
#define BDR_RAISED &H5                  '
#define EDGE_ETCHED &H2 Or &H4          '(BDR_SUNKENOUTER Or BDR_RAISEDINNER)
#define BF_LEFT &H1                     '
#define BF_TOP &H2                      '
#define BF_RIGHT &H4                    '
#define BF_BOTTOM &H8                   '
#define BF_RECT &h1 Or &H2 Or &H4 Or &H8 '(BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
#define DFC_BUTTON 4                    'ボタン
#define DFC_POPUPMENU 5                 'ポップアップメニュー
#define DFCS_BUTTON3STATE 8             '3ステートボタン
#define DT_CENTER &H1                   'テキストを水平方向の中央に揃える

#define TRANSPARENT 1                   '背景色を設定しない

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Var rct As RECT
    Var Ret As Long
    Var hDC As Long

    hDC = Api_GetDC(GethWnd)

    rct.Left = 30
    rct.Right = 200
    rct.Top = 10
    rct.Bottom = 50

    Ret = Api_DrawEdge(hDC, RCT, EDGE_ETCHED, BF_RECT)
    Ret = Api_OffsetRect(RCT, 0, 10)
    txt$ = "DrawEdgeで描画"
    Ret = Api_SetBkMode(hDC, TRANSPARENT)
    Ret = Api_DrawText(hDC, txt$, Len(txt$), rct, DT_CENTER)

    Line(30, 55) - (199, 94), , 1, b
    Line(31, 56) - (200, 95), , 15, b
    Symbol(75, 65), "Lineで描画", 1, 1

    Ret = Api_ReleaseDC(GethWnd, hDC)
End Sub

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