透明なフォーム          <TOP>


CreateRectRgn 長方形のリージョンを作成
CombineRgn 既存の二つの領域を結合して新しい領域を作成
SetWindowRgn 指定の領域をウィンドウ領域として設定
GetSystemMetrics さまざまなシステムメトリックの値とシステムの現在の構成を取得


例では、フォームに1個のButtonを貼り付けフォームの内側を透明にしています。

 

'================================================================
'= 透明なフォーム
'=    (CreateRectRgn2.bas)
'================================================================
#include "Windows.bi"

' 長方形のリージョンを作成
Declare Function Api_CreateRectRgn& Lib "gdi32" Alias "CreateRectRgn" (ByVal nLeftRect&, ByVal nTopRect&, ByVal nRightRect&, ByVal nBottomRect&)

' 既存の二つの領域を結合して新しい領域を作成
Declare Function Api_CombineRgn& Lib "gdi32" Alias "CombineRgn" (ByVal hRgnDest&, ByVal hRgnSrc1&, ByVal hRgnSrc2&, ByVal nCombineMode&)

' 指定の領域をウィンドウ領域として設定
Declare Function Api_SetWindowRgn& Lib "user32" Alias "SetWindowRgn" (ByVal hWnd&, ByVal hRgn&, ByVal bRedraw&)

' さまざまなシステムメトリックの値とシステムの現在の構成を取得
Declare Function Api_GetSystemMetrics& Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex&)

#define RGN_DIFF 4                      'HRGNSRC1からHRGNSRC2を除いた領域
#define RGN_OR 2                        'リージョン同士のOR結合
#define SM_CXFRAME 32                   'サイズ可変ウィンドウの境界線のX方向の幅
#define SM_CYFRAME 33                   'サイズ可変ウィンドウの境界線のY方向の幅
#define SM_CYBORDER 6                   'サイズ固定ウィンドウの境界線のY方向の幅
#define SM_CYCAPTION 4                  'キャプションの高さ

Var Shared Button1 As Object

Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub TransparentForm ()
Sub TransparentForm()
    Var outer_rgn As Long
    Var inner_rgn As Long
    Var wid As Single
    Var hgt As Single
    Var border_width As Single
    Var title_height As Single
    Var combined_rgn As Long
    Var ctl_left As Single
    Var ctl_top As Single
    Var ctl_right As Single
    Var ctl_bottom As Single
    Var control_rgn As Long
    Var Ret As Long

    'フォームの外側
    wid = GetWidth
    hgt = GetHeight
    outer_rgn = Api_CreateRectRgn(0, 0, wid, hgt)

    'フォームの内側
    border_width = Api_GetSystemMetrics(SM_CXFRAME)
    title_height = Api_GetSystemMetrics(SM_CYFRAME) + Api_GetSystemMetrics(SM_CYBORDER) + Api_GetSystemMetrics(SM_CYCAPTION)

    inner_rgn = Api_CreateRectRgn(border_width, title_height, wid - border_width, hgt - border_width)

    '外側から内側の領域を引き算
    combined_rgn = Api_CreateRectRgn(0, 0, 0, 0)
    Ret = Api_CombineRgn(combined_rgn, outer_rgn, inner_rgn, RGN_DIFF)

    ctl_left = border_width + 144
    ctl_top = title_height + 66
    ctl_right = ctl_left + 68
    ctl_bottom = ctl_top + 24

    control_rgn = Api_CreateRectRgn(ctl_left, ctl_top, ctl_right, ctl_bottom)
    Ret = Api_CombineRgn(combined_rgn, combined_rgn, control_rgn, RGN_OR)

    'ウィンドウを指定領域に制限
    Ret = Api_SetWindowRgn(GethWnd, combined_rgn, True)
End Sub

'================================================================
'=
'================================================================
Declare Sub MainForm_Resize edecl ()
Sub MainForm_Resize()
    If GetWidth < 240 Or GetHeight < 140 Then SetWindowSize 240, 140

    TransparentForm
End Sub

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