指定領域をフラッシュ          <TOP>


例では、指定した矩形領域をフラッシュ(反転)させています。

GdiFlush 呼び出し側スレッドの現在のバッチをフラッシュ

InvertRect 長方形内の色を反転描画

Sleep カレントスレッドの実行を指定の時間だけ中断

GetDC 指定されたウィンドウのクライアント領域のデバイスコンテキストのハンドルを取得

ReleaseDC デバイスコンテキストを解放

 

 

'================================================================
'= 指定領域をフラッシュ
'=    (GdiFlush.bas)
'================================================================
#include "Windows.bi"

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

' 呼び出し側スレッドの現在のバッチをフラッシュ
Declare Function Api_GdiFlush& Lib "gdi32" Alias "GdiFlush" ()

' 長方形内の色を反転描画
Declare Function Api_InvertRect& Lib "user32" Alias "InvertRect" (ByVal hDC&, lpRect As RECT)

' カレントスレッドの実行を指定の時間だけ中断
Declare Sub Api_Sleep Lib "Kernel32" Alias "Sleep" (ByVal dwMilliseconds&)

' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)

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

Var Shared Picture1 As Object
Var Shared Button1 As Object
Var Shared Bitmap As Object

Picture1.Attach GetDlgItem("Picture1")
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14
BitmapObject Bitmap

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Bitmap.LoadFile "flower.bmp"
    Picture1.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
End Sub

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

    hDC = Api_GetDC(Picture1.GethWnd)
    
    rct.Left = Picture1.GetWidth / 5
    rct.Top = Picture1.GetHeight / 5
    rct.Right = Picture1.GetWidth - Picture1.GetWidth / 5
    rct.Bottom = Picture1.GetHeight - Picture1.GetHeight / 5
    
    For i = 1 To 10
        Ret = Api_InvertRect(hDC, rct)
        Ret = Api_GdiFlush
        Api_Sleep(200)
    Next

    Ret = Api_ReleaseDC(Picture1.GethWnd, hDC)
End Sub

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