コマンドボタンの作成 <TOP>
CreateEllipticRgn 楕円形のリージョンを作成
CombineRgn 既存の二つの領域を結合して新しい領域を作成
SetWindowRgn 指定の領域をウィンドウ領域として設定
RGN_OR(2) リージョン同士のOR結合
PictureBoxをコマンドボタン代わりにしてみました。
'================================================================ '= コマンドボタンの作成 '= (CombineRgn2.bas) '================================================================ #include "Windows.bi" ' 楕円形のリージョンを作成 Declare Function Api_CreateEllipticRgn& Lib "gdi32" Alias "CreateEllipticRgn" (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&) #define RGN_OR 2 'リージョン同士のOR結合 Var Shared Bitmap As Object BitmapObject Bitmap Var Shared Picture1 As Object Var Shared Text1 As Object Picture1.Attach GetDlgItem("Picture1") Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() Var Rgn0 As Long Var Rgn1 As Long Var Rgn2 As Long Var Rgn3 As Long Var Ret As Long Bitmap.LoadFile "Mickey1.bmp" Picture1.StretchBitmap Bitmap, 0, 0, 80, 80 Bitmap.DeleteObject Rgn0 = Api_CreateEllipticRgn(14, 20, 68, 75) '顔中央部 Rgn1 = Api_CreateEllipticRgn(3, 3, 30, 33) '左耳 Rgn2 = Api_CreateEllipticRgn(52, 2, 77, 33) '右耳 Rgn3 = Api_CreateEllipticRgn(26, 33, 53, 79) '顎 Ret = Api_CombineRgn(Rgn0, Rgn0, Rgn1, RGN_OR) 'Rgn0 と Rgn1 を合成 = Rgn0 Ret = Api_CombineRgn(Rgn0, Rgn0, Rgn2, RGN_OR) 'Rgn0 と Rgn2 を合成 = Rgn0 Ret = Api_CombineRgn(Rgn0, Rgn0, Rgn3, RGN_OR) 'Rgn0 と Rgn3 を合成 = Rgn0 Ret = Api_SetWindowRgn(Picture1.GethWnd, Rgn0, True) Picture1.ShowWindow -1 End Sub '================================================================ '= '================================================================ Declare Sub Picture1_MouseDown edecl (ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) Sub Picture1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) If Button = 1 Then Picture1.MoveWindow 9, 9 Bitmap.LoadFile "Mickey2.bmp" Picture1.StretchBitmap Bitmap, 0, 0, 80, 80 Bitmap.DeleteObject End If End Sub '================================================================ '= '================================================================ Declare Sub Picture1_MouseUp edecl (ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) Sub Picture1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) Picture1.MoveWindow 8, 8 Bitmap.LoadFile "Mickey1.bmp" Picture1.StretchBitmap Bitmap, 0, 0, 80, 80 Bitmap.DeleteObject Text1.SetWindowtext "ミッキーマウスボタンが押されました!" Wait 100 Text1.SetWindowText "" End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End